Professional Documents
Culture Documents
Oklahoma State University: ECEN 4413 - Automatic Control Systems Matlab Lecture 1 Introduction and Control Basics
Oklahoma State University: ECEN 4413 - Automatic Control Systems Matlab Lecture 1 Introduction and Control Basics
Matlab Lecture 1
Introduction and Control Basics
2
The Interface
Workspace
and
Launch Pad
Command
Window
Command
History
and
Current
Directory
3
Variable assignment
• Scalar: a = 4
• Vector: v = [3 5 1] v 3 5 1
v(2) = 8 v 3 8 1
1 2
• Matrix: m = [1 2 ; 3 4] m
3 4
1 0
m(1,2)=0 m
3 4 4
Basic Operations
• Scalar expressions
10
b = 10 / ( sqrt(a) + 3 ) b
a 3
• Matrix expressions
1 0 1 1
n = m * [1 0]’ n
3 4 0 3
5
Useful matrix operations
• Determinant: det(m)
• Inverse: inv(m)
• Rank: rank(m)
6
Example
x = [0:0.01:2*pi];
y = cos(x);
plot(x,y)
7
Example
8
Adding graphs to reports
• Three options:
10
Other useful information
11
Using Matlab to create models
• Why model?
- Represent
- Analyze
Y (s ) 25
Given: G(s ) 2
U (s ) s 4s 25
Matlab function: tf
14
Zero-Pole-Gain representation
Y (s ) 3(s 1)
Given: H (s )
U (s ) (s 2 i )(s 2 i )
zeros = [1];
poles = [2-i 2+i];
gain = 3;
H = zpk(zeros,poles,gain)
15
State Space representation
1 0 1
x Ax Bu A B 0
Given: , 2 1
y Cx Du
C 3 2 D 0
Matlab function: ss
A = [1 0 ; -2 1];
B = [1 0]’;
C = [3 -2];
D = [0];
sys = ss(A,B,C,D)
16
System analysis
1) Stability analysis
e.g. pole placement
2) Time domain analysis
e.g. response to different inputs
3) Frequency domain analysis
e.g. bode plot
17
Stability analysis
In Matlab: pole(sys)
18
Time domain analysis
Once a model has been inserted in Matlab, the step
response can be obtained directly from: step(sys)
Unit Step Response of G(s)
1.4
0.8
0.6
• Impulse response
impulse(sys)
• Response to an arbitrary input
e.g.
t = [0:0.01:10];
u = cos(t);
lsim(sys,u,t)
21
Frequency domain analysis
Pole-Zero Map
4
1
Imaginary Axis
-1
-2
-3
-4
-2 -1.8 -1.6 -1.4 -1.2 -1 -0.8 -0.6 -0.4 -0.2 0
Real Axis
22
Extra: partial fraction expansion
2 s 2 3s 2
Given: G ( s) 2
s 3s 2
num=[2 3 2];
den=[1 3 2];
[r,p,k] = residue(num,den)
Answer:
r=
-4 r (1) r ( n)
G ( s) k ( s)
p=
1
s p(1)
4 1
s p ( n)
-2 2s 0
s (2) s (1)
-1
k=
2
23