You are on page 1of 6

Modelling Dynamic Systems - Computer Exercise 3

3 Computer exercise 3.
Simulation of multi-state systems and
linearization
3.1 Introduction
In the previous computer exercises you learned to work with the integration routine ode45. Now
you will use this numerical integration routine to study the responses of a one tank and a two
tank example. Furthermore you will linearize the two tank system, and compare the responses
of the non-linear and the linearized system.

3.2 Preparation/Homework

3.2.1 A single tank with liquid


We want to simulate the response of the height ℎ in a tank with an incoming volume flow 𝛷H,IJ ,
see Figure 4. In example 4.4 of the lecture notes, a model is derived for the height in a tank
without inflow, based on the mass balance. With a small adaptation the incoming volume flow
𝛷H,IJ is incorporated in the model.

incoming flow 𝛷𝑉,𝑖𝑛

flow out
Figure 4: A single tank

The mass balance is


𝑑ℎ
𝜌𝐴Y = 𝜌𝛷H,IJ − 𝜌𝛽𝐴KLM [2𝑔ℎ
𝑑𝑡
with mass of liquid in the tank 𝑚 = 𝜌𝑉 = 𝜌𝐴Y ℎ (kg), mass flow into the tank 𝜌𝛷H,IJ (kg s-1) and
mass flow out of the tank 𝜌𝛽𝐴KLM [2𝑔ℎ.
The term [2𝑔ℎ is the outflow velocity (m s-1), in which 𝑔 = 9.8 m s-2 is the gravitational
acceleration, 𝛽 = 0.8 (-) is a loss factor due to the resistance of the outflow opening, 𝐴Y (m2) is
the surface of the cross section (perpendicular to the height ℎ) of the tank, 𝐴KLM (m2) is the
surface of the outflow pipe opening and 𝜌 is the density of the liquid in the tank.
The surface areas are: 𝐴Y = 1 m2, 𝐴KLM = 3 ⋅ 10^D m2, the incoming volume flow 𝛷H,IJ = 0.5 l/s,
and the initial height ℎQ = 0 m. Let’s assume the liquid is water: 𝜌 = 1000 kg/m3.

20
Modelling Dynamic Systems - Computer Exercise 3

(1) Using Figure 4 and the (given) mass balance equation; derive the differential equation
which describes the dynamic behaviour of the height ℎ in the tank. Use SI units (m, s
etc.)! Make the state space map of this problem based on the differential equation.
Determine the equation for the steady state value.

(2) Edit the Matlab function ftank1 that computes the state derivative of the height ℎ in the
tank. This is similar to fconc in the previous computer exercise.

3.2.2 Two interacting liquid tanks


Here we will consider the dynamic behaviour of two interacting tanks, see Figure 5.

incoming flow 𝛷𝑉,𝑖𝑛

ℎ1
ℎ2

flow due to interaction flow out


Figure 5: Two interacting liquid tanks

The outgoing flow from tank 2 is similar to the outgoing flow in the one tank system. The outflow
from tank 1 however depends on the difference in height in tank 1 and tank 2 [2𝑔(ℎA − ℎB ).
You can assume the tanks have the same outlet, so the same value of 𝛽. Also the surfaces 𝐴Y
(m2) and 𝐴KLM (m2) are equal.

(3) Using Figure 5 and the mass balance equations, derive the differential equations which
describes the dynamic behaviour of the heights ℎA and ℎB in the tanks. Make the state
space map of this problem based on the differential equations. Determine the steady
state values ℎA,PP and ℎB,PP . Hint: you can simplify the equations by defining a constant 𝐾
that combines 𝛽, 𝐴KLM , 𝐴Y , 𝑔.

(4) The system you find in question (3) is non-linear. Linearize the system: compute 𝐴, 𝐵 of
Uab cd cd
the linearized model UM
= 𝐴Δ𝑥 + 𝐵Δ𝑢, 𝐴 = cb e , and 𝐵 = cL e about
bfbgg ,LfLgg bfbgg ,LfLgg
the steady state 𝑥PP , 𝑢PP . Do not fill in the values of the parameters; you will use Matlab
to compute the values.

(5) In this computer exercise you will use function handles again, in several different ways.
Therefore reread paragraph 2.3.1.

21
Modelling Dynamic Systems - Computer Exercise 3

3.3 Assignments
Start up Matlab. Go to the directory M:\⋯\ce3.
Retrieve the zip-file with the programs for this computer exercise from Brightspace. Unzip the
file in the directory MDS that you made last time. Start-up Matlab. Go to the directory M:\⋯\ce3.
Also place the files that you edited and made in the preparations there (ftank1 etc.).

3.3.1 Simulation of the one tank system


1. Edit the script sim_tank1 (similar to sim_conc). The script will be used to call the
integration routine ode45 to integrate your function ftank1.
• Start with placing the parameters in the file, and specifying their values.
• State space map: map from the physical properties to 𝑥, 𝑢, 𝑝.
• Compute the steady state value for the height ℎPP based on the equation you derived
in question (1).
• Test ftank1: [dxdt] = ftank1(t(1),x0,u,p)
• Make the function handle to call ftank1 (the function that computes 𝑑ℎ/𝑑𝑡) with ode45
(the integration routine). Call the subfunction ftank1 with the function ode45 to
integrate it.
• Plot the computed height.
• If necessary, change the time step delta_t and final time t_end of the time vector.

3.3.2 Simulation of the two tank system (non-linear)


2. Write a Matlab function ftank2 that computes the state derivatives of the heights ℎA and
ℎB in the tanks, based on the original (non-linear) equations.

3. Make a script sim_tank2. You can start from a copy of sim_tank1. The script will be
used to call the integration routine ode45 to integrate your function ftank2.
• Start with placing the parameters in the file, and specifying their values. You can start
with a copy of sim_tank1.
• State space map: map from the physical properties to 𝑥, 𝑢, 𝑝.
• Compute the steady state values for the height ℎPP based on the equation you derived
in question (3).
• Define the steady states 𝑢PP and 𝑥PP .
• Test ftank2: [dxdt] = ftank2(t(1),x0,u,p). Note that you now have two heights,
and two derivatives of the heights.
• Make the function handle to call ftank2 (the function that computes 𝑑ℎ/𝑑𝑡) with ode45
(the integration routine). Call the subfunction ftank2 with the function ode45 to
integrate it.
• Plot the computed heights.
• If necessary, change the time step delta_t and final time t_end of the time vector.

3.3.3 Simulation of the two tank system with the linearized system
In question (4) you have derived the equations for the linearized system
𝑑Δ𝑥
= 𝐴Δ𝑥 + 𝐵Δ𝑢
𝑑𝑡

22
Modelling Dynamic Systems - Computer Exercise 3

Remember that Δ𝑥 (𝑡) = 𝑥(𝑡) − 𝑥PP , Δ𝑢(𝑡) = 𝑢 (𝑡) − 𝑢PP where Δ𝑥 (𝑡), Δ𝑢 (𝑡) are deviation
variables.

This equation is placed in the function ftank2lin to compute the derivatives. The tricky part
is that we now need Δ𝑥Q and Δ𝑢, and that the result from the integration with ode45 is Δ𝑥, which
is the deviation of the heights compared to the steady states.

4. In the script sim_tank2 you have computed the steady state values 𝑢PP = 𝛷H,IJ and 𝑥PP .
• Use the steady states and your equations from question (4) to compute the matrices
𝐴 and 𝐵.
• Verify your matrices 𝐴 and 𝐵 with the function linfxu
fh = @(x,u)ftank2(t,x,u,p);
[A,B] = linfxu(fh,xss,uss)
• Define Δ𝑥Q and Δ𝑢.
• Make the function handle to call ftank2lin (the function that computes 𝑑Δℎ/𝑑𝑡) with
ode45 (the integration routine). Call the subfunction ftank2lin with the function ode45
to integrate it.
• Plot the computed heights. Note that these are not the same as the results from
question 3. Did you remember that these are the deviations Δℎ? You have to add ℎPP
to obtain the heights ℎ!
• Now plot the computed heights in the same figure as the result of the non-linear
system. Use legend to indicate which line is what.

3.3.4 Influence of size of perturbation on accuracy of linearization


We are going to look at the influence of large and small perturbations on the accuracy of the
linearization.
0
Up till now the system was started with empty tanks: ℎ (0) = h i.
0

5. Run the script sim_tank2 to have the values of ℎPP available in the workspace.
• Now start the system with tanks which have an initial height of ℎA (0) = ℎA,PP + 0.12 m
and ℎB (0) = ℎB,PP + 0.10 m above the steady state value. Look at the figure with the
responses of the non-linear and the linearized system.
• Now start the system with tanks which have an initial height of ℎA (0) = ℎA,PP + 0.60 m
and ℎB (0) = ℎB,PP + 0.50 m above the steady state value. Place the results in a new
graph (change the number of figure(...)).

You have finished all the exercises? Well done!

Questions you have to answer / What will we check?


• What can you conclude about the comparison of the non-linear and the linearized system?

• Also write one question as to something that is unclear to you after this exercise.

Before you call the supervisor to sign you off:

23
Modelling Dynamic Systems - Computer Exercise 3

• Have a runnable script with everything you may need to show the supervisor. Prepare to
answer questions.

Then call the supervisor to go over your exercises and these questions. Let him/her register
that you successfully passed this exercise. Clean up your desk completely.

24
Modelling Dynamic Systems - Computer Exercise 3

25

You might also like