0% found this document useful (0 votes)
72 views16 pages

Introduction To Simulink

Uploaded by

Amr Maher
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views16 pages

Introduction To Simulink

Uploaded by

Amr Maher
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Chapter 1

Introduction to Simulink

T
his chapter is an introduction to Simulink. This author feels that it is best to introduce Sim-
ulink in this chapter with a few examples. Tools for simulation and model−based designs are
presented in the subsequent chapters. Some familiarity with MATLAB is essential in
understanding Simulink, and for this purpose, Appendix A is included as an introduction to
MATLAB.

1.1 Simulink and its Relation to MATLAB


The MATLAB® and Simulink® environments are integrated into one entity, and thus we can
analyze, simulate, and revise our models in either environment at any point. We invoke Simulink
from within MATLAB. We begin with a few examples and we will discuss generalities in subse-
quent chapters. Throughout this text, a left justified horizontal bar will denote the beginning of
an example, and a right justified horizontal bar will denote the end of the example. These bars
will not be shown whenever an example begins at the top of a page or at the bottom of a page.
Also, when one example follows immediately after a previous example, the right justified bar will
be omitted.

Example 1.1
For the electric circuit of Figure 1.1, u 0 ( t ) *is the input and the initial conditions are i L ( 0 − ) = 0 ,
and v c ( 0 − ) = 0.5 V . We will compute v C ( t ) .
R L
+
1Ω 1⁄4 H C
+ vC ( t )

i(t) 4⁄3 F

vs ( t ) = u0 ( t )
Figure 1.1. Circuit for Example 1.1
For this example,
dv
i = i L = i C = C --------C- (1.1)
dt

* Throughout this text, the designation u 0 ( t ) will be used to denote the unit step function. We will use u ( t ) to
denote any other input to be consistent with the MATLAB and Simulink designations.

Introduction to Simulink with Engineering Applications, Second Edition 1−1


Copyright © Orchard Publications
Chapter 1 Introduction to Simulink

and by Kirchoff’s voltage law (KVL),


di
Ri L + L ------L- + v C = u 0 ( t ) (1.2)
dt
Substitution of (1.1) into (1.2) yields
2
dv d vC
- + vC = u0 ( t )
RC --------C- + LC ---------- (1.3)
dt 2
dt
Substituting the values of the circuit constants and rearranging we obtain:
2
1 d v dv
--- ----------C- + 4
--- --------C- + v C = u 0 ( t )
3 dt 2 3 dt

2
d vC dv
----------- + 4 --------C- + 3v C = 3u 0 ( t ) (1.4)
dt
2 dt

2
d v dv
----------C- + 4 --------C- + 3v C = 3 t>0 (1.5)
dt
2 dt

To appreciate Simulink’s capabilities, for comparison, three different methods of obtaining the
solution are presented, and the solution using Simulink follows.
First Method − Assumed Solution
Equation (1.5) is a second−order, non−homogeneous differential equation with constant coeffi-
cients, and thus the complete solution will consist of the sum of the forced response and the natu-
ral response. It is obvious that the solution of this equation cannot be a constant since the deriva-
tives of a constant are zero and thus the equation is not satisfied. Also, the solution cannot
contain sinusoidal functions (sine and cosine) since the derivatives of these are also sinusoids.
– at
However, decaying exponentials of the form ke where k and a are constants, are possible can-
didates since their derivatives have the same form but alternate in sign.
–s t –s t
It can be shown* that if k 1 e 1 and k 2 e 2 where k 1 and k 2 are constants and s 1 and s 2 are the
roots of the characteristic equation of the homogeneous part of the given differential equation,
–s1 t –s2 t
the natural response is the sum of the terms k 1 e and k 2 e . Therefore, the total solution will
be

* For a thorough discussion, please refer to Circuit Analysis II with MATLAB Applications, ISBN 0−
9709511−5−9, Appendix B.

1− 2 Introduction to Simulink with Engineering Applications, Second Edition


Copyright © Orchard Publications
Chapter 1 Introduction to Simulink

Figure 1.4. The Simulink Library Browser


2
d vC
----------- dv C
2 ---------
dt
u0 ( t ) 3 Σ ∫ dt
dt
∫ dt vC

−4

−3

Figure 1.5. Block diagram for equation (1.26)


To model the differential equation (1.26) using Simulink, we perform the following steps:

1. On the Simulink Library Browser, we click the leftmost icon shown as a blank page on
the top title bar. A new model window named untitled will appear as shown in Figure 1.6.

1− 8 Introduction to Simulink with Engineering Applications, Second Edition


Copyright © Orchard Publications
Simulink and its Relation to MATLAB

Figure 1.6. The Untitled model window in Simulink.


The window of Figure 1.6 is the model window where we enter our blocks to form a block dia-
gram. We save this as model file name Equation_1_26. This is done from the File drop menu of
Figure 1.6 where we choose Save as and name the file as Equation_1_26. Simulink will add the
extension .mdl. The new model window will now be shown as Equation_1_26, and all saved
files will have this appearance. See Figure 1.7.

Figure 1.7. Model window for Equation_1_26.mdl file


2. With the Equation_1_26 model window and the Simulink Library Browser both visible, we
click the Sources appearing on the left side list, and on the right side we scroll down until we
see the unit step function block shown as Step block. See Figure 1.8. We select it, and we drag
it into the Equation_1_26 model window which now appears as shown in Figure 1.8. We save
file Equation_1_26 using the File drop menu on the Equation_1_26 model window (right side
of Figure 1.8).
3. With reference to block diagram of Figure 1.5, we observe that we need to connect an ampli-
fier with Gain 3 to the unit step function block. The Gain block in Simulink is under Com-
monly Used Blocks (first item under Simulink on the Simulink Library Browser). See Figure
1.8. If the Equation_1_26 model window is no longer visible, it can be recalled by clicking on
the white page icon on the top bar of the Simulink Library Browser.
4. We choose the Gain block and we drag it to the right of the Step block (unit step function) as
shown in Figure 1.9. The triangle on the right side of the unit step function block and the >
symbols on the left and right sides of the gain block are connection points. We point the
mouse close to the connection point of the unit step function until is shows as a cross hair, and
draw a straight line to connect the two blocks. We double−click the Gain block and on the
Function Block Parameters, we change the gain from unity to 3. See Figure 1.10.

Introduction to Simulink with Engineering Applications, Second Edition 1−9


Copyright © Orchard Publications
Chapter 1 Introduction to Simulink

Figure 1.8. Dragging the unit step function into File Equation_1_26

Figure 1.9. File Equation_1_26 with added Step and Gain blocks
5. Next, we need to add a thee−input adder. The adder block appears on the right side of the
Simulink Library Browser under Math Operations. We select it, and we drag it into the
Equation_1_26 model window. We double click it, and on the Function Block Parameters
window which appears, we specify 3 inputs. We then connect the output of the Step block to
the input of the Gain block, and the output of the of the Gain block to the first input of the
Add block as shown in Figure 1.10.

1−10 Introduction to Simulink with Engineering Applications, Second Edition


Copyright © Orchard Publications
Simulink and its Relation to MATLAB

Figure 1.10. File Equation_1_26 with added Add block and connections between the blocks
6. From the Commonly Used Blocks of the Simulink Library Browser, we choose the Integra-
tor block, we drag it into the Equation_1_26 model window, and we connect it to the output
of the Add block. We repeat this step and to add a second Integrator block. We click the text
“Integrator” under the first integrator block, and we change it to Integrator 1. Then, we
change the text “Integrator 1” under the second Integrator to “Integrator 2” as shown in Fig-
ure 1.11.

Figure 1.11. File Equation_1_26 with the addition of two integrators


7. To complete the model to represent the block diagram in Figure 1.5, we add the Scope block
which is found in the Commonly Used Blocks on the Simulink Library Browser, we click
the Gain block, and we copy and paste it twice. We flip the pasted Gain blocks by using the
Flip Block command from the Format drop menu, and we label these as Gain 2 and Gain 3.
Finally, we double−click these gain blocks and in the Function Block Parameters dialog box,
we change the gains in Gain 2 and Gain 3 blocks from unity to −4 and −3 as shown in Figure
1.12.

Figure 1.12. File Equation_1_26 complete block diagram


dv
8. The initial conditions i L ( 0 − ) = C --------C- −
= 0 , and v c ( 0 ) = 0.5 V are entered by double−
dt t=0
clicking the Integrator blocks and entering the values 0 for the first integrator, and 0.5 for the
second integrator. To obtain a true picture of the output (voltage across the capacitor), we

Introduction to Simulink with Engineering Applications, Second Edition 1−11


Copyright © Orchard Publications
Chapter 1 Introduction to Simulink

double−click the Unit block and in the Source Block Parameters window we change the
Step time value from 1 to 0. We leave all other parameters in their default state. We also need
to specify the simulation time. This is done by specifying the simulation time to be 10 seconds
on the Configuration Parameters from the Simulation drop menu. We can start the simula-

tion on Start from the Simulation drop menu or by clicking the icon.
9. To see the output waveform, we double click the Scope block, and then clicking on the

Autoscale icon. Then we right−click near the vertical axis, we click on Axes properties,
we specify Y−min =0, Y−max = 1.5, we click OK, and we obtain the waveform shown in Fig-
ure 1.13. Henceforth, we will use this procedure to scale the vertical axis in our subsequent
Scope block displays.

Figure 1.13. The waveform for the function v C ( t ) in Example 1.1


Another easier method to obtain and display the output v C ( t ) for Example 1.1, is to use State−
Space block from Continuous in the Simulink Library Browser, as shown in Figure 1.14.

Figure 1.14. Obtaining the function v C ( t ) for Example 1.1 with the State−Space block.

1−12 Introduction to Simulink with Engineering Applications, Second Edition


Copyright © Orchard Publications
Simulink and its Relation to MATLAB
The simout To Workspace block shown in Figure 1.14 writes its input to the workspace. In this
example, we have assigned the name Example_1_1 to it, and Simulink appends it with the .mat
extension. As we know from our MATLAB studies, the data and variables created in the MAT-
LAB Command window, reside in the MATLAB Workspace. This block writes its output to an
array or structure that has the name specified by the block's Variable name parameter. It is highly
recommended that this block is included in the saved model. This gives us the ability to delete or
modify selected variables at a later time. To see what variables reside in the MATLAB Work-
space, we issue the command who or whos.*
From Equation 1.23,
x· 1
= –4 –4 1 + 4 u0 ( t )
x
x· 2 3 ⁄ 4 0 x2 0
The output equation is
y = Cx + du
or
x1
y = [0 1] + [ 0 ]u
x2

We double−click the State−Space block, and in the Functions Block Parameters window we
enter the constants shown in Figure 1.15.

Figure 1.15. The Function block parameters for the State−Space block.

* who displays only the variables names, not the function to which each variable belongs. whos lists
more information about each variable.

Introduction to Simulink with Engineering Applications, Second Edition 1−13


Copyright © Orchard Publications
Chapter 1 Introduction to Simulink

The initials conditions [ x1 x2 ]' are specified at the MATLAB command prompt as
x1=0; x2=0.5;

As before, to start the simulation we click the icon, and to see the output waveform, we dou-

ble click the Scope block. Then we click on the Autoscale icon, and we scale the vertical
axis as we did with the waveform of Figure 1.13. The waveform shown in Figure 1.16.

Figure 1.16. The waveform for the function v C ( t ) for Example 1.1 with the State−Space block.

The state−space block is the best choice when we need to display the output waveform of three or
more variables as illustrated by the following example.

Example 1.2
A fourth−order network is described by the differential equation
4 3 2
d y d y d y dy
--------- + a 3 --------3- + a 2 -------2- + a 1 ------ + a 0 y ( t ) = u ( t ) (1.27)
dt
4
dt dt dt

where y ( t ) is the output representing the voltage or current of the network, and u ( t ) is any input,
and the initial conditions are y ( 0 ) = y' ( 0 ) = y'' ( 0 ) = y''' ( 0 ) = 0 .
a. We will express (1.27) as a set of state equations

1−14 Introduction to Simulink with Engineering Applications, Second Edition


Copyright © Orchard Publications
Simulink and its Relation to MATLAB
b. It is known that the solution of the differential equation
4 2
d y d y
-------- + 2 -------2- + y ( t ) = sin t (1.28)
4
dt dt

subject to the initial conditions y ( 0 ) = y' ( 0 ) = y'' ( 0 ) = y''' ( 0 ) = 0 , has the solution
2
y ( t ) = 0.125 [ ( 3 – t ) – 3t cos t ] (1.29)
In our set of state equations, we will select appropriate values for the coefficients
a 3, a 2, a 1, and a 0 so that the new set of the state equations will represent the differential equa-
tion of (1.28) and using Simulink, we will display the waveform of the output y ( t ) .
1. The differential equation of (1.28) is of fourth−order; therefore, we must define four state vari-
ables that will be used with the four first−order state equations.
We denote the state variables as x 1, x 2, x 3 , and x 4 , and we relate them to the terms of the
given differential equation as
2 3
dy d y d y
x1 = y ( t ) x 2 = ------ x 3 = --------- x 4 = --------- (1.30)
dt 2 3
dt dt
We observe that
x· 1 = x 2
x· 2 = x 3
x· 3 = x 4 (1.31)
4
d y
--------- = x· 4 = – a 0 x 1 – a 1 x 2 – a 2 x 3 – a 3 x 4 + u ( t )
4
dt
and in matrix form
x· 1 0 1 0 0 x1 0
x· 2 0 0 1 0 x2
= + 0 u(t) (1.32)
x· 3 0 0 0 1 x3 0
x· 4 –a0 –a1 –a2 –a3 x4 1

In compact form, (1.32) is written as


x· = Ax + bu (1.33)
Also, the output is
y = Cx + du (1.34)
where

Introduction to Simulink with Engineering Applications, Second Edition 1−15


Copyright © Orchard Publications
Chapter 1 Introduction to Simulink

x· 1 0 1 0 0 x1 0
x· 2 0 0 1 0 x2
x· = , A= , x= , b= 0, and u = u ( t ) (1.35)
x· 3 0 0 0 1 x3 0
x· 4 –a0 –a1 –a2 –a3 x4 1

and since the output is defined as


y ( t ) = x1
relation (1.34) is expressed as

x1
x2
y = [1 0 0 0] ⋅ + [ 0 ]u ( t ) (1.36)
x3
x4

2. By inspection the differential equation of (1.27) will be reduced to the differential equation of
(1.28) if we let
a3 = 0 a2 = 2 a1 = 0 a0 = 1 u ( t ) = sin t

and thus the differential equation of (1.28) can be expressed in state−space form as

x· 1 0 1 0 0 x1 0
x· 2 0 0 1 0 x2
= + 0 sin t (1.37)
x· 3 0 0 0 1 x3 0
x· 4 –a0 0 –2 0 x4 1

where
x· 1 0 1 0 0 x1 0
x· 2 0 0 1 0 x2
x· = , A= , x= , b= 0, and u = sin t (1.38)
x· 3 0 0 0 1 x3 0
x· 4 –a0 0 –2 0 x4 1

Since the output is defined as


y ( t ) = x1
in matrix form it is expressed as

1−16 Introduction to Simulink with Engineering Applications, Second Edition


Copyright © Orchard Publications
Simulink and its Relation to MATLAB

x1
x2
y = [1 0 0 0] ⋅ + [ 0 ] sin t (1.39)
x3
x4

We invoke MATLAB, we start Simulink by clicking on the Simulink icon, on the Simulink
Library Browser, we click the Create a new model (blank page icon on the left of the top
bar), and we save this model as Example_1_2. On the Simulink Library Browser we select
Sources, we drag the Signal Generator block on the Example_1_2 model window, we click
and drag the State−Space block from the Continuous on Simulink Library Browser, and we
click and drag the Scope block from the Commonly Used Blocks on the Simulink Library
Browser. We also add the Display block found under Sinks on the Simulink Library
Browser. We connect these four blocks and the complete block diagram is as shown in Figure
1.17.

Figure 1.17. Model for Example 1.2 with the entries specified below
We now double−click the Signal Generator block and we enter the following in the Function
Block Parameters dialog box the following:
Wave form: sine
Time (t): Use simulation time
Amplitude: 1
Frequency: 2
Units: Hertz
Next, we double−click the State−Space block and we enter the following parameter values in
the Function Block Parameters:
A: [0 1 0 0; 0 0 1 0; 0 0 0 1; −a0 −a1 −a2 −a3]
B: [0 0 0 1]’
C: [1 0 0 0]
D: [0]
Initial conditions: x0
Absolute tolerance: auto

Introduction to Simulink with Engineering Applications, Second Edition 1−17


Copyright © Orchard Publications
Chapter 1 Introduction to Simulink

Now, we switch to the MATLAB Command window and at the command prompt we type the
following values:
a0=1; a1=0; a2=2; a3=0; x0=[0 0 0 0]’;

We change the Simulation Stop time to 25 , and we start the simulation by clicking on the
icon. To see the output waveform, we double− click the Scope block, then we click the

Autoscale icon, and we obtain the waveform shown in Figure 1.18.

Figure 1.18. Waveform for Example 1.2


The Display block in Figure 1.17 shows the value at the end of the simulation stop time.

Examples 1.1 and 1.2 have clearly illustrated that the State−Space is indeed a powerful block. We
could have also obtained the solution of Example 1.2 using four Integrator blocks.

Example 1.3
We will create a model that will produce the simultaneous solution of three equations with three
unknowns using Algebraic Constraint blocks found in the Math Operations library, Display
blocks found in the Sinks library, and Gain blocks found in the Commonly Used Blocks library.
The model will display the values for the unknowns z 1 , z 2 , and z 3 for the system of the equations

a1 z1 + a2 z2 + a3 z3 + k1 = 0
a4 z1 + a5 z2 + a6 z3 + k2 = 0 (1.40)
a7 z1 + a8 z2 + a9 z3 + k3 = 0

The model is shown in Figure 1.19.

1−18 Introduction to Simulink with Engineering Applications, Second Edition


Copyright © Orchard Publications
Simulink and its Relation to MATLAB

Figure 1.19. Model for Example 1.3 with the entries specified below
Next, at the MATLAB command prompt we enter the following values:
a1=2; a2=−3; a3=−1; a4=1; a5=5; a6=4; a7=−6; a8=1; a9=2;...
k1=−8; k2=−7; k3=5;
After clicking on the simulation icon, we obtain the values of the unknowns as z 1 = 2 , z 2 = – 3 ,
and z 3 = 5 as shown in the Display blocks in Figure 1.19.

An Algebraic Constraint block constrains the input signal f ( z ) to zero, outputs a value for z ,
and this value eventually produces a zero at the input. Thus, output is fed back to the input via a
feedback path. We can improve the efficiency of the algebraic loop solver by providing an initial
guess for the algebraic state z that is close to the final solution value. By default, the initial guess
value is zero.

An outstanding feature in Simulink is the representation of a large model consisting of many


blocks and lines, to be shown as a single Subsystem block.

Introduction to Simulink with Engineering Applications, Second Edition 1−19


Copyright © Orchard Publications
Chapter 1 Introduction to Simulink

For instance, to group all blocks and lines in the model of Figure 1.19 except the display blocks,
from the Edit drop menu we choose Create Subsystem and this model will be shown as in Figure
1.20* where at the MATLAB command prompt we have entered the following values:
a1=5; a2=−1; a3=4; a4=11; a5=6; a6=9; a7=−8; a8=4; a9=15;...
k1=14; k2=−6; k3=9;

Figure 1.20. The model in Figure 1.19 represented as a subsystem

The Display blocks in Figure 1.20 show the values of z 1 , z 2 , and z 3 for the values that we speci-
fied at the MATLAB command prompt above.
The Subsystem block is described in detail in Chapter 2, Section 2.1, Page 2−2.
1.2 Simulink Demos
At this time, the reader with no prior knowledge of Simulink, should be ready to learn Simulink’s
additional capabilities. We will explore other features in the subsequent chapters. However, it is
highly recommended that the reader becomes familiar with the block libraries found in the Sim-
ulink Library Browser. Then, the reader can follow the steps delineated in The MathWorks Sim-
ulink User’s Manual to run the Demo Models beginning with the thermo model. This model can
invoked by typing thermo at the MATLAB command prompt.
In the subsequent chapters, we will study each of the blocks under each of libraries in the Tree
Pane. They are listed in Table 1.1 below in alphabetical order, the library where they appear, the
chapter where they are described in this text, section/subsection, and page number in which they
are described.

* The contents of the Subsystem block are not lost. We can double−click on the Subsystem block to see its con-
tents. The Subsystem block replaces the inputs and outputs of the model with Inport and Outport blocks. These
blocks along with the Subsystem block are described in Section 2.1, Chapter 2, Page 2−2.

1−20 Introduction to Simulink with Engineering Applications, Second Edition


Copyright © Orchard Publications
Summary
1.3 Summary
• MATLAB and Simulink are integrated and thus we can analyze, simulate, and revise our mod-
els in either environment at any point. We invoke Simulink from within MATLAB.
• When Simulink is invoked, the Simulink Library Browser appears. The left side is referred to as
the Tree Pane and displays all libraries installed. The right side is referred to as the Contents
Pane and displays the blocks that reside in the library currently selected in the Tree Pane.
• We open a new model window by clicking on the blank page icon that appears on the leftmost
position of the top title bar. On the Simulink Library Browser, we highlight the desired library
in the Tree Pane, and on the Contents Pane we click and drag the desired block into the new
model. Once saved, the model window assumes the name of the file saved. Simulink adds the
extension .mdl.
• The > and < symbols on the left and right sides of a block are connection points.
• We can change the parameters of any block by double−clicking it, and making changes in the
Function Block Parameters window.
• We can specify the simulation time on the Configuration Parameters from the Simulation
drop menu. We can start the simulation on Start from the Simulation drop menu or by click-

ing on the icon. To see the output waveform, we double click on the Scope block, and

then clicking on the Autoscale icon.


• It is highly recommended that the simout To Workspace block be added to the model so all
data and variables are saved in the MATLAB workspace. This gives us the ability to delete or
modify selected variables at a later time. To see what variables reside in the MATLAB Work-
space, we issue the command who or whos.
• The state−space block is the best choice when we need to display the output waveform of three
or more variables.
• We can use Algebraic Constrain blocks found in the Math Operations library, Display blocks
found in the Sinks library, and Gain blocks found in the Commonly Used Blocks library, to
draw a model that will produce the simultaneous solution of two or more equations with two or
more unknowns.
• The Algebraic Constraint block constrains the input signal f(z) to zero and outputs an alge-
braic state z. The block outputs the value necessary to produce a zero at the input. The output
must affect the input through some feedback path. This enables us to specify algebraic equa-
tions for index 1 differential/algebraic systems (DAEs). By default, the Initial guess parameter
is zero. We can improve the efficiency of the algebraic loop solver by providing an Initial guess
for the algebraic state z that is close to the solution value.

Introduction to Simulink with Engineering Applications, Second Edition 1−29


Copyright © Orchard Publications

You might also like