State Variable Models

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

1

MATLAB Applications No. (1)


State Variable Models

 Objectives:
The objectives of this application are to:
1. Obtain the state space model from the differential equations or transfer
function.
2. Convert between transfer function and state space models.
3. Determine the state transition matrix Φ(𝑠).

 State Variable Models:

The modern control tendency in engineering systems is toward greater


complexity, due mainly to the requirements of complex tasks and good
accuracy. Complex systems may have multiple inputs and multiple
outputs and may be time varying. Because of the necessity of meeting
increasingly stringent requirements on the performance of control
systems, the increase in system complexity, and easy access to large scale
computers, modern control theory, which is a new approach to the
analysis and design of complex control systems (called is the state-space
approach). This new approach is based on the concept of state.

 Advantages State Space Techniques:

This technique has the following advantages:


1. This approach can be applied to linear or nonlinear, time varying or
time invariant systems.
2. It is easier to apply where the Laplace transform cannot be applied.

Khaled Mustafa Mahmoud Session: Fall 2015/2016


2

3. This method is suitable for digital computer computation because this


is time domain approach.
4. This approach can be applied to multiple-input, multiple-output
systems.

 State Space Representation:


In state-space analysis we are concerned with three types of variables that
are involved in the modeling of dynamic systems: input variables, output
variables and state variables. A system is represented in state space by the
following equations:
𝑥̇ (𝑡) = A𝑥(𝑡) + B𝑢(𝑡) (State Equation)

𝑦(𝑡) = C𝑥(𝑡) + D𝑢(𝑡) (Output Equation)

Where:
𝑥 = state vector, 𝑥̇ = derivative of state vector with respect to time.
𝑦 = output vector, 𝑢 = input or control vector.
A = system matrix, B = input matrix, C =output matrix, D= feedforward
matrix.
A block diagram representation of state and output Equations is shown
in Figure 1.1.

Figure 1.1: Block diagram of the control system represented in state space.

Khaled Mustafa Mahmoud Session: Fall 2015/2016


3

The state-space representation for a given system is not unique because


there is more than one alternative set of state variables, except that the
number of state variables is the same for any of the different state-space
representations of the same system. There are several key canonical
forms of the state variable representation, such as the Phase Variable
Canonical Form, that we will investigate in this application. In general, we
can represent state space model (let consider the third order transfer
function when the nominator is a polynomial in s) as:
𝑌(𝑠) 𝑏2 𝑠 2 + 𝑏1 𝑠 + 𝑏0
𝐺(𝑠) = =
𝑈(𝑠) 𝑎3 𝑠 3 + 𝑎2 𝑠 2 + 𝑎1 𝑠 + 𝑎0
𝑌(𝑠) 𝑏2 𝑠 −1 + 𝑏1 𝑠 −2 + 𝑏0 𝑠 −3
𝐺(𝑠) = =
𝑈(𝑠) 1 + 𝑎2 𝑠 −1 + 𝑎1 𝑠 −2 + 𝑎0 𝑠 −3
In phase variable canonical form, we can represent this transfer function
as:
𝑥̇ 1 0 1 0 𝑥1 0
[ 𝑥̇ 2 ] = [ 0 0 𝑥
1 ] [ 2 ] + [0] 𝑢(𝑡)
𝑥̇ 3 −𝑎0 −𝑎1 −𝑎2 𝑥3 1
𝑥1
𝑦(𝑡) = [𝑏0 𝑏1 𝑏2 ] [𝑥2 ]
𝑥3
To obtain the transfer function from the state-space equations, we can be
used the following expression:
𝐺(𝑠) = C(SI − A)−1 B + D
Where: (SI − A)−1 = Φ(𝑠) is called the state transition matrix. The state
transition matrix is the exponential function that describes the unforced
response of the system.

Khaled Mustafa Mahmoud Session: Fall 2015/2016


4

Example 1.1: A single loop control system is shown in Figure 1.2. The
closed loop transfer function of the system is:
𝑌(𝑠) 2𝑠 2 + 8𝑠 + 6
𝑇(𝑠) = =
𝑅(𝑠) 𝑠 3 + 8𝑠 2 + 16𝑠 + 6

Figure 1.2: Single loop control system.

Use MATLAB to obtain state space representation of the system in the


phase variable canonical form.
Solution:
>> % To convert the transfer function T(s)=(2s^2+8s+6)/(s^3+8s^2+16s+6)..%
>> % to state space model %
>> num=[2 8 6];
>> den=[1 8 16 6];
>> T=tf(num,den)
Transfer function:
2 s^2 + 8 s + 6
-----------------------------
s^3 + 8 s^2 + 16 s + 6
>> [a,b,c,d]=tf2ss(num,den);
>> % To obtain the state space model in the phase variable canonical form %
>> A=flipud(fliplr(a))
A=
0 1 0
0 0 1
-6 -16 -8
>> B=flipud(b)
B=
0
0
1
>> C=fliplr(c)
C=
6 8 2

Khaled Mustafa Mahmoud Session: Fall 2015/2016


5

Example 1.2: A system is described by the differential equation:


𝑦⃛ + 6𝑦̈ + 11𝑦̇ + 6𝑦 = 20 𝑢(𝑡)

Where 𝑦 is the output and 𝑢 is the input to the system (𝑢(𝑡) = 1). Obtain
state space representation of the system.
Solution:
>> % Firstly, convert the differential equation to transfer function%
>> Y=laplace(dsolve('D3y+6*D2y+11*Dy+6*y=20','y(0)=0,Dy(0)=0,D2y(0)=0'));
>> pretty(simplify(Y))
20
------------------------------ % Y(s) = T(s)*U(s), U(s) = 1/s %
s (s + 1) (s + 2) (s + 3)
>> % The transfer function T(s)=20/(s+1)(s+2)(s+3) %
>> num=20;
>> den=conv([1 1],conv([1 2],[1 3]));
>> [a,b,c,d]=tf2ss(num,den);
>> % To obtain the state space model in the phase variable canonical form %
>> A=flipud(fliplr(a))
A=
0 1 0
0 0 1
-6 -11 -6
>> B=flipud(b)
B=
0
0
1
>> C=fliplr(c)
C=
20 0 0

Khaled Mustafa Mahmoud Session: Fall 2015/2016


6

Example 1.3: The two tank system shown in Figure 1.3(a) is controlled by
a motor adjusting the input valve and ultimately varying the output flow
rate. The system has the block diagram shown in Figure 1.3(b). Use
MATLAB to:
1. Obtain the matrix differential equation for the phase variable form.
2. Plot the output response of the system when the input signal is unit step.

Figure 1.3: A two tank system with the motor current controlling the output flow rate.
(a) Physical diagram. (b) Block diagram.
Solution:
>> % Firstly, determine the transfer function: G(s)= Q o(s)/I(s)%
>> s=tf('s');
>> G1=10/(s+5);
>> G2=3/(s+2);
>> G3=1/(s+3);
>> G=series(G1,series(G2,G3))
Transfer function:
30
--------------------------------
s^3 + 10 s^2 + 31 s + 30

Khaled Mustafa Mahmoud Session: Fall 2015/2016


7

>> % To convert the transfer function G(s)=1/(s^3+10s^2+31s+30)..%


>> % to state space model %
>> num=30;
>> den=[1 10 31 30];
>> [a,b,c,d]=tf2ss(num,den);

>> % To obtain the state space model in the phase variable canonical form %
>> A=flipud(fliplr(a))
A=
0 1 0
0 0 1
-30 -31 -10
>> B=flipud(b)
B=
0
0
1
>> C=fliplr(c)
C=
30 0 0
>> % To plot the output response of the system for the unit step input %
>> t=0:0.01:10;
>> r=heaviside(t);
>> lsim(a,b,c,d,r,t)
>> title('Step Response of the Two Tank System')
>> xlabel('Time')
>> ylabel('Output Flow Rate')
>> gtext('Input')
>> gtext('Output')

Khaled Mustafa Mahmoud Session: Fall 2015/2016


8

Step Response of the Tw o Tank System

Input
1

Output

0.8
Output Flow Rate

0.6

0.4

0.2

0
0 1 2 3 4 5 6 7 8 9 10
Time (sec)

Figure 1.4: Output response of the two tank system for Example 1.3.

Example 1.4: A single input single output system has the matrix equation:

0 1 0
𝑥̇ = [ ]𝑥 + [ ]𝑢
−3 −4 1

and

𝑦 = [10 0]𝑥

Using MATLAB:
1. Determine the state transition matrix Φ(𝑠).
2. Determine the transfer function 𝐺(𝑠) = 𝑌(𝑠)/𝑈(𝑠).

Khaled Mustafa Mahmoud Session: Fall 2015/2016


9

Solution:

>> % 1. To determine the state transition matrix 𝚽(𝐬) %


>> syms s
>> A=[0 1;-3 -4];
>> B=[0;1];
>> C=[10 0];
>> D=[0];
>> I=eye(2);
>> Phi=inv(s*I-A)
>> pretty(Phi)
+- -+
| s+4 1 |
| -------------------, --------------- |
| s2 +4s+3 s 2+ 4 s + 3 |
| -3 s |
| -------------------, ------------------ |
| s2 + 4 s + 3 s2 + 4 s + 3 |
+- -+

>> % 2. To determine the transfer function 𝑮(𝒔) = 𝒀(𝒔)/𝑼(𝒔) %

>> [num,den]=ss2tf(A,B,C,D) >> G=C*Phi*B


num = >> pretty(G)
0 0 10
den =
1 4 3
>> G=tf(num,den)

Transfer function:
10
------------------
s^2 + 4 s + 3

Khaled Mustafa Mahmoud Session: Fall 2015/2016


10

Example 1.5: Transfer function of a system is:


𝑌(𝑠) 3𝑠 2 + 10𝑠 + 15
=
𝑅(𝑠) 𝑠 3 + 8𝑠 2 + 12𝑠 + 9
That can be represented in the state space model for the phase variable
form, where:
𝑥̇ 1 0 1 0 𝑥1 0
[ 𝑥̇ 2 ] = [ 0 0 1 ] [𝑥2 ] + [0] 𝑟(𝑡)
𝑥̇ 3 −9 −12 −8 𝑥3 1
𝑥1
𝑦(𝑡) = [15 10 3] [𝑥2 ]
𝑥3
Using MATLAB Simulink:
1. Simulate the state space model of the system.
2. Obtain the output response for the unit step input.
Solution:
The simulation of the system using MATLAB Simulink as shown in Figure 1.5:

Figure 1.5: Simulation the system of Example 1.5 using MATLAB Simulink.

Khaled Mustafa Mahmoud Session: Fall 2015/2016


11

The unit step response of the system as shown in Figure 1.6:


Unit Step Response of the System
1.8

1.6 Output

1.4

1.2

1
Output

Input

0.8

0.6

0.4

0.2

0
0 1 2 3 4 5 6 7 8 9 10
Time(sec)
Figure 1.6: Unit step response of the system for Example 1.5.
--------------------------------------------------------------------------------------------
Homework 1.1: Consider the spring - mass - damper system as shown in
Figure 1.7. The external force 𝑟(𝑡) is the input to the system (unit step),
and the displacement 𝑦(𝑡) of the mass is the output where 𝑀 = 1.5 kg,
𝑘 = 100 N/m, and 𝑏 = 20 N. s/m.

Figure 1.7: A spring – mass – damper system.

Khaled Mustafa Mahmoud Session: Fall 2015/2016


12

Do the following:
1. Obtain the differential equation of the system. Assume the initial
conditions equals to zero.
2. Use MATLAB to obtain state space representation of the system in the
phase variable canonical form.
--------------------------------------------------------------------------------------------
Homework 1.2: A system has a block diagram as shown in Figure 1.8. Do
the following using MATLAB:
1. Determine the overall transfer function 𝑌(𝑠)/𝑅(𝑠).
2. Determine the state variable differential equation in a matrix form.
3. Obtain the state transition matrix Φ(𝑠) and Φ(𝑡).

Figure 1.8: Feedback control system.


--------------------------------------------------------------------------------------------
Homework 1.3: Consider the two systems:
0 1 0 0
𝑥̇ 1 = [ 0 0 1 ] 𝑥1 + [0] 𝑢
−4 −5 −8 4

𝑦 = [1 0 0]𝑥1 (1)
and

0.5000 0.5000 0.7071 0


𝑥̇ 2 = [ −0.5000 −0.5000 0.7071 ] 𝑥2 + [0] 𝑢
−6.3640 −0.7071 −8.000 4
𝑦 = [0.7071 −0.7071 0]𝑥2 (2)

Khaled Mustafa Mahmoud Session: Fall 2015/2016


13

Perform the following:


1. Using the tf function, determine the transfer function 𝑌(𝑠)/𝑅(𝑠) for
system (1).
2. Repeat part (1) for system (2).
3. Compare the results in parts (1) and (2) and comment.
--------------------------------------------------------------------------------------------
Homework 1.4: A single input single output system has the matrix equation:
𝑥̇ 1 0 1 0 𝑥1 0
[𝑥̇ 2 ] = [ 0 0 1 ] [𝑥2 ] + [0] 𝑟(𝑡)
𝑥̇ 3 −3 −2 −5 𝑥3 4
𝑥1
𝑦 = [1 0 0] [𝑥2 ]
𝑥3
1. Simulate the state space model of the system using MATLAB Simulink,
and obtain the output response for the sine wave input.
2. Using the tf function, determine the transfer function 𝑌(𝑠)/𝑅(𝑠).
3. Repeat part (1) if the system in the transfer function form.
4. Compare the results in parts (1) and (3) and comment.

Khaled Mustafa Mahmoud Session: Fall 2015/2016

You might also like