Sie sind auf Seite 1von 6

# Experiment No.

1
Vectors .............................................................................................................................. 1
Functions ........................................................................................................................... 1
Plotting .............................................................................................................................. 2
Polynomials as Vectors ........................................................................................................ 3
Polynomial Using the s Variable ............................................................................................ 3
Matrices ............................................................................................................................. 4

## Writing some simple MATLAB operations

Vectors
a = [1 2 3 4 5 6 7]

t = 0:2:20

b = a+2

c = a + b

a =

1 2 3 4 5 6 7

t =

0 2 4 6 8 10 12 14 16 18 20

b =

3 4 5 6 7 8 9

c =

4 6 8 10 12 14 16

Functions
sin(pi/4)
help myFunctions
y = myFunction(3)

1
Experiment No. 1

ans =

0.7071

## This is a very simple cube function

This is a function which outputs cube of input
Published output in the Help browser
showdemo myFunction

y =

27

Plotting
t = 0:0.25:7;
y = sin(t);
plot(t,y);
title('Sine Wave as a Function of Time')
xlabel('Time(secs)')
ylabel('Amplitude')

2
Experiment No. 1

Polynomials as Vectors
The following line creates a polynomial s^3+3*s^2+4*s+5

poly1 = [1 3 4 5];

## % polyval() calculates the value of polynomial(first argument) at the

second argument
poly1_val = polyval(poly1,2)

## %Roots of polynomial are found using roots()

poly1_roots = roots(poly1)

x = [1 2];
y = [1 4 8];
z = conv(x,y)

## % deconv() divides first argument vector by the second

[xx, R] = deconv(z,y)

poly1_val =

33

poly1_roots =

-2.2134 + 0.0000i
-0.3933 + 1.4506i
-0.3933 - 1.4506i

z =

1 6 16 16

xx =

1 2

R =

0 0 0 0

## Polynomial Using the s Variable

tf() returns an s domain variable

3
Experiment No. 1

s = tf('s')
s_poly1 = s^3+3*s^2+4*s+5

## % s domain zeros can be found using zero()

poly1_zero = zero(s_poly1)

s =

## Continuous-time transfer function.

s_poly1 =

s^3 + 3 s^2 + 4 s + 5

## Continuous-time transfer function.

poly1_zero =

-2.2134 + 0.0000i
-0.3933 + 1.4506i
-0.3933 - 1.4506i

Matrices
B = [1 2 3 4; 5 6 7 8; 9 10 11 12]

C = B'

D = B * C

operation
mat1 = [1 2
3 4]

mat2 = [5 6
7 8]

## % Square matric self multiplication n times can be found using

matric^n
mat1_to_5 = mat1^5

## % Similarly elements of matrix power can be found using .^ operation

4
Experiment No. 1

mat1_elements_to_5 = mat1.^5

X = inv(mat1)

E = eig(mat1)

p = poly(mat1)

## % roots of the polynomial can be found using roots function

% In this case of characteristic polynomial using roots of its
% characteristic
r = roots(p)

B =

1 2 3 4
5 6 7 8
9 10 11 12

C =

1 5 9
2 6 10
3 7 11
4 8 12

D =

30 70 110
70 174 278
110 278 446

mat1 =

1 2
3 4

mat2 =

5 6
7 8

mat1_x_2 =

19 22

5
Experiment No. 1

43 50

mat1_to_5 =

1069 1558
2337 3406

mat1_elements_to_5 =

1 32
243 1024

X =

-2.0000 1.0000
1.5000 -0.5000

E =

-0.3723
5.3723

p =

r =

5.3723
-0.3723