Professional Documents
Culture Documents
Pedro Beiro
Instituto Superior de Engenharia de Coimbra
Departamento de Engenharia Mecnica
Rua Pedro Nunes, 3030 - 199 Coimbra, Portugal
pbeirao@isec.pt
Launching Simulink
In the MATLAB command window type
>> simulink
Workspace
Library of elements
Example 1
Build a Simulink model to solve the differential equation
= 3 sin(2t)
x(t)
Initial condition x(0) = -1
Input function 3sin(2t)
Output solution of differential equation x(t)
Example 1
Build this model in Simulink
x(0) = -1
input
3sin(2t)
x (t)
1
s
x(t)
output
x(t)
Integrator
Example 1
Drag a Sine Wave block from Sources library to the
model window
Example 1
Drag an Integrator block from Continuous library to the
model window
Example 1
Drag a Scope block from Sinks library to the model
window
10
Example 1
Place the cursor on Sine Wave block output and drag
from there to the Integrator input
Place the cursor on Integrator block output and drag from
there to the Scope input
Example 1
Double-click on Sine Wave block to set amplitude = 3
and frequency = 2
Example 1
Double-click on Integrator block to set initial condition = -1
Example 1
Run the simulation in the model window select Start
from Simulation menu
Example 1
Double-click on Scope block to view simulation results
Simulation results
15
Example 2
Build a Simulink model to solve the differential equation
+ cx(t)
+ kx(t) = f(t)
mx(t)
Second order mass-spring-damper system
Initial conditions zero
Input f(t) step with magnitude 3
Parameters m = 0.25, c = 0.5, k = 1
16
Example 2
Solve for the term with highest-order derivative
= f(t) cx(t)
kx(t)
mx(t)
Make the left-hand side of this equation the output of a
summing block
+
-
mx(t)
Sum
17
Example 2
Drag a Sum block from Math library to the model window
18
Example 2
Double-click to change block parameters to rectangular
and + - -
19
Example 2
Add a gain (multiplier) block to eliminate the coefficient m
and produce the highest-derivative alone
+
Sum
mx(t)
1
m
x(t)
Gain
20
10
Example 2
Drag a Gain block from Math library to the model window
21
Example 2
Double-click to set gain block parameter
1
1
=
=4
m 0.25
22
11
Example 2
Add integrators to obtain the desired output variable
+
Sum
mx(t)
1
m
Gain
x(t)
1
s
x (t)
Integrator
1
s
x(t)
Integrator
23
Example 2
Drag Integrator blocks from Continuous library to the
model window
24
12
Example 2
Connect gain blocks to integrated signals
+
Sum
mx(t)
1
m
Gain
x(t) 1
s
x (t)
Integrator
1
s
x(t)
Integrator
c
Gain
k
Gain
Example 2
Drag new Gain blocks from Math library to the model
window
26
13
Example 2
Drag a Scope block from Sinks library to the model
window
Example 2
Double-click on gain blocks to set parameter c = 0.5 and
parameter k = 1
28
14
Example 2
Connect all signals and inputs to the summing block
f(t)
+
-
mx(t)
1
m
Gain
Sum
cx(t)
x(t) 1
s
x (t)
Integrator
1
s
x(t)
Integrator
c
kx(t)
Gain
k
Gain
29
Example 2
Drag a Step block from Sources library to the model
window
30
15
Example 2
Double-click on Step block to set parameter
For a step input of magnitude = 3 set Final value = 3
31
Example 2
Final Simulink model
32
16
Example 2
Run the simulation in the model window select Start
from Simulation menu
33
Example 2
Underdamped response with a overshoot of 0.5 and a
final value of 3
Is this expected?
34
17
Example 2
Analysis based on motion equations
x(t)
c
1
+ x(t)
+ x(t) = f(t)
k
k
k
m
k
=2
Natural frequency n =
m
Standard form
Damping ratio 2
Static gain K =
c
= = 0.5
n k
1
=1
k
35
Example 2
Damping ratio equal to 0.5 less than 1
Expect underdamped system
Expect overshoot
Static gain is 1
Expect output magnitude match input magnitude
Input and output magnitude 3
Simulation results confirm expectations
36
18
Example 3
Single tank level system
Qin [m3/s] inlet volumetric flow of the tank
Qout [m3/s] outlet volumetric flow of the tank
h [m] water level in the tank
37
Example 3
Build a Simulink model to predict changes in the tank
level due to changes in flow conditions
Develop a mass balance
Volumetric flows a density term is needed to convert
from volume units to mass units
It is also needed to know the cross-sectional area of the
tank in order to determine the volume holdup and hence
the mass holdup in the tank
The mass balance of the simple tank system is given by:
d ( Ah )
dt
= Qin Qout
38
19
Example 3
The tank has a cylindrical shape constant cross
sectional area A = 20 m2
There is no heating effect density assumed constant
A
dh
dh
= Qin Qout A
= Qin Qout
dt
dt
h Qout = k h = 2 h
dh
dh
dh Qin k h
= Qin Qout A
= Qin k h
=
dt
dt
dt
A
39
Example 3
Final Simulink model
40
20
Example 3
Null initial conditions (set up through the integrator block)
Unit step change in the inlet flow rate of the tank system
Simulation gives the following response
H( s)
Qin ( s )
41
Example 4
Two tank level system without interaction
Qin1 [m3/s] inlet volumetric flow of the first tank
Qout1 [m3/s] outlet volumetric flow of the first tank
Qin2 [m3/s] inlet volumetric flow of the second tank
Qout2 [m3/s] outlet volumetric flow of the second tank
h1 [m] water level in the first tank
h2 [m] water level in the second tank
42
21
Example 4
43
Example 4
Build a Simulink model to predict changes in both tank
levels due to changes in flow conditions
Develop a mass balance
Volumetric flows a density term is needed to convert
from volume units to mass units
It is also needed to know the cross-sectional area of both
tanks in order to determine the volume holdup and hence
the mass holdup in both tanks
The mass balance of the two tank level system is given
by:
d ( A1h1 )
44
dt
d ( A 2h2 )
dt
= Qin2 Qout2
22
Example 4
Both tanks have a cylindrical shape constant cross
sectional area A1 = A2 = A = 20 m2
There is no heating effect density assumed constant
The flows Qout1 and Qout2 through the discharge valves
(with cross section a) are related with the water level in
both tanks:
Qout1 = k1 h1 = 2 h1 and Qout2 = k 2 h2 = 2 h2
The volumetric flow exiting the first tank feeds the second
tank Qout1 = Qin2
The mass balance equations of both tanks are given by:
45
dh1 Qin1 k1 h1
dh2 k1 h1 k 2 h2
=
and
=
dt
A
dt
A
Example 4
Final Simulink model
46
23
Example 4
Final Simulink model
47
Example 4
Final Simulink model subsystem
48
24
Example 4
Null initial conditions (set up through the integrator block)
Unit step change in the inlet flow rate of the tank system
Simulation gives the following responses
H1 ( s )
Qin1 ( s )
and
H2 ( s )
Qin2 ( s )
49
Example 5
Two tank level system with interaction
Qin1 [m3/s] inlet volumetric flow of the first tank
Qout1 [m3/s] outlet volumetric flow of the first tank
Qin2 [m3/s] inlet volumetric flow of the second tank
Qout2 [m3/s] outlet volumetric flow of the second tank
h1 [m] water level in the first tank
h2 [m] water level in the second tank
50
25
Example 5
51
Example 5
Build a Simulink model to predict changes in both tank
levels due to changes in flow conditions
Develop a mass balance
Volumetric flows a density term is needed to convert
from volume units to mass units
It is also needed to know the cross-sectional area of both
tanks in order to determine the volume holdup and hence
the mass holdup in both tanks
The mass balance of the two tank level system is given
by:
d ( A1h1 )
52
dt
d ( A 2h2 )
dt
= Qin2 Qout2
26
Example 5
Both tanks have a cylindrical shape constant cross
sectional area A1 = A2 = A = 20 m2
There is no heating effect density assumed constant
Due to the interaction between the two tanks Qout1 is
obtained by the level difference of the two tanks:
Qout1 = k 1 h1 h2 = 2 h1 h2
The volumetric flow exiting the first tank feeds the second
tank Qout1 = Qin2
The mass balance equations of both tanks are given by:
dh1 Qin1 k1 h1 h2
dh2 k1 h1 h2 k 2 h2
=
and
=
dt
A
dt
A
53
Example 5
Final Simulink model
54
27
Example 5
Tank 1 is empty and Tank 2 has a level of 1 m (set up
through the corresponding integrator block)
Unit step change in the inlet flow rate of the tank system
Simulation gives the following responses
H1 ( s )
Qin1 ( s )
and
H2 ( s )
Qin2 ( s )
55
Example 6
Mass-spring-damper system
Mass m = 4 kg
Damping coefficient c = 2 Ns/m
Spring constant k = 36 N/m
Position initial condition x(0) = 0.5 m
56
28
Example 6
Build a Simulink model of the mass-spring-damper
system
Develop a force balance using 2nd Newtons law:
= f(t) cx(t)
kx(t)
mx(t)
Find the system responses to the following inputs:
Constant input of 0 N or no input
Constant input of 100 N
Step input of 100 N with an initial value of 0, final value
of 100 and step time of 20 s
Sinusoidal input with amplitude of 100 N and frequency
of 3 rad/s
Write an m-file to plot all the responses in a single figure
57
Example 6
Final Simulink model
58
29
Example 6
m-file to plot all the system responses in a single figure
59
Example 6
System responses to the given inputs
Constant Forced Response
5
0.4
4
position (m)
position (m)
Free Response
0.6
0.2
-0.2
-0.4
10
15
20
time (sec)
25
30
35
40
10
25
30
35
40
30
35
40
0.6
0.4
position (m)
position (m)
20
time (sec)
2
1
0.2
-0.2
0
-1
15
10
15
20
time (sec)
25
30
35
40
-0.4
10
15
20
time (sec)
25
60
30
Example 7
Industrial mixing process
Qhot [m3/s] hot volumetric flow
Qcold [m3/s] cold volumetric flow
Thot [C] hot temperature
Tcold [C] cold temperature
61
Example 7
Build a Simulink model to simulate the temperature
control of a mixing process
The temperature of the mixed flow is given by:
dT Qhot Thot + QcoldTcold ( Qhot + Qcold ) T
dT Qhot Thot + Qcold Tcold QT
=
=
dt
V
dt
V
31
Example 7
Final Simulink model
63
Example 7
Final Simulink model
64
32
Example 7
Final Simulink model subsystem
65
Example 7
Final Simulink model subsystem
66
33
Example 7
Run the simulation and plot the responses of T and Q
67
34