0% found this document useful (0 votes)
31 views

Laboratory in Automatic Control: Lab 3 Analysis of State Variable Models

This document provides an overview of state-space models and their analysis in MATLAB. It includes 10 sections that cover topics like: - Converting transfer functions to state-space models and vice versa using functions like ss(), tf2ss(), and ss2tf() - Using the exponential matrix function expm() to calculate the fundamental or state transition matrix - Simulating state-space models using lsim() and obtaining the state trajectories and output over time - Plotting the state variables individually using subplot() The document uses examples throughout to demonstrate the MATLAB code for working with state-space models.

Uploaded by

nchubccl
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF or read online on Scribd
0% found this document useful (0 votes)
31 views

Laboratory in Automatic Control: Lab 3 Analysis of State Variable Models

This document provides an overview of state-space models and their analysis in MATLAB. It includes 10 sections that cover topics like: - Converting transfer functions to state-space models and vice versa using functions like ss(), tf2ss(), and ss2tf() - Using the exponential matrix function expm() to calculate the fundamental or state transition matrix - Simulating state-space models using lsim() and obtaining the state trajectories and output over time - Plotting the state variables individually using subplot() The document uses examples throughout to demonstrate the MATLAB code for working with state-space models.

Uploaded by

nchubccl
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF or read online on Scribd
You are on page 1/ 22

Laboratory in Automatic Control

Lab 3
Analysis of State Variable Models
Magic square (1/8)
Syntax
M = magic(n)
B = sum(M)
Matlab code
M = magic(4)

sum(M)

sum(M')
Result
Magic square (2/8)
Syntax
X = diag(v)
Matlab code
M = magic(4)

X = diag(M)

sum(diag(M))
Result
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 4
0
2
4
6
8
10
12
14
16
Magic square (4/8)
Syntax (the colon
operator)
:
Matlab code
1:10

100:-7:50

0:pi/4:pi
Result
Magic square (5/8)
Matlab code
M = magic(4)

M(1:3,4)

M(2:4,2:3)
Result
Magic square (6/8)
Matlab code
M = magic(4)

M(:,1:2:4)

M(:,2:3:4)
Result
Magic square (7/8)
Matlab code
M = magic(4)

M(:,:)

M(:,2)
Result
Magic square (8/8)
Matlab code
M = magic(4)

[M(:,:),M(:,2)]

N = M(:,[4 1 2 3])
Result
Impulse signal
Syntax
impulse(sys)
impulse(sys,t)

impulse(sys1,sys2,...,sysN)
impulse(sys1,sys2,...,sysN,t)
impulse(sys1,'PlotStyle1',...,sysN,'PlotStyle
N')
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 s
s
U s s
s s
+ +
=
+ + +
x( ) = Ax( ) + Bu( )
y( ) = Cx( ) + Du( )
t t t
t t t
State-space models (2/10)
In Matlab 7.4
State-space models (3/10)
2
3 2
( ) 2 8 6
( ) 8 16 6
Y s s
s
U s s
s 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

( (
( (
= +
( (
( (

(
(
= +
(
(

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
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)
State-space models (6/10)
Syntax
Y = expm(X)
Matlab code
a=[0 -2;1 -3];
t=0.2;
Phi=expm(a*t)
0 2
A , 0.2
1 3
( ) exp(A )
( ( ) : fundamental or
state transition matrix)
t
t t
t

(
= =
(


u =
u
Example
Result
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)


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 model
x0=[2 2]; % initial conditions
t=[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
State-space models (9/10)
Result
subplot(3,1,1)
subplot(3,1,2)
subplot(3,1,3)
State-space models (10/10)
Lab Assignments (1/2)
Lab Assignments (2/2)
Mp3.4 Consider the system

You might also like