Lec 1 Model Building in MATLAB
Lec 1 Model Building in MATLAB
Coefficient of s1 or z1
Coefficient of sn or zn
Example 1
The transfer function of a linear time-invariant system is:
2 s 2 4s 1
G( s)
3s 4 8s 3 9s 2 10s
2 s^2 + 4 s + 1
---------------------------------
3 s^4 + 8 s^3 + 9 s^2 + 10 s
If we want to perform some operation on G(s), such as computing the
step response, the quantities num and den are used as arguments to the
command.
2. Zero-Pole-Gain form
Y (s)
A transfer function G ( s ) can be expressed in terms of gain constant,
U (s)
its zeros (the solutions of Y(s) = 0) and its poles (the roots of U(s) = 0).
To create a model in this form, we enter the gain as a scalar and zeros
and poles as column vectors.
A transfer function is expressed in zero-pole-gain form:
Z (s) ( s Z (1))(s Z (2)) K ( s Z (n))
G(s) k (5)
p( s) ( s p(1))(s p(2)) K ( s p(n))
It has a gain of 10, zeros s = –2 and s = –5, and poles s = –1, s = –3+2i
and s = –3–2i. So, we could enter the lines:
>>k = 10; Gain
When using any MATLAB command to operate on G(s), we must list the
arguments in the command in the following order: zeros, poles, and gain.
3. State-Space form
The state-space approach is a unified method for modeling, analyzing, and
designing a wide range of systems. For example, the state-space approach
can be used to represent time-varying systems, nonlinear systems that have
backlash, saturation, and dead zone. Many systems do not have just a
single-input and single-output (SISO). Multiple-input, multiple-output
systems (MIMO) can be compactly represented in state-space with a model
similar in form and complexity to that used for SISO systems.
Example 3
Let's consider a passive RLC circuit shown in Fig. 1.
R L
The x1(t0) and x2(t0) represent the total initial energy of the network.
We can write two first-order differential equations in terms of the state
variables x1 and x2 as follows:
Then we may describe the Eq. (13) and Eq. (14), then the two
matrices' equations as follows:
dx1 (t )
R 1 x (t ) 1
dt L LC 1 L u (t )
dx 2 1 x 2 (t )
0 0 (15)
dt
1 x1 (t )
y (t ) 0 0 u (t )
C x 2 (t )
Thus,
R 1 1
A L
, B , C 0 1 , D 0 .
LC L
C
1 0 0
For example, let R = 5, L = 1 and C = 0.2. Then the matrices are the
following:
5 5 1
A , B , C 0 5 , D 0 .
1 0 0
So, we can enter in MATLAB the following lines:
x1 x2
x1 -5.00000 -5.00000
x2 1.00000 0
b=
input-volt.
x1 1.00000
x2 0
c=
x1 x2
output-volt. 0 5.00000
d=
input-volt.
output-volt. 0
X(s) Y(s)
G(s)
Y(s) = G(s)X(s)
+
X3(s)
Y(s) = X1(s)-X2(s)+X3(s)
X(s)
X(s) X(s)
X(s)
Example 4
Enter the subsystems that have the transfer functions:
2s 2
G1 ( s )
s 2 4s
and
4
G2 ( s) 2
s 4 s 10
and connect them in series to form a new system that has the transfer
function:
G12 ( s ) G1 ( s )G2 ( s )
Solution:
G1(s)X(s)
G1(s)
+
X(s) [G1(s) + G2(s)]X(s)
G1(s) + G2(s)
+
G2(s)
G2(s)X(s)
Solution:
>>numG1 = [2 2];
G1 ( s )
>>denG1 = [1 4 0];
>>numG2 = [4];
G 2 ( s)
>>denG2 = [1 4 10];
>>[num, den] = parallel(numG1,denG1,numG2,denG2);
>>printsys(num,den) Parallel
connection
num/den =
2 s^3 + 14 s^2 + 44 s + 20
---------------------------------- G12 ( s) G1 ( s ) G 2 ( s )
Example 6
Enter the following transfer functions:
2
G (s) 2
s 4
and
s 1
H ( s)
s5
and connect them in negative feedback to form a new system that has the
transfer function:
G (s)
T (s)
1 G (s) H (s)
Solution:
Solution:
Example 8
This is an example for the multiloop system reduction. A multiloop
feedback system is shown in Fig. 11. Our objective is to compute the
closed-loop transfer function
Y (s)
T (s)
R( s)
2
>>[num2,den2]=cloop(num1,den1,-1);
3
>>[num3,den3]=series(num2,den2,numG2,denG2) ;
4
>>[num4,den4]=feedback(num3,den3,numH2,denH2);
>>printsys(num4,den4)
num/den =
5 s^3 + 27 s^2 + 36 s
Y ( s)
------------------------------------------------ T (s)
R( s )
6 s^4 + 38 s^3 + 113 s^2 + 206 s + 168
Step 2
Step 3
Step 4
5. Model conversion
The CONTROL SYSTEM TOOLBOX contains a set of functions that allow LTI
models to be converted between the various representations. These
functions are shown in Table 1.
tf2ss
Transfer State
function Space
ss2tf
ss2zp
zp2tf
zp2ss
tf2zp
Zero-pole-gain
For two functions that convert from state-space form (ss2tf and
ss2zp), it necessary to include an additional integer argument that
designates the particular input involved. For single-input single-output
systems (SISO), this integer value is always 1.
We are illustrating the use of these functions in the following
example.
and this zero-pole form let transform to the two other forms, and finally
returning it to the original form.
Solution:
a=
x1 x2 x3 x4
x1 -9.00000 -43.00000 -75.00000 0
x2 1.00000 0 0 0
x3 0 1.00000 0 0
x4 0 0 1.00000 0
b=
u1
x1 1.00000
x2 0
x3 0
x4 0
c=
x1 x2 x3 x4
y1 0 10.00000 30.00000 20.00000
d=
u1
y1 0 State-space to
zero-pole
>>[z1,p1,k1] = ss2zp(A,B,C,D,1)
z1 =
-1.0000
-2.0000
p1 =
0
-3.0000 + 4.0000i
-3.0000 - 4.0000i
-3.0000
k1 =
Prof. Dr. Taha Helmy 24
10.0000
6. Discretisation
We also can convert between continuous-time and discrete-time models in
MATLAB as shown in the Table 2.
[numd,dend] = c2dm(num,den,Ts,'method');
Example 10
Let the continuous-time transfer function of a system is:
s2 1
G(s)
s 2 4s 4
Enter this transfer function and discretise it with the c2dm MATLAB
function, if the sample time is 0.5 sec and the conversion method is zero-
order hold (zoh).
s^2 + 4 s + 4
>>printsys(numd,dend,'z')
num/den =
z^2 - 1.67 z + 0.7696
---------------------------- G(z)
Controller Plant
C(s)
R(s) + 1 1
s2 s 2s 4
2
-
2
2
s