Sei sulla pagina 1di 8

Modelling and simulation of engineering systems

Simulink Exercise 1 - translational mechanical systems


Dr. M. Turner (mct6@sun.engg.le.ac.uk)
1 Overview of Simulink
Simulink is a package which runs in the MATLAB environment. It is used for simulating the behaviour
of dynamic systems and today forms a vital part of the design and validation processes in many, often
diverse, industries.
Simulink allows one to construct block-diagrams of systems using standard blocks such as integrators,
differentiators, gains, summing elements and such like. These blocks can be used to build up complex
systems which can then be simulated using Simulinks differential equation solver.
This first exercise will introduce you to Simulink and useful concepts such as state-space modelling,
which can simplify the use of Simulink and enhance its power.

2 State-space equations
Often when the equations of motion are derived for a system they appear as high-order differential
equations. For example, modelling two masses connected by a spring yields a fouth order differential
equation which may be expressed in the form:

(1)

where is independent of and often represents either constants, externally acting forces, or inputs of
some sort.
However, if we define the variables:

(2)
(3)
(4)
(5)

it then follows that we can write equation (1) as

(6)

(7)

or

As it is this is not useful, but then recall that, from the definitions of , etc we have that
and , so we can write the above relationships, together with equation (7) as

(8)
(9)
(10)
(11)

In other words we have transformed our fourth order ODE into four first order ODEs. Defining the

vector (where denotes the transpose of a vector) we could write this as

(12)

which is a much more compact form than equation (1).


In fact this situation holds quite generally, and assuming that the high-order differential equations
satisfy certain properties, we can always write an order differential equation as first-order
differential equations of the form:

(13)

where the state vector, x has rows. Each of the variables , etc is said to be a state variable of
the system. It is not too difficult to see that this form can greatly simplify complex, high-order ODEs.
This form is also very convenient for computation and, in fact, is the type of format in which much of
the computation associated with simulation is carried out.

3 State-space realisations of linear systems


If the system which we are considering is linear, we can simplify its description even further. The
standard procedure is to define a set of inputs, u, and a set of outputs, y and then write the system in
the following form:

(14)
(15)

where the matrices A,B,C,D are of compatible dimensions with the vectors. The first equation, (14) is
often called the state equation. In terms of our previous example, the state equation could be easily
written in this form with the matrices A,B given by

(16)

and the input being taken as (which is only a scalar in this case).
Now, imagine we would like the output to be the state variable , then the output equation (equation
(15) would be written as

(17)

This would mean the matrices C,D would be given by

(18)

The matrices A,B,C,D are often called the state-space matrices of the system.
Summary - An -th order differential equation can be re-written as a set of first order differential
equations. Given an input vector and an output vector, one can then write a description of a system in
terms of one vector first order differential equation and one algebraic vector equation. These equations
are parametrised by four matrices.

4 An example system
Let us consider a very simple system to begin with. Consider the mass-spring damper system depicted
below. Let us take the force acting on the first mass as the input to the system and the velocity of the
second mass as the output.

It is easily verified that the equations of motion governing the system are


(19)

(20)
we can write these coupled second order differential equations as a set

Defining and
of four first order differential equations, viz:

(21)

(22)

We shall now consider two different ways of describing such a system using Simulink.

(23)
(24)

4.1 Realisation using basic blocks


Such a system as above can be realised in SIMULINK using very basic elements: integrators, gains
and summing elements, together with the users favourite input and output elements.
The first step in this realisation process is to notice that an integrator block can be considered as
something which integrates the derivative of a signal to recover the signal. It is perhaps easier to
think of this pictorially as shown below. Here the input to the integrator is and thus the output will
be .

Now, in state-space systems we have expressions for s in terms of . So for example, if we had
, where is another variable and are constants, we could write this in Simulink
that
as

Note that the output of a summing block is equal to the sum of its inputs. The blocks containing and
are gain blocks.
Using only these elements we can thus draw the Simulink version of the example system as shown on
the last page of this worksheet
It can be easily seen that although the elements used to construct the Simulink block daigram are
simple, the block diagram itself is not. This is only a realisation of a very simple system. Imagine the
complexity of a complete car suspension system.....

4.2 Realisation using state-space blocks


In Simulink there is also a state-space block which takes an input signal and produces an output. To
use this, one must simply specify the state-space matrices of the system.
So, turning to our example, we can work out the state-space matrices of the system as

(25)

(26)

where we have selected the velocity of the second mass as the output.
These matrices can simply be entered into the Matlab workspace and used in the Simulink block to
simulate the system.
To enter a variable, say

, into Matlab workspace, at the command prompt type:

>>B=1
To enter matrix variables, say A, into the workspace, type:
A=[-B/M1 -K/M1 B/M1 K/M1 ; 1 0 0 0 ; B/M2 K/M2 -B/M2 -K/M2; 0 0 1 0]
The elements of the rows are separated by a space. The end of a row (and the start of the next) is
indicated by using a semi-colon.
A nice property of the system in this form is that its stability can be analysed by looking at the eigenvalues of the -matrix. Typically these eigenvalues will be complex - an imaginary part indicating that
the system is under-damped and hence will contain oscillatory modes. For (asymptotic) stability it is
a requirement that all of the eigenvalues have negative real part.
In Matlab you can view the eigenvalues of a matrix, A, by typing
>> eig(A)

4.3 A comparison
By now, the strengths of the state-space approach are probably becoming clear: they allow a general
and convenient way of simulating dynamic systems in Simulink. The individual blocks approach
seems complex, even for simple systems, and may be error prone. In addition the structure of these
connections will vary from system to system, whereas with a state-space block there is no change in
connections, only in the form of the state-space matrices.
This is not the whole story however. The simple example we have looked at is a linear system and
hence the differential equations describing it are linear. This is not true of every system and complex
systems are frequently nonlinear in some way. So while, parts of the system (which are linear or almost
linear) may be realised through Simulink state-space blocks, other parts of the system will have to be
described using individual elements.

5 Working with Simulink


To invoke Simulink, simply type
>> simulink
at the Matlab command prompt. This will bring up the Simulink library window. The library contains
most common blocks which are needed in simulation, grouped under several categories (Explore these
to familiarise yourself). Once this window has been opened, under the File tab there are options to
load/save block diagrams or to create a new diagram.

To start a new diagram under File, click New. This should bring up a blank Simulink window. To
create a block diagram simply drag blocks over from the library to the new window. The blocks can
also be connected with the mouse. Double clicking on a block in the new window will display some
of the blocks properties. This is used, amongst other things for entering parameters. Note that these
parameters must correspond to variables which exist in the Matlab workspace, or are simply numbers
or matrices of numbers.
Normally one wants to apply inputs to the system and observe the outputs. There are dedicated input
blocks, such as the step block, which will apply a step function to the system and the sine block which
will apply a sine wave to the system. These behave much the same way as any other block and require
certain parameters, such as the magnitude of the sine wave for example, to be set.
There are several different ways to observe the outputs of a system, but they are all enabled through
various different blocks. For example, connecting a scope block to a certain variable shows the timeevolution of this variable as the system simulates it. The block To workspace saves the variable to the
workspace after simulation. It can then be plotted using.
>> plot(tout,x)
assuming the variables name is (you can change the variables name by double-clicking on the block).
On later versions of Matlab, make sure that the variable is saved as a matrix or array type - double
click on the To workspace block to make sure this is the case. You should also check that the variable
tout in Simulation/Workspace I/O is set to a matrix or array type.
Before starting a simulation, there are several parameters which need to be set.To set these parameters,
click on the Simulation tab and select Parameters. A small window will be displayed containing a
selection of system parameters. The most important of these are
Stop-time - the point at which the simulation will stop.

Solver options - determines the ODE solver to find the solutions to the underlying differential
equations which describe the system. For now, leave this as it is and only change if you experience problems.

To run the simulation make follow the following steps:


1. Make sure all required variables have been entered into the Matlab workspace.
2. Ensure all connections in the Simulink diagram are correctly made and have compatible dimensions.
3. Ensure the time and solver properties are properly set.
4. Click Simulation and select Start

6 Exercise
Construct block Simulink models of the example system discussed earlier using both a connection
of individual elements and just one state-space block. Test the response of the system using various
different inputs: steps, impulses, etc. Verify that the response of the systems using the two different
realisation approaches is the same.
For your tests use the following parameter values:

Vary to between and and compare the responses.

Note you can save variables to a .mat file by using the following command:
>> save filename variable1 variable2, .....
Alternatively you can save all the variables in the workspace by simply typing:
>> save filename
A .mat file can be loaded to the workspace by typing:
>> load filename
Any current workspace variables of the same name as those in filename.mat will be over-written.
To display more than one graph at a time use
hold
to toggle the figure hold function on and off.

What do you notice about the systems response as you vary ? Do you notice anything surprising?
What does this suggest about the systems transfer function? Use the function
>> [num,den]=ss2tf(A,B,C,D)
to verify this.
What can one say about the stability of this system?
Instead of the output , now take the output as . What can we now say about the stability of the
system? Is this consistent with the physical interpretation. How can this be for a passive system?

Fa(t)

v1

x1_dot

x1

s
Integrator1

s
Integrator

B/M1
Gain
B/M2

K/M2
Gain3

Gain2
B/M1

K/M1

Gain6

K/M1
Gain1

v2

v2_dot

B/M2
Gain4
K/M2
Gain5

x2

x2_dot

s
Integrator2

s
Integrator3

Gain7

Figure 1: Simulink diagram of mass-spring system using basic elements

v1_dot

Potrebbero piacerti anche