Adama Science and Technology
University
Mathematical Representation of
Systems
ASTU
Department of EPCE
4.1 State Space Rep.
(Question) Is it possible to express the model
represented by transfer functions in the state space form?
(Answer)
In the case of transfer functions, it is possible through
rewriting them as differential equations and
transforming them into state space.
4.1 State Space Rep.
For example, consider a system represented by TF
u 𝑠+3 y
𝑠(𝑠 + 5)(𝑠 + 10)
From the block diagram
( s 15s 50s )Y ( s) ( s 3)U ( s)
3 2
Taking the inverse Laplace transform yields
y 15 y 50 y u 3u
where y (t0 ) y (t0 ) y (t0 ) u (t0 ) u (t0 ) 0
4.2 State Space Rep. : Method 1
Method 1 (observable structure)
3rd-order ODE
y a1 y a2 y a3 y b0u b1u b2u b3u
ICs y (t0 ), y (t0 ), y (t0 ), u (t0 ), u (t0 ), u (t0 )
Defining the derivative operator as p= d/dt yields
dy/dt= py, d2y/dt2= p2y, d3y/dt3= p3y
4.2 State Space Rep. : Method 1
y a1 y a2 y a3 y b0u b1u b2u b3u
Writing the expression in terms of p
( p3 a1 p 2 a2 p a3 ) y
(b0 p 3 b1 p 2 b2 p b3 )u
p ( y b0u ) p (a1 y b1u )
3 2
p(a2 y b2u ) (a3 y b3u ) 0
4.2 State Space Rep. : Method 1
p 3 ( y b0 u ) p 2 (a1 y b1u )
p (a2 y b2 u ) (a3 y b3u ) 0
Defining the state variable as
x1 y b0u
x2 p ( y b0u ) (a1 y b1u )
px1 (a1 y b1u )
x3 p 2 ( y b0u ) p (a1 y b1u ) (a2 y b2u )
px2 (a2 y b2u )
4.2 State Space Rep. : Method 1
p 3 ( y b0u ) p 2 (a1 y b1u )
p(a2 y b2u ) (a3 y b3u ) 0
x3 p 2 ( y b0u ) p (a1 y b1u ) (a2 y b2u )
From and
p[ p ( y b0u ) p (a1 y b1u ) (a2 y b2u )]
2
(a3 y b3u ) 0
px3 (a3 y b3u ) 0
4.2 State Space Rep. : Method 1
x1 y b0u
x2 px1 (a1 y b1u )
x3 px2 (a2 y b2u )
px3 (a3 y b3u ) 0
Substituting equation into and rewriting gives
px1 x2 a1 y b1u
x2 a1 ( x1 b0u ) b1u
x1 a1 x1 x2 (b1 a1b0 )u
4.2 State Space Rep. : Method 1
x1 y b0u
x2 px1 (a1 y b1u )
x3 px2 (a2 y b2u )
px3 (a3 y b3u ) 0
Substituting equation into and rewriting gives
px2 x3 a2 y b2u
x3 a2 ( x1 b0u ) b2u
x2 a2 x1 x3 (b2 a2b0 )u
4.2 State Space Rep. : Method 1
x1 y b0u
x2 px1 (a1 y b1u )
x3 px2 (a2 y b2u )
px3 (a3 y b3u ) 0
Substituting equation into and rewriting gives
px3 a3 y b3u
a3 ( x1 b0u ) b3u
x3 a3 x1 (b3 a3b0 )u
4.2 State Space Rep. : Method 1
State equation
x1 a1 x1 x2 (b1 a1b0 )u
x2 a2 x1 x3 (b2 a2b0 )u
x3 a3 x1 (b3 a3b0 )u
or
x Ax Bu
a1 1 0 b1 a1b0
where A a2
0 1 , B b2 a2b0
a3 0 0 b3 a3b0
4.2 State Space Rep. : Method 1
From
y x1 b0u
Output equation
y Cx Du
where C 1 0 0 , D b0
4.2 State Space Rep. : Method 1
Calculation of Initial Conditions (ICs)
From the initial values y (t0 ), y (t0 ), y (t0 ), u (t0 ), u (t0 ), u (t0 )
and the state variables
x1 y b0u
x2 px1 (a1 y b1u )
x3 px2 (a2 y b2u )
we have
x2 px1 a1 y b1u p ( y b0u ) a1 y b1u
y b0u a1 y b1u
x3 px2 a2 y b2u p ( y b0u a1 y b1u ) a2 y b2u
y b0u a1 y b1u a2 y b2u
4.2 State Space Rep. : Method 1
Substituting t= t0 gives
x1 (t0 ) y (t0 ) b0u (t0 )
x2 (t0 ) y (t0 ) b0u (t0 ) a1 y (t0 ) b1u (t0 )
x3 (t0 ) y (t0 ) b0u (t0 ) a1 y (t0 )
b1u (t0 ) a2 y (t0 ) b2u (t0 )
Initial conditions are calculated by the above
equations.
4.2 State Space Rep. : Method 1
nth-order ODE
(n) ( n 1) ( n) ( n 1)
y a1 y an 1 y an y b0 u b1 u bn 1u bn u
( n 1) ( n 1)
ICs y (t0 ), , y (t0 ), y (t0 ), u (t0 ), , u (t0 ), u (t0 )
where
a1 1 0 0 b1 a1b0
a 0 1 0 b a b
x Ax Bu 2 2 2 0
A , B
y Cx Du
an 1 0 0 1 bn 1 an 1b0
a 0 b a b
n 0 0 n n 0
C 1 0 0 0 , D b0
4.2 State Space Rep. : Method 1
Example 1, consider an ODE
2 y 2 y 4 y u 2u
with y(0)= 0, y(0)= 0.1, u(0)= u(0)= 0
1,
a1= 1, a 2= 2, b 0= 0, b 1= 2 b2= 1
y a1 y a2 y b0u b1u b2u
4.2 State Space Rep. : Method 1
Dynamic equation
x Ax Bu
2 y 2 y 4 y u 2u
y Cx Du
a1= 1, a2= 2,
where 1,
a1 1 1 1 b0= 0 b1= b2= 1
,
2
A
2 a 0 2 0
b1 a1b0 1/ 2
B
b2 a2b0 1
C 1 0 , D b0 0
4.2 State Space Rep. : Method 1
From ICs y(0)= 0, y(0)= 0.1, u(0)= u(0)= 0
and previous equations
x1 (t0 ) y (t0 ) b0u (t0 )
x2 (t0 ) y (t0 ) b0u (t0 ) a1 y (t0 ) b1u (t0 )
we have x1 (0) y (0) b0u (0) 0.1
x2 (0) y (0) b0u (0) a1 y (0) b1u (0) 0.1
1 1 1/ 2 0.1
x x u, x (t0 )
2 0 1 0.1
y 1 0 x
4.2 State Space Rep. : Method 1
Example 2: Write the differential equation as a dynamic
equation.
y 3 y 4 y u u 2u
with y(0)= 0, y(0)= y(0)= 0.2, u(0)= u(0)= u(0)= 0
Solution: From the given equation
a1= 3, a2= 0, a3= 4, b0= 1, b1= -1, b2= 0, b3= 2
y a1 y a2 y a3 y b0u b1u b2u b3u
4.2 State Space Rep. : Method 1
Dynamic equation
x Ax Bu
y 3 y 4 y u u 2u
y Cx Du
where a1 1 0 3 1 0
A a2 0 1 0 0 1
a3 0 0 4 0 0
b1 a1b0 1 3 1 4
B b2 a2b0 0 0 1 0
b3 a3b0 2 4 1 2
C 1 0 0 , D b0 1
4.2 State Space Rep. : Method 1
ICs are
x1 (0) y (0) b0u (0) 0.2
x2 (0) y (0) b0u (0) a1 y (0) b1u (0)
0.2 3 0.2 0.8
x3 (0) y (0) b0u (0) a1 y (0)
b1u (0) a2 y (0) b2u (0)
3 0.2 0 0.2 0.6
y(0)= 0, y(0)= y(0)= 0.2, u(0)= u(0)= u(0)= 0
4.2 State Space Rep. : Method 1
Example 3: Write a dynamic equation of the system
represented by the block diagram. All initial values
are 0.
u 𝑠+3 y
𝑠(𝑠 + 5)(𝑠 + 10)
Solution: From the block diagram
( s 3 15s 2 50s )Y ( s ) ( s 3)U ( s )
s 3Y ( s ) 15s 2Y ( s ) 50sY ( s ) sU ( s ) 3U ( s )
4.2 State Space Rep. : Method 1
Taking inverse Laplace transform yields
y 15 y 50 y u 3u
Thus, a1= 15, a2= 50, a3= 0, b0= b1= 0, b2= 1, b3= 3
y a1 y a2 y a3 y b0u b1u b2u b3u
15 1 0 0 0
x 50
0 1 x 1 u, x (0) 0
0 0 0 3 0
y 1 0 0 x
4.2 State Space Rep. : Method 1
Example 4: Obtain the unit step response of the
system for 10 seconds.
2 y 2 y 4 y u 2u
where y(0)= 0, y(0)= 0.1, u(0)= u(0)= 0
Program: From the previous results
1 1 1/ 2 0.1
x x u, x (0)
2 0 1 0.1
y 1 0 x
4.2 State Space Rep. : Method 1
Function program
function xdot= fun(t,x,u)
xdot= zeros(2,1);
xdot(1)= -x(1)+x(2)+0.5*u;
xdot(2)= -2*x(1)+u;
1 1 1/ 2
x x u
2 0 1 x1 x1 x2 0.5u
x2 2 x1 u
4.2 State Space Rep. : Method 1
Primary function
function ode01
t= 0; x= [0.1;0.1]; h= 0.02; loop= 500;
buf= [t x(1)]; u= 1;
for i= 1:loop
x= RK4(@fun,t,x,u,h);
t= t+h;
buf= [buf; t x(1)];
end
plot(buf(:,1),buf(:,2),'linewidth',2)
xlabel('t'); ylabel('y(t)');
axis([0 10 0 1])
4.2 State Space Rep. : Method 1
Unit step response
1
0.8
0.6
y(t)
0.4
0.2
0
0 2 4 6 8 10
t
4.3 State Space Rep. : Method 2
Method 2 (Controllable structure)
3rd-order ODE
y a1 y a2 y a3 y b0u b1u b2u b3u
with ICs y (t0 ), y (t0 ), y (t0 ), u (t0 ), u (t0 ), u (t0 )
Rewriting using the derivative operator p= d/dt gives
u
y (b0 p b1 p b2 p b3 )
3 2
( p3 a1 p 2 a2 p a3 )
u
Letting q
( p3 a1 p 2 a2 p a3 )
4.3 State Space Rep. : Method 2
( p3 a1 p 2 a2 p a3 )q u
y (b0 p b1 p b2 p b3 )q
3 2
Defining state variables and differentiating both sides
once gives (p= d/dt)
x1 q x1 pq x2
x2 pq x2 p 2 q x3
x3 p 2 q x3 p 3 q a3 q a2 pq a1 p 2 q u
a3 x1 a2 x2 a1 x3 u
4.3 State Space Rep. : Method 2
( p3 a1 p 2 a2 p a3 )q u
y (b0 p 3 b1 p 2 b2 p b3 )q
From and , the output equation is
y (b0 p 3 b1 p 2 b2 p b3 )q
b0 (u a1 p 2 q a2 pq a3 q ) b1 p 2 q b2 pq b3q
(b3 a3b0 )q (b2 a2b0 ) pq (b1 a1b0 ) p q b0u
2
(b3 a3b0 ) x1 (b2 a2b0 ) x2 (b1 a1b0 ) x3 b0u
4.3 State Space Rep. : Method 2
Dynamic equation x1 x2
x2 x3
x Ax Bu
x3 a3 x1 a2 x2 a1 x3 u
y Cx Du y (b3 a3b0 ) x1 (b2 a2b0 ) x2
where (b1 a1b0 ) x3 b0u
0 1 0 0
A 0 0 1 , B 0
a3 a2 a1 1
C b3 a3b0 b2 a2b0 b1 a1b0 , D b0
4.3 State Space Rep. : Method 2
Initial condition
From the dynamic equation
y Cx Du
y Cx Du C ( Ax Bu ) Du
CAx CBu Du
y CAx CBu Du
CA( Ax Bu ) CBu Du
CA x CABu CBu Du
2
4.3 State Space Rep. : Method 2
Substituting t= t0 yields
y (t0 ) Cx (t0 ) Du (t0 )
y (t0 ) CAx (t0 ) CBu (t0 ) Du (t0 )
y (t0 ) CA2 x (t0 ) CABu (t0 ) CBu (t0 ) Du (t0 )
Rewriting
1
C y (t0 ) Du (t0 )
x (t0 ) CA y (t 0 ) CB u (t 0 ) Du (t 0 )
CA2 y (t0 ) CABu (t0 ) CBu (t0 ) Du (t0 )
4.3 State Space Rep. : Method 2
nth-order ODE
(n) ( n 1) ( n) ( n 1)
y a1 y an 1 y an y b0 u b1 u bn 1u bn u
( n 1) ( n 1)
ICs y (t0 ), , y (t0 ), y (t0 ), u (t0 ), , u (t0 ), u (t0 )
x Ax Bu
y Cx Du
where 0 1 0 0 0
0 0 1 0 0
A , B , D b0
0 0 0 1 0
a a a1 1
n n 1 an 2
C bn an b0 bn 1 an 1b0 b2 a2b0 b1 a1b0
4.3 State Space Rep. : Method 2
Quiz 1: Find a dynamic equation of the differential
equation.
y 3 y 2 y 2u u
where y(0)= 0, y(0)= 0, u(0)= u(0)= 0
y a1 y a2 y b0u b1u b2u
4.3 State Space Rep. : Method 2
Example 4: Find a dynamic equation of the
differential equation.
y 3 y 2 y 2u u
where y(0)= 0, y(0)= 1, u(0)= u(0)= 0
Solution: From the given equation
a1= 3, a2= 2, b0= 0, b1= 2, b2= 1
y a1 y a2 y b0u b1u b2u
4.3 State Space Rep. : Method 2
Dynamic equation
x Ax Bu a1= 3, a2= 2,
y Cx Du b0= 0, b1= 2, b2= 1
where
0 1 0 1 0
A ,B
a2 a1 2 3 1
C b2 a2b0 b1 a1b0 1 2
D b0 0
4.3 State Space Rep. : Method 2
ICs are y(0)= 0, y(0)= 1, u(0)= u(0)= 0
0 1
CA 1 2 4 5
2 3
1
C y (0) Du (0)
x (0)
CA y (0) CBu (0) Du (0)
1
1 2 1 1 5 2 1 5 / 3
4 5 0 3 4 1 0 4 / 3
4.3 State Space Rep. : Method 2
Example 5: Obtain the zero-input response of the
ODE for 10 seconds.
y 3 y 2 y 2u u
where y(0)= 0, y(0)= 1, u(0)= u(0)= 0
Program: From the previous result
0 1 0 5 / 3
x x u, x (0)
2 3
1 4 / 3
y 1 2 x
4.3 State Space Rep. : Method 2
Function program
function xdot= fun(t,x,u)
xdot= zeros(2,1);
xdot(1)= x(2);
xdot(2)= -2*x(1)-3*x(2)+u;
0 1
x
0
x u
x1 x2
2 3 1 x2 2 x1 3x2 u
4.3 State Space Rep. : Method 2
Primary function
function ode03
t= 0; x= [-5/3;4/3]; h= 0.02; u= 0; loop= 500;
y= x(1)+2*x(2); y 1 2 x
buf= [t y];
for i=1:loop
x= RK4(@fun,t,x,u,h);
t=t+h; y= x(1)+2*x(2);
buf= [buf; t y];
end
plot(buf(:,1),buf(:,2),'linewidth',2)
xlabel('t'), ylabel('y(t)'), axis([0 10 0 1])
4.3 State Space Rep. : Method 2
Zero-input response
1
0.8
0.6
y(t)
0.4
0.2
0
0 2 4 6 8 10
t
4.3 State Space Rep. : Method 2
Method 1 (observable structure)
y a1 y a2 y a3 y b0u b1u b2u b3u
Y (s) (b1 a1b0 ) s 2 (b2 a2b0 ) s (b3 a3b0 )
b0
U (s) s 3 a1s 2 a2 s a3
a1 1 0 b1 a1b0
x Ax Bu A a2 0 1 , B b2 a2b0
y Cx Du a3 0 0 b3 a3b0
C 1 0 0 , D b0
4.3 State Space Rep. : Method 2
Method 2 (controllable structure)
y a1 y a2 y a3 y b0u b1u b2u b3u
Y (s) (b1 a1b0 ) s 2 (b2 a2b0 ) s (b3 a3b0 )
b0
U (s) s 3 a1s 2 a2 s a3
0 1 0 0
x Ax Bu A 0 0 1 , B 0
y Cx Du a3 a2 a1 1
C b3 a3b0 b2 a2b0 b1 a1b0 , D b0
4.3 State Space Rep. : Method 2
(Quiz 1) Write the transfer equation (1) for method 1 and
(2) for method 2.
Y (s) s4
(1)
U ( s ) ( s 1)( s 2)( s 3)
Y (s) s3 s 2 4
(2) 3
U ( s) s 2s 2
4.3 State Space Rep. : Method 2
Y (s) s4
(1) 3
U ( s ) s 6s 2 11s 6
From the equation
a1= 6, a2= 11, a3= 6, b0= 0, b1= 0, b2= 1, b3= 4
6 1 0 0
x 11 0 1 x 1 u, x (t0 ) 0
6 0 0 4
y 1 0 0 x
4.3 State Space Rep. : Method 2
Y (s) s s 4
3 2
(2) 3
U ( s) s 2s 2
From the equation
a1= 0, a2= 2, a3= 2, b0= 1, b1= 1, b2= 0, b3= 4
0 1 0 0
x 0 0 1 x 0 u , x (t 0 ) 0
2 2 0 1
y 2 2 1 x u
4.4 Simulation of systems
Example 6: Obtain the unit step response of the
system for 10 seconds, where all ICs are 0 and time
increment (h)= 0.01.
R(s) U(s) 1 1 Y(s)
+
25
- - s3 s
3
25
4.4 Simulation of systems
Plant
Defining the state variables X1(s) and X2(s) in the
plant yields
U(s) 1 Y(s)
1
s3 X2(s) s X1(s)
sX1(s)= X2(s) x1 x2
(s+3)X2(s)= U(s) x2 3x2 u
Y(s)= X1(s) y x1
4.4 Simulation of systems
Controller
3
u 25(r x1 x2 ) 25r 25 x1 3x2
25
X2(s)
X1(s)
4.4 Simulation of systems
Function program for plant
function xdot= fun(t,x,u)
xdot= zeros(2,1);
xdot(1)= x(2);
xdot(2)= -3*x(2)+u;
x1 x2
x2 3x2 u
4.4 Simulation of systems
Primary Function
function ode02
t= 0; x= [0;0]; h= 0.01; loop= 1000;
buf= [t x(1)]; r= 1;
for i=1:loop
u= 25*r-25*x(1)-3*x(2); % Controller
x= RK4(@fun,t,x,u,h); % Plant
t= t+h; buf= [buf; t x(1)];
end
plot(buf(:,1),buf(:,2),'linewidth',2)
xlabel('t'); ylabel('y(t)');
axis([0 10 0 1.5])
4.4 Simulation of systems
Unit step response
1.5
1
y(t)
0.5
0
0 5 10
t
4.4 Simulation of systems
Example 7: The following block diagram shows the
disk head position control system. Obtain a unit step
response when Ka= 100.
d
r+ e u y
5000 m + - 1
Ka
- 𝑠 + 1000 𝑠(𝑠 + 20)
4.4 Simulation of systems
Controller
u K a (r y )
Actuator
( s 1000) M ( s) 5000U ( s)
m(t ) 1000m(t ) 5000u (t )
4.4 Simulation of systems
Linear motor
( s 2 20s )Y ( s) M ( s) D( s)
a1= 20, a2= 0 20 1 0
x x (m d )
b0= b1= 0, b2= 1 0 0 1
y 1 0 x
4.4 Simulation of systems
Actuator m(t ) 1000m(t ) 5000u (t )
function xdot= actuator(t,x,u)
xdot= -1000*x+5000*u;
20 1 0
x x (m d )
Linear motor 0 0 1
function xdot= linearmotor(t,x,u)
d= 0; % zero disturbance
xdot= zeros(2,1);
xdot(1)= -20*x(1)+ x(2);
xdot(2)= u-d;
4.4 Simulation of systems
Primary function
function head_position_control
t= 0; h= 0.001; loop= 1000;
r= 1; xa= 0; xm= [0;0]; Ka= 100;
buf= [t xm(1)];
for i=1:loop
u= Ka*(r-xm(1));
xa= RK4(@actuator,t,xa,u,h);
xm= RK4(@linearmotor,t,xm,xa,h);
t= t+h;
buf= [buf; t xm(1)];
end
4.4 Simulation of systems
plot(buf(:,1),buf(:,2),'b','linewidth',2)
axis([0 1 0 1.5])
grid on
function xdot= actuator(t,x,u)
xdot= -1000*x+5000*u;
function xdot= linearmotor(t,x,u)
d= 0;
xdot= zeros(2,1);
xdot(1)= -20*x(1)+x(2);
xdot(2)= u-d;
4.4 Simulation of systems
Unit step response
1.5
0.5
0
0 0.2 0.4 0.6 0.8 1
4.4 Simulation of systems
Example 8: Obtain the step response of the mooring
winch tensioning system.
2𝑠 + 1
d 𝑠2 + 5𝑠 + 500
r e u y
+ 1500 + - 1
PI
- 𝑠2 + 5𝑠 + 500 q 𝑠
Mooring winch
4.4 Simulation of systems
PI Controller
e(t ) r (t ) y (t )
t
u (t ) K p e(t ) K i e( )d
0
Kp: Proportional gain, Ki: Integral gain
4.4 Simulation of systems
Actuator
( s 2 5s 500)Q( s ) 1500U ( s )
x1 5 1 x1 0
q 5q 500q 1500u x x u
2 500 0 2 1500
q x1
4.4 Simulation of systems
Angular/Angle velocity
sY ( s ) Q( s ) D( s) y qd
4.4 Simulation of systems
Disturbance
( s 2 5s 500) D( s) (2 s 1)Y ( s)
x1 5 1 x1 2
d 5d 500d 2 y y x x y
2 500 0 2 1
d x1
4.4 Simulation of systems
function auto_mooring_winch
t= 0; h= 0.02; loop= 2000; r= 20; z= 0;
xa= [0;0]; xi= 0; xd= [0;0]; Kp= 0.73; Ki= 0.2;
buf= [t xi];
for i=1:loop
e= r-xi; z= z+h*e; u= Kp*e+Ki*z;
xa= RK4(@actuator,t,xa,u,h);
ui= xa(1)-xd(1);
xi= RK4(@integrator,t,xi,ui,h);
xd= RK4(@disturbance,t,xd,xi,h);
t= t+h; buf= [buf; t xi];
end
4.4 Simulation of systems
plot(buf(:,1),buf(:,2),'b','linewidth',2)
axis([0 h*loop 0 25])
function xdot= actuator(t,x,u)
xdot= zeros(2,1);
xdot(1)= -5*x(1)+x(2);
xdot(2)= -500*x(1)+1500*u;
function xdot= integrator(t,x,u)
xdot= u;
function xdot= disturbance(t,x,u)
xdot= zeros(2,1);
xdot(1)= -5*x(1)+x(2)+2*u;
xdot(2)= -500*x(1)+u;
4.4 Simulation of systems
Step response
25
20
15
10
0
0 10 20 30 40
4.4 Simulation of systems
Q&A