The Matlab Language
The Matlab Language
Key Features
• High-level language for technical computing
• Development environment for managing code, files,
and data
• Interactive tools for iterative exploration, design, and
problem solving
• Mathematical functions for linear algebra, statistics,
Fourier analysis, filtering, optimization, and numerical
integration
• 2-D and 3-D graphics functions for visualizing data
• Tools for building custom graphical user interfaces
• Functions for integrating MATLAB based algorithms
with external applications and languages, such as C,
C++, Fortran, Java, COM, and Microsoft Excel
1
The MATLAB® language supports the vector and matrix
operations that are fundamental to engineering and
scientific problems. It enables fast development and
execution.
2
EIGEN VALUES:
3
positive definite B. It computes the generalized eigenvalues
of A and B
using the Cholesky factorization of B.
EIG(A,B,'qz') ignores the symmetry of A and B and uses the
QZ algorithm.
In general, the two algorithms return the same result,
however using the
QZ algorithm may be more stable for certain problems.
The flag is ignored when A and B are not symmetric.
OUTPUT:
a=
1 2 1
2 4 6
-5 4 8
ans =
4
ans =
-1.3742
3.8853
10.4889
NYQUIST:
5
NYQUIST(SYS1,SYS2,...,W) plots the Nyquist response of
multiple
LTI models SYS1,SYS2,... on a single plot. The frequency
vector
W is optional. You can also specify a color, line style, and
marker
for each system, as in
nyquist(sys1,'r',sys2,'y--',sys3,'gx').
6
OUTPUT:
Transfer function:
2
---------------------
0.1 s^3 + 0.7 s^2 + s
7
ROOT LOCUS:
8
+-----+
---->O----->| SYS |----+---->
-| +-----+ |
| |
| +---+ |
+-------| K |<----+
+---+
9
% plotting root locus and checking the stability
clc
clear
s1=tf([1 1],[conv([1 3 0],[1 2 5])]);
t1=feedback(s1,1)
figure(1);
rlocus(t1)
for k=1:.1:100;
sys=k*s1;
sys1=feedback(sys,1);
p=pole(sys1);
r=real(p);
if max(r)>=0
'the system becomes unstable for values of gain k greater than
and equal to'
k=k
break
end
end
s3=tf([1],[1 2 0 0]);
t3=feedback(s3,1)
figure(3);
rlocus(t3)
'system is unstable for all values of gain k'
OUTPUT:
10
Transfer function:
s+1
-------------------------------
s^4 + 5 s^3 + 11 s^2 + 16 s + 1
ans =
the system becomes unstable for values of gain k greater than and
equal to
k=
24.5000
Transfer function:
3s+2
---------------------
s^3 + 6 s^2 + 3 s + 2
ans =
Transfer function:
1
---------------
s^3 + 2 s^2 + 1
ans =
11
FIGURE 1
12
FIGURE 2
Root Locus
6
2
Imaginary Axis
-2
-4
-6
-6 -5 -4 -3 -2 -1 0
Real Axis
13
FIGURE 3
Root Locus
5
1
Imaginary Axis
-1
-2
-3
-4
-5
-6 -5 -4 -3 -2 -1 0 1 2
Real Axis
14
SS Creates state-space model or converts model to state
space.
CONVERSION:
NUM(s) -1
H(s) = -------- = C(sI-A) B + D
DEN(s)
of the system:
.
x = Ax + Bu
y = Cx + Du
15
denominator in descending powers of s. The numerator
coefficients
are returned in matrix NUM with as many rows as there
are
outputs y.
CONTROLLABILITY:
OBSERVABILITY:
16
%obtaining response curves using matlab with
initial state X(0)=0
a=[-1 1;-1 0]
b=[0;2]
c=[1 0]
d=[0]
sys=ss(a,b,c,d)
t=0:.1:10;
17
OUTPUT:
a=
-1 1
-1 0
b=
0
2
c=
1 0
d=
a=
x1 x2
x1 -1 1
x2 -1 0
b=
u1
x1 0
x2 2
c=
x1 x2
18
y1 1 0
d=
u1
y1 0
FIGURE 1
2.5
1.5
0.5
0
0 20 40 60 80 100 120
FIGURE 2
19
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
-0.1
0 20 40 60 80 100 120
20
OUTPUT
a=
-1 -3 -3
0 -2 1
2 0 -1
b=
3
0
1
c=
1 2 0
d=
21
a=
x1 x2 x3
x1 -1 -3 -3
x2 0 -2 1
x3 2 0 -1
b=
u1
x1 3
x2 0
x3 1
c=
x1 x2 x3
y1 1 2 0
d=
u1
y1 0
Continuous-time model.
ans =
system is controllable
ans =
system is observable
22
BODE PLOT:
23
size [NY NU LENGTH(W)] where MAG(:,:,k) and
PHASE(:,:,k) determine
the response at the frequency W(k). To get the
magnitudes in dB,
type MAGDB = 20*log10(MAG).
MARGIN:
OUTPUT:
Transfer function:
24
0.5 s + 1
---------
0.2 s + 1
gm =
Inf
pm =
-180
wcg =
NaN
wcp =
ans =
lag =
-180
25
B o d e D ia g r a m
8
6
M a g n itu d e (d B )
0
3 0
2 0
P h a s e (d e g )
1 0
0
- 1 0 1 2
1 0 1 0 1 0 1 0
F re q u e n c y ( r a d /s e c )
26
Simulink
Simulink is a software package for modeling, simulating, and
analyzing dynamic systems. It supports linear and nonlinear
systems, modeled in continuous time, sampled time, or a
hybrid of the two. Systems can also be multirate, i.e., have
different parts that are sampled or updated at different
rates.
27
Effects of non-linearities:
1
s2 + 3 s+ 1 0
T ra n sfe r F c n 2
1
1 0
s2 + 3 s + 1 0
S te p G a in S a t u r a t iT o r na n s f e r F c n S c o p e
1
s2 + 3 s + 1 0
S a t u r a B t i ao cn k 1l a T s r h a n s f e r F c n 1
28
Step Response:
4
s2 + 4
d a m p in g ra tio = 0
4
s2 + 4 s + 4
d a m p in g ra tio = 1
4
S c o p e
S te p s2 + 2 s + 4
d a m p in g ra tio = 0 .5
4
s2 + 6 s + 4
d a m p in g ra tio = 1 .5
29
INDEX
30