Upload
nchubccl
View
224
Download
0
Embed Size (px)
Citation preview
8/2/2019 Laboratory in Automatic Control Lab3
1/22
Laboratory in Automatic Control
Lab 3
Analysis of State Variable Models
8/2/2019 Laboratory in Automatic Control Lab3
2/22
Magic square (1/8) Syntax
M = magic(n)
B = sum(M) Matlab code
M = magic(4)
sum(M)
sum(M')
Result
8/2/2019 Laboratory in Automatic Control Lab3
3/22
Magic square (2/8) Syntax
X = diag(v)
Matlab code
M = magic(4)
X = diag(M)
sum(diag(M))
Result
8/2/2019 Laboratory in Automatic Control Lab3
4/22
Magic square (3/8) Subscript
A(i,j)
Matlab code
M = magic(4);
[M(1,1),M(1,2),M(1,3),M(1,4)]
M(1,1)+M(1,2)+M(1,3)+M(1,4)
plot(M)
Result
1 1.5 2 2.5 3 3.5 40
2
4
6
8
10
12
14
16
8/2/2019 Laboratory in Automatic Control Lab3
5/22
Magic square (4/8) Syntax (the colon
operator)
: Matlab code
1:10
100:-7:50
0:pi/4:pi
Result
8/2/2019 Laboratory in Automatic Control Lab3
6/22
Magic square (5/8) Matlab code
M = magic(4)
M(1:3,4)
M(2:4,2:3)
Result
8/2/2019 Laboratory in Automatic Control Lab3
7/22
Magic square (6/8) Matlab code
M = magic(4)
M(:,1:2:4)
M(:,2:3:4)
Result
8/2/2019 Laboratory in Automatic Control Lab3
8/22
Magic square (7/8) Matlab code
M = magic(4)
M(:,:)
M(:,2)
Result
8/2/2019 Laboratory in Automatic Control Lab3
9/22
Magic square (8/8) Matlab code
M = magic(4)
[M(:,:),M(:,2)]
N = M(:,[4 1 2 3])
Result
8/2/2019 Laboratory in Automatic Control Lab3
10/22
Impulse signal Syntax
impulse(sys)
impulse(sys,t)
impulse(sys1,sys2,...,sysN)
impulse(sys1,sys2,...,sysN,t)
impulse(sys1,'PlotStyle1',...,sysN,'PlotStyleN')
8/2/2019 Laboratory in Automatic Control Lab3
11/22
State-space models (1/10) Syntax
sys =
ss(transfer_function) [A,B,C,D] = tf2ss(b,a)
Matlab code
H = tf([2 8 6],[1 8 16 6]);
sys = ss(H)%[a,b,c,d]=tf2ss([2 8 6],[1 8 16 6])
Example
2
3 2( ) 2 8 6( ) 8 16 6
Y s ss
U s ss s
x( ) = Ax( ) + Bu( )
y( ) = Cx( ) + Du( )
t t t
t t t
8/2/2019 Laboratory in Automatic Control Lab3
12/22
State-space models (2/10)In Matlab 7.4
8/2/2019 Laboratory in Automatic Control Lab3
13/22
State-space models (3/10)2
3 2
( ) 2 8 6
( ) 8 16 6
Y s ss
U s ss s
1
2
3
8 4 1.5 2
x 4 0 0 x 0 ( )
0 1 0 0
( ) 1 1 0.75 0 ( )
u t
x
y t u t x
x
8/2/2019 Laboratory in Automatic Control Lab3
14/22
State-space models (4/10)
1
2
3
8 4 1.5 2
x 4 0 0 x 0 ( )
0 1 0 0
( ) 1 1 0.75 0 ( )
u t
x
y t u t x
x
( )?
( )
Y s
U s
Example
8/2/2019 Laboratory in Automatic Control Lab3
15/22
State-space models (5/10) Syntax
sys = tf(ss(a,b,c,d))
[nums,dens]= ss2tf(a,b,c,d) Matlab code
a=[-8 -4 -1.5;4 0 0;0 1 0];b=[2;0;0];
c=[1 1 0.75];d=[0];sys = tf(ss(a,b,c,d))%[nums,dens]= ss2tf(a,b,c,d)
8/2/2019 Laboratory in Automatic Control Lab3
16/22
State-space models (6/10)
Syntax
Y = expm(X)
Matlab code
a=[0 -2;1 -3];t=0.2;Phi=expm(a*t)
0 2A , 0.2
1 3
( ) exp(A )
( ( ) : fundamental or
state transition matrix)
t
t t
t
Example
Result
8/2/2019 Laboratory in Automatic Control Lab3
17/22
State-space models (7/10)
Syntax
lsim(sys,u,t)
lsim(sys,u,t,x0)
[y,t,x] = lsim(sys,u,t,x0)
n = length(X)
8/2/2019 Laboratory in Automatic Control Lab3
18/22
State-space models (8/10)
Matlab code
a=[0 -2;1 -4];b=[2;0];c=[1 0];d=[0];sys=ss(a,b,c,d); % state-space modelx0=[2 2]; % initial conditionst=[0:0.01:1];u=0*t; % zero input
[y,T,x]=lsim(sys,u,t,x0);
subplot(3,1,1),plot(T,x)subplot(3,1,2),plot(T,x(:,1))subplot(3,1,3),plot(T,x(:,2))dt=1;Xf1=expm(a*dt)*x0'
Result
8/2/2019 Laboratory in Automatic Control Lab3
19/22
State-space models (9/10)
Result
subplot(3,1,1)
subplot(3,1,2)
subplot(3,1,3)
8/2/2019 Laboratory in Automatic Control Lab3
20/22
State-space models (10/10)
8/2/2019 Laboratory in Automatic Control Lab3
21/22
Lab Assignments (1/2)
8/2/2019 Laboratory in Automatic Control Lab3
22/22
Lab Assignments (2/2)Mp3.4 Consider the system