Matlab1 PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

MATLAB Examples Page 1 of 4

MATLAB

Plots: Multiple Curves with labels
% Thi s scr i pt i s used t o pl ot y( t ) =si n( al pha*t ) .
%
% The val ue of al pha must exi st i n t he wor kspace pr i or
% t o i nvoki ng t he scr i pt .
%

t =[ 0: 0. 01: 1] ' ;
al pha=2*pi ;

y=si n( al pha*t ) ;
ysquar ed= y . * y;

pl ot ( t , y, t , ysquar ed)

xl abel ( ' Ti me ( sec) ' )
yl abel ( ' y( t ) = si n( \ al pha t ) ' )
gr i d on

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Time (sec)
y
(
t
)

=


s
i
n
(


t
)


MATLAB Examples Page 2 of 4
Transfer Function
% Tr ansf er Funct i on Exampl e
%
num= [ 1 3] ;
den = [ 1 3 2] ;

sys = t f ( num, den)

Transfer function:
s + 3
-------------
s^2 + 3 s + 2

[ y1, t 1] =i mpul se( sys) ;

t 2 = ( 0: . 01: 6) ' ;
y2 = 2*exp( - t 2) - 1*exp( - 2*t 2) ;

pl ot ( t 1, y1, t 2, y2)
xl abel ( ' Ti me ( sec) ' )
yl abel ( ' I mpul se Response' )
gr i d on

Figure 1
0 1 2 3 4 5 6
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Time (sec)
I
m
p
u
l
s
e

R
e
s
p
o
n
s
e


y3 = 2*exp( - t 1) - 1*exp( - 2*t 1) ;
er r or = y3- y1;

f i gur e( 2)
pl ot ( t 1, er r or )
xl abel ( ' Ti me ( sec) ' )
gr i d on
pause
axi s( [ 0 6 - . 001 . 001] )

MATLAB Examples Page 3 of 4
Figure 2 before pause
0 1 2 3 4 5 6
0
0.2
0.4
0.6
0.8
1
1.2
x 10
-15
Time (sec)


Figure 2 after pause
0 1 2 3 4 5 6
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
x 10
-3
Time (sec)

MATLAB Examples Page 4 of 4

f i gur e( 3)
st ep( sys)
xl abel ( ' Ti me ( sec) ' )
gr i d on

Figure 2 after pause
Time (sec)
A
m
p
l
i
t
u
d
e
Step Response
0 1 2 3 4 5 6
0
0.5
1
1.5
From: U(1)
T
o
:

Y
(
1
)

You might also like