A series of examples related to control systems will be used to illustrate the use of the Simulink program. A nonlinear ordinary differential equation, (ODE) example is used first, followed by a multivariable system, a computer controlled system, and a time varying system. It will be appreciated from these examples that systems with significant complexity can be simulated using Simulink.
Example 4.2 (block diagram solution of nonlinear differential equations). Consider the well-known Rössler chaotic equation, whose mathematical form is
˙x(t) = −y(t) − z(t),
˙y(t) = x(t) + ay(t),
˙z(t) = b + [x(t) − c]z(t).
Selecting a= b = 0.2, c = 5.7, and x(0) = y(0) = z(0) = 0, the Simulink model can be constructed and simulation analysis can be applied to the given system.
A simple trick for simulating ODEs is by assigning each integrator to a state variable to represent the output as the state xi(t ); then the input to the integrator is˙xi(t ). The Simulink model in Figure 4.13 can be easily established. The control parameters for simulation can then be set accordingly. If one starts the simulation process, two variables tout andyoutwill be returned. The time response of the three states are obtained with the
plot(tout,yout) command as shown in Figure 4.14(a).
If the states x1(t ), x2(t ), and x3(t )are used as the three axes, the phase space trajec-tories can be drawn as shown in Figure 4.14(b). The functioncomet3()can further be used to draw dynamically the trajectories of the phase space curve:
>> plot3(yout(:,1),yout(:,2),yout(:,3)) % or further using comet3 comet3(yout(:,1),yout(:,2),yout(:,3))
Many blocks in Simulink support vector operations, i.e., the block can easily process the case when several inputs are placed into a vector signal by using theMux block. If such
3
Figure 4.13. Simulink model of Rössler equations (file: c4mrossler.mdl).
0 20 40 60 80 100
(a) time response of states
−10
(b) phase space curves
Figure 4.14. Simulation results of the Rössler equations.
1
(a) improved (file: c4mross1a.mdl)
1
(b) thickened vectors (file: c4mross1b.mdl)
Figure 4.15. Another simulink description of the Rössler equations.
a signal is put through an integrator block, the output signal is also a vector, whose channels are the integrals of the input channels. Thus, the blocks in Figure 4.15(a) can be used to rewrite the blocks in the Simulink model.
In the model, the blockFcn is used to define the mathematical operation on the input signals. The input to the block is the state of the system, and the input to theFcn block is
1
(b) data types (c4mross2b.mdl)
Figure 4.16. Enhancements of vector signal blocks.
denoted byu. Ifuis a vector,u[i]can be used to denote the components of its ith channel.
Thus the model constructed is much easier than the one established in Figure 4.13, and it is more easily maintained.
The vector signals can be visually enhanced in Simulink. For instance, the For-mat/Wide nonscalar lines menu in the model window allows the thickened line expression for vector signals, as shown in Figure 4.15(b). If the user selects theFormat/Signal dimen-sions menu item, the dimendimen-sions of the signal will be displayed over the vector signals.
For instance, since the state variable is three-dimensional a “3” is displayed, as shown in Figure 4.16(a). TheFormat menu further provides the item Format/Port data types, which allows the display of data types in the signals, as shown in Figure 4.16(b). These facilities make the physical meanings more informative.
Example 4.3 (simulation of multivariable delayed systems). Consider the multivariable system in Example 3.19. Since there exists time delays in the transfer function matrix of the open-loop system, the closed-loop function matrix cannot be expressed with the feedback()function. In Example 3.19, Padé approximations are used to approximate the delay terms. There was no other way to verify the accuracy of the simulation results.
With the use of Simulink, the accurate model can be established as shown in Figure 4.17.
In the simulation model, the two input signals are assigned as the variablesu1andu2.
Recalling the Padé approximation used in Example 3.19, we can use thestep() function to find the approximate simulation results for the multivariable system above when each input acts individually:
>> g11=tf(0.1134,[1.78 4.48 1],’ioDelay’,0.72);
g21=tf(0.3378,[0.361 1.09 1],’ioDelay’,0.3);
g12=tf(0.924,[2.07 1]); g22=tf(-0.318,[2.93 1],’ioDelay’,1.29);
G=[g11, g12; g21, g22];
[n1,d1]=paderm(0.72,0,2); g11.ioDelay=0; g11=tf(n1,d1)*g11;
[n1,d1]=paderm(0.30,0,2); g21.ioDelay=0; g21=tf(n1,d1)*g21;
[n1,d1]=paderm(1.29,0,2); g22.ioDelay=0; g22=tf(n1,d1)*g22;
G1=[g11, g12; g21, g22];
Kp=[0.1134,0.924; 0.3378,-0.318]; G2=ss(G1*Kp);
[y1,x1,t1]=step(G2.a,G2.b,G2.c,G2.d,1,15);
[y2,x2,t2]=step(G2.a,G2.b,G2.c,G2.d,2,15);
1 Out1
u2 u1
Kp* u Matrix
Gain
−0.318 2.93s+1 G22(s) 0.361s +1.09s+12
0.3378
G21(s) 2.07s+1
0.924
G12(s) 1.78s +4.48s+12
0.1134
G11(s)
Delay 22 Delay 21
Delay 11
Figure 4.17. Simulink model of the multivariable system (c4mmimo.mdl).
−0.2 0 0.2 0.4
To: Out(1)
From: In(1)
0 5 10 15
0 0.2 0.4
To: Out(2)
From: In(2)
0 5 10 15
Step Response
Time (sec)
Amplitude
Figure 4.18. Comparisons of the multivariable system simulation results.
By simulating the system with Simulink, we can obtain the step response of the system driven by the two signals individually. They can be drawn together with the approximation results, as shown in Figure 4.18:
>> u1=1; u2=0; [tt1,x1,yy1]=sim(’c4mmimo’,15);
u1=0; u2=1; [tt2,x2,yy2]=sim(’c4mmimo’,15);
subplot(221), plot(t1,y1(:,1),’:’,tt1,yy1(:,1)) subplot(222), plot(t1,y1(:,2),’:’,tt1,yy1(:,2)) subplot(223), plot(t2,y2(:,1),’:’,tt2,yy2(:,1)) subplot(224), plot(t2,y2(:,2),’:’,tt2,yy2(:,2))
It can be seen from Figure 4.18 that the approximate simulation results are quite close to the exact results.
Example 4.4 (computer control system simulation). Consider the classical computer con-trolled system [53] shown in Figure 4.19, where the controller is a discrete controller, with sampling interval of T seconds. The ZOH is the zero-order-hold, and the plant is given by
ZOH - D(z) ZOH
- - - G(s)
-6
R
T T T
Y (z)
Figure 4.19. Block diagram of a computer controlled system.
2 Out2
1 Out1 a
s(s+a)
Zero−Pole Zero−Order Hold2 Zero−Order
Hold1 Zero−Order
Hold Step
K(z−z1) (z−p1) Discrete Zero−Pole
Figure 4.20. Simulink model for a computer controlled system (c4mcompc.mdl).
a continuous model. Assume that the plant and controller are given, respectively, as
G(s)= a
s(s+ 1), D(z)= 1− e−T 1− e−0.1T
z− e−0.1T z− e−T ,
where a= 0.1. It is not possible to write out the corresponding differential equation for this system, since both continuous and discrete elements exist in the system.
Simulink has the advantage that it can solve this type of hybrid problem. From the given block diagram of the system, the Simulink model can be easily established, as shown in Figure 4.20. In the system model, a few variables a, T , z1, p1, K are used, where the former two should be specified by the user, while the latter three should be calculated. In the first ZOH block, the sampling interval is set to T , and for simplicity, the rest of the blocks are assigned to−1, indicating that they inherit the sampling intervals of their input signals.
It is not necessary to put the value of T in each discrete block.
If a= 0.1, and the sampling interval is given by T = 0.2 seconds, the step response of the closed-loop system can be obtained as shown in Figure 4.21(a):
>> T=0.2; a=0.1; z1=exp(-0.1*T); p1=exp(-T); K=(1-p1)/(1-z1);
[t,x,y]=sim(’c4mcompc’,20);
plot(t,y(:,2)); hold on; stairs(t,y(:,1))
If the sampling interval is further increased to T = 1 second, the step response of the closed-loop system can be obtained as shown in Figure 4.21(b). It can be seen that when the sampling interval increases, the difference between the continuous and discrete signals increases:
>> T=1; z1=exp(-0.1*T); p1=exp(-T); K=(1-p1)/(1-z1);
[t,x,y]=sim(’c4mcompc’,20);
plot(t,y(:,2)); hold on; stairs(t,y(:,1))
In fact, with the conversion algorithm given in Chapter 2, the discrete version of the plant model can be found under sampling interval T . Thus the closed-loop discrete
0 5 10 15 20 0
0.2 0.4 0.6 0.8 1 1.2 1.4
(a) T= 0.2 seconds
0 5 10 15 20
0 0.5 1 1.5
(b) T = 1 second
Figure 4.21. Step responses for different sampling intervals.
1 Out1 Zero−Order
Hold Step
a s(s+a)
G(s) K(z−z1)
(z−p1) D(z)
Figure 4.22. Simplified computer control system (file: c4mcomc1.mdl).
system can be obtained. The step response of the system can be obtained with the following statements:
>> T=0.2; z1=exp(-0.1*T); p1=exp(-T); K=(1-p1)/(1-z1);
Dz=zpk(z1,p1,K,’Ts’,T); G=zpk([],[0;-a],a); Gz=c2d(G,T);
GG=zpk(feedback(Gz*Dz,1)), step(GG) The controller can be obtained as
Gc(z)= 0.018187(z+ 0.9934)(z − 0.9802) (z− 0.9802)(z2− 1.801z + 0.8368).
The statements can be used to get the same results with the Simulink model, and they are much simpler. However, this method has its own limitations.
Further investigation of the Simulink model shows that the ZOH after the controller D(z)is redundant, since the output of D(z) is already a discrete signal and remains the same within a sampling interval. Thus it can be removed. The ZOH on the output signal can also be removed. The simulation model can finally be reduced to the one shown in Figure 4.22, without causing any problems.
Of course, the system can be further simplified in the Simulink model, since all the ZOHs can be removed, as shown in Figure 4.23. Although this is not an official method from a theoretical aspect, the approximation is correct under Simulink.
Example 4.5 (simulation of time varying systems). Assume that the plant model is given by ¨y(t) + e−0.2t˙y(t) + e−5tsin(2t + 6)y(t) = u(t). Now consider a PI control system, shown in Figure 4.24, where Kp = 200 and Ki = 10. The width of the saturation element is δ= 2.
It can be seen that, apart from the time varying block, the modeling of the rest of system is very straightforward. In the time varying part, assume that the first-order explicit
1 Step Out1
a s(s+a)
G(s) K(z−z1)
(z−p1) D(z)
Figure 4.23. Further simplified Simulink model (file: c4mcomc2.mdl).
plant
-6- u(t )
-Kp+Ki
- s
-6
-r(t ) .. y(t )
..
δ
Figure 4.24. Block diagram of the time varying system.
1 Out1 Kp.s+Ki
s Transfer Fcn
Step Saturation
Product1 Product
1 s Integrator1
1 s Integrator
exp(−5*u)*sin(2*u+6) Fcn1 exp(−0.2*u)
Fcn Clock
x1 x2
e−0.2t
u y(t )
t
Figure 4.25. Simulink model (file: c4mtimv.mdl).
differential equations x1(t )= y(t), x2(t )= ˙y(t) can be established as
! ˙x1(t )= x2(t ),
˙x2(t )= −e−0.2tx2(t )− e−5tsin(2t+ 6)x1(t )+ u(t).
Similar to the method in Example 4.2, an integrator should be assigned to each state variable. The Simulink model in Figure 4.25 can be established, where the time varying function can be set up with Simulink blocks.
Once the simulation model is established, the following MATLAB statements can be issued to simulate the system. The step response of the time varying system can be obtained as shown in Figure 4.26.
>> opt=simset(’RelTol’,1e-8); Kp=200; Ki=10;
[t,x,y]=sim(’c4mtimv’,10,opt); plot(t,y)
0 2 4 6 8 10 0
0.5 1 1.5
Figure 4.26. Step response of the time varying system.
1 Out1 Kp.s+Ki
s Transfer Fcn
Step Saturation
Product
1/s 1/s
exp(−5*u)*sin(2*u+6) Fcn1
exp(−0.2*u)
Fcn Clock
x2(t ) x1(t ) e−0.2t t
u y(t )
Figure 4.27. Impulse response of a time varying system (c4mtimva.mdl).
Example 4.6 (impulse response). Consider again the time varying model of Example 4.5.
Assume that the input signal is a unit impulse signal. Here Simulink is used to find the impulse response of the time varying system.
Since there is no unit impulse block provided in Simulink, the step input block can be used instead to approximate it. If the step time is a, where a is an extremely small value, the initial value of the step block can be set to 1/a, and the final time can be set to 0. The simulation model in Figure 4.27 can be used to model the whole system.
Theoretically, when a → 0, the impulse signal can be approximated. In real sim-ulation, a can be set to relatively large values, for instance, a = 0.001. The impulse response of the system can be obtained with the following MATLAB statements, as shown in Figure 4.28:
>> opt=simset(’RelTol’,1e-8); Kp=200; Ki=10; a=0.001;
[t,x,y]=sim(’c4mtimva’,10,opt); plot(t,y)
In fact, even though a is selected as a large value, for instance a= 0.1, a very good approximation to the results can still be obtained.
In real applications, the inputs with arbitrary periodic signals can be established as well with the use of theRepeating Sequence block. Even more complicated signals or system behaviors can be modeled with the use of the S-functions.
0 2 4 6 8 10 0
0.02 0.04 0.06 0.08 0.1
Figure 4.28. Impulse response of the time varying system.