You are on page 1of 45

MODELLING DYNAMIC SYSTEMS USING SIMULINK

P04700
Introduction
SIMULINK is a graphical software program included with MATLAB that allows you to express a
dynamical system as a series of blocks. It is a software program which uses symbolic representation.
It is a time-based software package, and its main purpose is to solve Ordinary Differential Equations
(ODEs) numerically. For many ODEs, there is no analytical solution, particularly those involving non-
linear elements.
The numerical solvers break the ODE into small time segments, and calculate the solution numerically
for each small time segment. The length of the segment is called “step size”. Because the method is
numerical, there will be an error in the solution. This depends on the method used and the step size.
Simulink is mostly used to model dynamic systems. These are modelled mathematically so that we can
experiment, for example, with different types and designs of controller, and check that they work
properly, before installing them in the real system. In many cases, for example engine control systems
for cars, heater control systems for industrial processes, aileron control systems on aircraft, direction
controllers on a rocket, it would be far too expensive and dangerous to try out different designs on the
real system. With models you can also learn about how systems behave just sitting by a computer,
without having to be in a special lab.

1. Creating a model in Simulink


We are going to learn about Simulink through building simple models. We will begin by modelling a
simple function:
𝑦 = 5 ∗ sin⁡(𝑡)

1.1 Starting Simulink and the Library Browser

Simulink is opened from within MATLAB by clicking on the Simulink Library – or by typing ‘simulink’ in
the MATLAB Command Window.

P04700 1
We start a new Simulink model, either by selecting ‘New -> Model’ from the ‘File’ menu, or by clicking

on the icon in the top left hand corner of the Browser.

1.2 Adding Blocks to the model

P04700 2
1.3 Connecting blocks

You can either connect between blocks by clicking on the ‘source’ block while holding down the CTRL
key, and then clicking on the ‘destination’ block. Another method is to drag the mouse from one block
to another.

P04700 3
By clicking on individual blocks, parameters can be defined. The gain can be changed to 5.

1.4 Labelling Blocks and Signals


Blocks can be renamed by clicking on the block label and editing, and signals can be labelled by
double-clicking the signal line and entering text.

P04700 4
1.5 Running a Simulation

Once the model is complete, the system can be simulated by clicking on the green ‘Play’ arrow.
The results can be viewed by clicking on the Scope.
To auto-scale the results, click on the ‘auto-scale’ button.

Example no 1

Build a Simulink model to simulate the following function, and plot its output from t = 0 to t = 10s.

𝑦 = ⁡ |sin⁡(𝑡)| + 3

P04700 5
2. Solvers in Simulink

The main task in Simulink is to solve Ordinary Differential Equations (ODE) numerically. It is useful to
investigate how we can change parameters in a simulation, and the effect that this has on the results.
We will do this by considering another relatively straightforward function:
𝑦 = 5 ∗ (sin(t) + sin⁡(2t)) −10
We need to remember throughout that Simulink is a time-based software package.
2.1 Setting up the model

The default stop time for a model is t = 10s. If we solve the model for the default parameters, the
output is:

2.2 Changing the stop time


If we now change the stop time to 50s, we get a very different output.

P04700 6
What we can see is that changing the stop time has a significant effect on the resolution of the output.
For a simple system, if the maximum step size is set to ‘auto’, Simulink automatically calculates the
step size, h, as:
𝑡𝑠𝑡𝑜𝑝−𝑡𝑠𝑡𝑎𝑟𝑡
ℎ=
50
For tstop = 10 s
10−0
ℎ= = 0.2⁡𝑠
50
But for tstop = 50 s

𝟓𝟎 − 𝟎
𝒉= = 𝟏⁡𝒔
𝟓𝟎

2.3 Changing the step size


The ‘steps’ are the segments that the solver breaks the ODE into, in order to calculate the solution
numerically for this segment. Errors depend on both the step size and the method of solution chosen.
It is possible to change the step size through the model ‘Configuration Parameters’.

P04700 7
First let’s change the maximum step size to 0.1 s.

This produces an output with a much better resolution.

P04700 8
Example no 2

Now try a different model and change the stop time and Max step size (try 50s and 0.1 s).

P04700 9
2.4 Different solvers

If we return to the Model ‘Configuration Parameters’ pane, we see that there are various other
options to change:

In Simulink there are various different formulae or ‘solvers’ that can be used to solve the underlying
ODEs numerically. Simulink uses Dormund-Prince (ODE5), fourth-order Runge-Kutta (ODE4), Bogacki-
Shampine (ODE3), improved Euler (ODE2), and Euler (ODE1). A rule of thumb states that the error in
ODE5 is proportional to h5, in ODE4 to h4, and so forth. Hence, the higher the method, the smaller the
error.
Unfortunately, the higher order methods like ODE5 are very slow. To overcome this variable step size
solvers are used. The algorithm changes the step size as the model progresses. When there is very
little change in the system’s states, the step size can increase, and hence simulation is faster. On the
other hand, when the states change rapidly, then the step size can be made sufficiently small.
The variable step-size methods that Simulink uses are:
 An explicit Runge-Kutta (4,5) formula, the Dormand-Prince Pair(ODE45)
 An explicit Runge-Kutta (2, 3) pair, of Bogacki and Shampine (ODE23)
 A variable-order Adams-Bashforth-Moulton PECE solver (ODE113)
 A variable-order solver based on the numerical differentiation formulas (NDFs) (ODE15s)
 A modified Rosenbrock formula of order 2 (ODE23s)

Note: the solvers that contain the letter ‘s’ are ‘stiff’ solvers. For more information about Stiff solvers
and ODE in general look at the Simulink help files or at specialised books about numerical solutions.

P04700 10
2.5 Getting help
There are 3 ways of getting help in Simulink:

P04700 11
Or click on the ‘Help’ button at the bottom of the pane.

Or by accessing the extensive Simulink documentation on the MathWorks website:

P04700 12
There are also help boxes for individual Simulink Blocks, which can be accessed through the Library
Browser:

P04700 13
Further help can be found in the Simulink Help menu:

3 Modelling First order systems


So far we have just been modelling simple equations in Simulink. We now want to move on to model
simple Engineering systems. In the first instance we will model systems that can be described by first
order equations. The first method for solving these will be with the use of transfer functions, which
you will have already met in Control theory and the modelling of dynamical systems.
3.1 Modelling a variable flow rate fan
A variable flow rate fan can be modelled as a first order system, which can be expressed as:
𝑑𝜃𝑜
𝜃𝑖 = 𝑇 + ⁡ 𝜃𝑜
𝑑𝑡
This is very similar to many systems encountered in practice. The time constant, T, represents the
system delay, and as a result, the output rises exponentially to its new value. The “time constant” is
the time taken for about 2/3 of the change to be made (63.2% to be more accurate).

The equation relating input and output is:

 
t

Output  Gain  1  e    Input

 

P04700 14
Which is shown graphically below:

Flow rate/ kg/s

Time to make 2/3 of change

Voltage/V

It is useful to remember that by using Laplace Transforms, we can convert differential equations into
algebraic equations.

The first Laplace transform is that we replace the derivative:

d/dt with s

𝑑𝜃 𝑑2𝜃
As an example →𝑠 and → 𝑠2
𝑑𝑡 𝑑𝑡 2

For the first order system already given

becomes

𝜃𝑖 = 𝑇𝑠𝜃𝑜 + ⁡ 𝜃𝑜

= 𝜃𝑜 (𝑇𝑠 + 1)
Which can be expressed as a transfer function (ratio of Output to input). The transfer function given is
common to all first order systems:

Gain
Output   Input
s  1

P04700 15
Consider a variable-speed cooling fan driven by a motor, which is supplied by a voltage which varies
from 0 to 12 Volts. When the voltage is maximum, the maximum flowrate of air is 18 kg/sec. Assuming
the system operates in a linear way, then the gain is 18 ÷ 12 = 1.5.
The time constant of the system is observed to be 2 seconds. Hence the system transfer function, as a
function of s, is:-
1.5
Output   Input
2s  1
Hence the block diagram is

Supply voltage Air flowrate in


kg/sec

Let’s now model this system in Simulink.


Start SIMULINK by clicking on the “Library Browser” symbol here, and open a new Simulink model
from the browser.

From the Library Browser, we start a new Simulink model, and we then add a ‘Transfer Function’
block, which can be found under the ‘Continuous’ blocks menu.

P04700 16
We need to drag and drop this to add it to the new model window.
1 .5
We then want to edit the transfer function so that it is: .
2s  1
We double click on the ‘transfer function’ box, and this window will appear:

P04700 17
Change the “Numerator” to [1.5], as above. (The numerator is the top bit of the transfer function)
Change the “Denominator” to [2 1], as above. (The denominator is the bottom bit of a fraction.)
Notice that we do not write in the s, SIMULINK knows that if there is more than one digit, the first
refers to the multiplier for s.
Once you’ve done that click on OK, and then click on the name “Transfer Fcn” underneath the block.
You should then be able to edit the text. Change the name to “Blower”.
The window should then look like the one on the next page.

However, this block is just the process block, the electric motor driven air blower. On its own it is of
no interest or use at all.
We need to connect an actuator block to it, to give it some voltage, and see what the air flow is.

3.2 Actuator blocks


The force, current, torque, or whatever that drives a process has to come from somewhere. In some
cases, especially the case of electrical voltage or current, this actuator might be something very
simple, like a switch. Such a block will only have an output, and no input. The output will be controlled
by time. Such blocks are known as sources in SIMULINK.
In other cases it might be a first order actuator, and behave like the first order system above, with a
gain and a time constant. An electric motor driven from a variable voltage might sometimes behave
like this. (A complication to watch: an electric motor might be that actuator in a system driven by a
motor, but it could sometimes be the process in other cases.)
In automotive applications an engine is a common actuator, and in this case the output (e.g. torque)
will depend on at least two variables (speed, throttle position) in a rather complicated way. This is
best done using a very useful SIMULINK block called a “Lookup Table”. For this you supply known
values of output for some specific input values. SIMULINK will then interpolate between these
supplied values to calculate a value of the output for ANY set of input values.

P04700 18
In the case of our variable flow rate fan, the actuator block providing the voltage is a very simple
“Source”. In Simulink there are many different types of sources – pulses, ramps, sine waves, etc. The
best one to use as in this example is the Step input.
The step block is found under ‘Sources’ in Simulink, as shown below:

Drag this icon into the model window and place it to the left of the “Blower” block.
We also need a ‘scope’ block to look at the result.

P04700 19
You can then use the usual CAD and circuit drawing methods to join up the three blocks as shown
below.

You should then “double click” on the Step icon. A new window will open, and this should by used to
set the step size to 6 (Volts), after 1 second. Click OK to close this window.
You are now ready to run the simulation. Then click on the Scope to see the result.

This should be the result you would expect to get. The air flow-rate gradually rises up to 9 kg/sec.
This is 1.5 times the input voltage of 6 Volts. Also, it takes about 2 seconds to reach 2/3 of this value,
which is 6 kg/sec. That is because the time constant is 2 seconds.

P04700 20
3.3 Other blocks in Simulink - for system quirks and anomalies
No real system is entirely linear or without certain step changes and other quirks in their behaviour.
These are often very important in how they behave. SIMULINK provides a very wide range of blocks
that model these. Examples include:-
 Hysteresis – output values are different for rising and falling inputs. This is called backlash in
SIMULINK.
 Saturation – the output changes according to some rule, but at a certain value it will not go
any higher. This applies to very many systems, especially those involving electricity.
 Transport delay – the output changes, but takes some time to reach where it is used. Hot
fluids flowing down pipes are a classic example of this.
 Switches – the behaviour changes according to time or some other variable. A classic example
in automotive is the gearbox.

Other blocks
There is no end to the complexity of SIMULINK, and there are hosts of other blocks, but that is enough
for now. We can draw some block diagrams.

Example no. 3

We will now build a SIMULINK model of a system which is slightly more complicated. There is a heater
heating some air, but it is also sending this air down a pipe.
Air is blown over a heating element that behaves like a ‘classical’ first order system with delay.
The heater element is supplied with electric current so that a one amp current causes a 5 degree rise
in temperature, a two amp current a 10 degree rise, etc. The gain of this part of the system is thus 5.
The time constant of this simple heating element would not be large, and 0.5 seconds is a good
estimate.
5
The transfer function of this part of the system is thus given by .
0.5s  1
This heated air then passes along a tube to the process where it is needed. We will say that this causes
a transport delay which is 2 seconds. Using the same techniques as you used to make the last model,
get the following blocks into a new simulation window

The Step input block should be set to change from 0 to 10 Amps after 2 seconds.

P04700 21
The result should look like this:-

Note that the


temperature begins to
rise 2 seconds after the
current changes.

Current to the heater.

This shows both the exponential rise due to the “first order” heating element, and you can also see
the “transport delay”, as there is no change at all in the output for a full two seconds after the step
change in the input. It works as you should expect.

First refinement to model


One problem with this simulation is that the output, which is the temperature of the air, is 0 oC when
there is no current to the heater. This is unlikely to be true. We can correct this by adding the ambient
temperature of air to the temperature as it leaves the heater. We can do this by adding a “Constant”
block from “Sources”, and a “Sum” block from “Math Operations”. This is a good example where
simple Maths is needed and used. The heat is supplied to air that already has a non-zero temperature,
and that needs to be in the model.
You should be able to get these blocks, and drag them into the simulation, and get the block diagram
to look as below. You see that the temperature of the air is now the sum of ambient temperature plus
the temperature rise from the heater.

Sum block

P04700 22
However, this is not quite so easy as we might like. We also need to make sure that the Transport
Delay is set up properly with the ambient temperature as its initial value. Double click on it, to get this
window:-

Clicking on the ‘run simulation’ arrow and you will get a result like those below. The temperature now
rises from 20 oC to 70 oC, with the change beginning 2 seconds after the input current changes from 0
to 10 Amps. We now have a good realistic simulation.

Temperature

Current

P04700 23
Second refinement of model
This model is quite good. However, a problem with this type of diagram is that the lines mean all kinds
of different things in different places. It is a good idea to label the lines connecting the blocks, so that
we are clear what means what.
This can be done as follows. Firstly, spread the blocks out a bit more like this:-

Then you should then left click and then right click on the line between the heating element and the
summing block, which will open a mini-window like this:-

Click on the option “Properties”, and you will get this window:-

P04700 24
Temp rise /deg C
to be written here

In the space “Signal name” write “Temp rise /deg C”. In the “Description” you could write something
like “This line represents the temperature rise of the incoming air given by the heater, which depends
on the current. The unit is degrees Celsius.”
After clicking on OK you will see the name as given appear below the line. By holding down the left
mouse button you can drag the words to a nice middle position.
Repeat this for all the lines, using sensible names and descriptions. With a bit of position adjustment,
you should be able to make your model diagram look like that shown below.

Such additions make it much clearer what’s what – a thing that is often far from clear with these block
diagrams.

P04700 25
4 A system with an Integrator
Another important system block is the “integrator”. There are many systems in nature and machines
that work as integrators. One of the most common is the steering system of a car (or boat). The
heading angle of a car or boat is not proportional to the steering wheel (or tiller) angle, but the
integral of the angle with respect to time – the longer it is turned the more effect it has.
We will also use this example to show how you can be clever with the Step input function to create
pulses. We use two different steps, at different times, and then add them together.
The first step goes from 0 to 6 after 2 seconds. The second goes from 0 to -6 (N.B. minus 6) after 6
seconds. If we add these together we get a value of 6 from time 2 seconds to 6 seconds, i.e. it lasts 4
seconds. The actuator is made up of these two step inputs and their summing block.
The boat is the process, with its direction as the output. The gain of the process is negative, -1 – if you
have ever steered a boat you will know that is true. You put the tiller to port (left) and the boat will
turn to starboard (the right). We will assume the process is a first order system, which has a gain of 1
and a time constant of 0.5 seconds. This represents the rotational inertia of the boat. The transfer
1 1
function of the steering control of the boat is followed by an integrator , to give the
0.5s  1 s
boat direction or heading angle.
Use SIMULINK to create this block diagram for the direction control of the boat:-

Process

Actuator

When you click on the “run simulation” arrow you should be able to get an output that looks like that
on the next page.

P04700 26
Tiller force, 6N for 4
seconds.

Boat direction,
changes from 0 to
–24 degrees.

This is the sort of response we would expect from a simple system with integrating function. Notice
that:-
1. The output changes at a more-or-less steady rate while the input has a constant non-zero
value.
2. The output remains at its non-zero value even when the input returns to zero.
3. To return the output to zero, the input would need to be negative for a while.
These are the characteristics of an integrating system.

P04700 27
5 A cruise controller

We now want to develop a simple cruise controller for a car. This system will do the following:

 Read the vehicle target speed (in km/h)


 Read the current vehicle speed (in km/h)
 Command the throttle with the accelerator pedal, providing an output between 0 (not
pressed) to 1 (fully pressed)
Start by opening a new Simulink model from the Library Browser. We are firstly going to annotate the
model – this is like adding comments eg % ……. In MATLAB. Click on the Annotate button, or double
click on the white area of the model editor.

By right-clicking on this note, and selecting ‘Format’, you can change the alignment (default: centre),
and draw a border.

P04700 28
Now add two input ports (copy the first by right clicking on the first and selecting paste), and one
output ports, and re-label them as shown below. Name the model ‘cruise_control_sim’.

The simplest, and most effective cruise control algorithm is a PI (Proportional-Integral) controller. This
can be expressed in 4 steps, and a corresponding mathematical equation:
1. Calculate the error e(t) ie the difference between the target speed and the vehicle speed
2. Multiply the error by the proportional gain, Kp
3. Multiply the integral of the error by the Integral gain, Ki
4. Sum both these components to give the control signal, u(t).
𝑡

𝑢(𝑡) = 𝐾𝑝 𝑒(𝑡) + 𝐾𝑖 ∫ 𝑒(𝜏)𝑑𝜏


0

Also the throttle pedal can’t be pushed beyond its physical limits, so we need to clamp the signal
between the lower limit of 0 (throttle closed) and the upper limit of 1 (throttle open). We do this by
adding a saturation block.
Draw the Simulink model for this equation as shown below.

P04700 29
5.1 Creating Proportional and Integral sub-systems
A really useful feature in Simulink is that we can create separate sub-systems. These appear in a
hierarchy of levels, and help to make our models less cluttered and easy to understand (less like
spaghetti).
If we use the mouse to select the proportional elements, we can then right-click on the contextual
menu and create a subsystem.

We need to do the same for the Integral component, and then the diagram will look like this:

If we click on the sub-system blocks we can re-name the input and outputs as shown. We can also
move between the different levels of the sub-system by clicking on the name cruise_control_sim at
the top of the editor, or clicking on the Model Browser in the left-hand pane.

P04700 30
We can then organise the model into another sub-system by selecting all the PI controller elements
(everything except the ports and the Saturation block).

We can then create a final root system for the cruise controller by creating everything (including the
ports).

5.2 Declare workspace variables


One of the useful features of Simulink being part of the MATLAB package, is that Simulink can read
variables defined in the MATLAB workspace, and it can also output data to the MATLAB workspace.
We will show this by defining 2 variables in the MATLAB Command Window:

Kp = 1;

P04700 31
Ki = 1;

As we had defined the gains in our model using these variables, rather than constants, these values
are now defined via the workspace.
We can save this file as a MATLAB file cruise_control.m in the same folder used to save the Simulink
model.
Another useful feature is that to avoid having to load this MATLAB file every time we open the
Simulink model, we need to use the PreLoadFcn model callback. A callback is something that is
executed every time we run a particular step or model – we will meet this again when we meet
MATLAB GUIs.
If we navigate to the root subsystem, and right-click on the white space, and the choose the Model
Properties from the Contextual menu, we see this dialogue box. We then need to click on Callbacks

We then need to choose PreLoadFcn, and type in the MATLAB file we want to load every time we run
the Simulink model.

P04700 32
Often it is useful to check you haven’t made errors by using a feature called Update diagram.
Simulink usually runs this at the start of a simulation to check you haven’t made errors, but
you can do this yourself periodically. Under the Simulation menu click on Update diagram.

5.3 Running a simulation


To run the model, we need to replace the input and output ports with suitable sources and sinks.
Change your model as shown below:

The vehicle speed is set to zero, and the target speed is set as a Step block, with a Final value set to
0.1. We have also added a Scope block to view the throttle signal.

P04700 33
Save and close the model. Making sure that the current Matlab working directory is the same as the
folder used to save the Simulink model, click on the Simulink model initiate the PreLoad function. If
we run the simulation, we get an output that looks like this:

This looks right.


 Before 1 second, our target speed is 0.
 At 1 second, the target speed (and speed difference) goes to 0.1. The proportional factor of
the controller multiplies this by Kp, and the integral factor starts working.
 From 1 second onwards, the proportional contribution stays the same, but the integral
contribution rises linearly ie the slope of the throttle is equal to Ki multiplied by the speed
difference.
It is interesting to observe that the Scope graph isn’t really continuous. If you open the ‘Scope’
parameters window (click on the Parameters icon button – 2nd from the left) and choose a line marker
(under the Style tab) – such as a cross ‘x’ as shown below. Simulink only calculates the output signal
at each time step.

P04700 34
The output then looks like this:

P04700 35
6 An Automotive Example
The following example illustrates a number of important points in SIMULINK model building.
 It uses a lookup table, these are often really useful in complex systems
 It is a system with no input – the model runs using the fact that the initial value of all variables
defaults to zero. This is often useful, and often something that needs to be changed.
 The linking blocks between the actuator and the process go both ways. There is feedback. In
this case the actuator is a motor, and the torque it gives out depends on the vehicle speed.
(The vehicle being the process.)
 The linking blocks between the actuator and process, both ways, depend on and are created
from the mechanics of the process.
The vehicle is an electric Formula Student type car. The motors are two Perm PMG 132 motors
running off a 72Volt supply. These have a Torque which is, for short term operation, is limited to
38Nm. At 72 Volts this torque is maintained till 3200rpm. Above this speed the torque falls rapidly, to
zero at 3500 rpm.1
The torque speed graph appears as given below,

38

Torque/Nm

Motor speed/rpm
3200 3500

The shape of the graph is defined by the three ringed points (0,38) (3200,38) and (3500,0), and these
three points are used to set up the lookup table.
Other model information is given below.
 There are two motors, one for each rear wheel
 The motors are connected to their axles with a 4:1 gearing
 The wheel radius is 0.24m
 There is no rolling resistance or aero drag (to be corrected later!!)
 The mass of the car and driver is 300kg

1
This type of torque characteristic is common to all large permanent magnet DC motors. Small motors
start loosing torque as soon as their speed is above zero.

P04700 36
The process is simply a divide by 300, as the output acceleration = F/m, and the actuator, through the
gearing and wheels, provides Force.
So, this is the first stage of the model:-

The lookup table is set up like this:-

Type in the three points from the torque


speed graph as three vectors like this. Note,
two motors, hence 76Nm not 38.

When you run the model you will simulate the standing start, wide open throttle, full speed
acceleration of the car. You could see how the gearing affects things by experimenting with changing
values. You will notice that if you want to change the gearing, you need to change the model in TWO
places.
This very simple model gives useful results but of limited accuracy. Next week we will improve the
model, but for now we’ll leave it there.

P04700 37
7 Modelling the heating system of a house
We will build up a simple model of the heating system of a house. This is a very good way of bringing in
some more SIMULINK tools, as well as revising many of those we have already used. We will also use
the house heating system as an introduction to modelling feedback control.
The assumptions we will make are as follows:-
The actuator in this system is a “boiler”, heating hot water, and a system of hot water pipes and
radiators. We will assume the boiler has a power of 15 kW. It uses hot water radiators, and we will
assume the time constant is 10 minutes (= 600 seconds), and there is a transport delay, caused by the
need to pump the water through the system, of 2 minutes.
The actuator (boiler and radiators) will be controlled by an input which is either 0 or 1, corresponding
to ON or OFF. So, the gain of the boiler is 15,000. (The output power is 15kW when the input is 1) The
transfer function of the actuator is thus:-
15000
followed by a two minute (120 second) transport delay.
600s  1
The process in this system is the house, and it is a little complex to model. We need to think (and
model) how the input heat from the actuator (boiler and radiators) affects the temperature of the
house. We need to remember some basic physics connecting heat ant temperature. We will assume
that the heat capacity of the house is 1.5 × 106 Joules per oC. Now we know from basic
thermodynamics that:-
t
1
E  C  T so T 
C
 E , and E   P . dt
0

So to get the temperature of the house the heat power should thus be divided by C (1500000 J/oC) and
integrated. This is done in two blocks.
However, the heat power is not simply the heat supplied by the actuator (boiler and radiators). An
important complication is that heat is lost out through the windows, doors, roof and floor of the
building. A realistic value is to say that:-
Rate of loss of heat = 700 × ΔT Watts.
Here ΔT is the temperature difference between indoors and outdoors in oC. In other words, the heat
conductivity of the entire house is 700 W per oC
The model of the system should then be like that on the next page. Notice how “Sum” blocks are used
to firstly find the temperature difference between indoors and outdoors, and then to find the total
heat supply. The heat supply to the house is the difference between that supplied from the boiler and
that lost through the walls and windows etc.

P04700 38
The gain of this multiplier block should be set
to 1/1500000

This is the
boiler

The notes below explain how to change these Set the gain of this multiplier
“Sum” blocks so that they find the difference block to 700
between two signals

To set the circles that compute the difference between the indoor and outdoor temperature, and the
difference between the heat supplied and the heat lost, use the SUM block, which is found in “math
operators”. Then change it using this window which is obtained by “double clicking” it.

Change the default ++ here to +-

When you run a simulation it usually runs for about 20 seconds. This is far too short for the heating of
a house. To get it to work for a realistic time you need to change the Simulation parameters. This is
done from the “Simulation” drop down menu, and choose “Simulation parameters”.

P04700 39
This will give you a window like this:-

The only parameter you


need to change is the
Stop time here.
Make SIMULINK
simulate a 4 hour run by
changing the time as
shown. The time must
be in seconds. 4*60*60
is obviously the number
of seconds in 4 hours.

P04700 40
When this is run, by clicking on the “run simulation” arrow you should be able to get a result like this
from the scope:-

After about 3
hours the
temperature has
settled to about 32
Celsius.

This shows that if the outside temperature was 10oC, and the heating was left on full blast, the house
temperature would eventually settle out at about 31oC. This is a reasonably realistic result.
Now, play with the model, and change the outdoor temperature, the heat conductivity, and the heat
capacity of the house, and check that the model behaves as it should.
Of course, we do not really want to leave the heating on all the time. We want to put in some control.
One way to do that would be to not have the heating on all the time, but to continuously turn it on and
off. This can be done by selecting the “Pulse generator” from the “Sources” group, and using that
instead of the Step.

P04700 41
You don’t want to turn a boiler on and off too quickly, so double click on the Pulse Generator block to
get this window:-

Leave the amplitude as 1,


corresponding to “on”.

Change the period to 10


minutes, which is 600 seconds.

Start this at 80%, but try


different values later. This
means the heating is on for
80% of the time.

Make the settings as shown above, and then run the simulation again. You should find that the house
temperature settles down at a lower value. If the outdoor temperature is 10oC, then the indoor
temperature will be more reasonable that the 31oC it was before.
We could control the house temperature this way. For every outdoor temperature we could have a
fixed “pulse width”, or mark/space ratio. However, this would not be a good way of doing it. Using
“feedback control” is much more efficient.
In the next model we incorporate simple on/off feedback control, as is provided by the standard house
thermostat.

House heating system with feedback


Most real control systems will incorporate feedback. This involves taking the system output, and
comparing it with some “set point” or required value. We will start by modelling the feedback control
used in most houses, the thermostat.
When modelling systems, the “set point” and “actual output” are subtracted, giving another signal,
which is the error. This is reasonably easy to do in SIMULINK. The set input is replaced by a source of
type “Constant” (as on page 6.13.). A Sum is taken from the Math operators folder. It is then modified
so that the lower input is a – sign rather than plus, just like we did on page 6.20.
The thermostat is completed by having a ‘Relay’. This is found in the Discontinuities folder. The error
signal is fed into the relay. The output is ‘1’ when the error is greater than zero, and ‘0’ when the error
is zero or less. The current value of the output temperature is found by running a line back, as in the
diagram below.

P04700 42
These three items here simulate the thermostat.

15000 1 Indoor temperature


20 -K-
error 600s+1 heat supplied Nett Rate of s
heat supply
Set Point Relay Boiler 2 minute Divide by Integrator Scope
and water transport heat
delay capacity

-K-
Temp
diff.
10 Heat
conductivity
Outdoor
temperature

Rate of heat loss

FEEDBACK

If you make and run this simulation, you should get a result like that below.

You should be totally impressed! This is very realistic. The temperature oscillates around the set point
of 20, exactly as it does in reality.
Use this model to verify the following points, which do indeed apply to real house heating systems.

P04700 43
1. The set point on the thermostat controls the temperature reasonably well. (Change the set
point to, for example, 24.)
2. The average temperature falls in the house falls if the outside temperature falls. (Reset the set
point to 20, change the outside temperature to 0, then 18. Compare the results.)
3. There is an outside temperature at which the indoor temperature cannot be brought to 20
Celsius, even if the heating is on all the time. What is it for this house? How could the problem
be solved?

P04700 44

You might also like