Sei sulla pagina 1di 32

Downloaded 09/09/15 to 130.237.29.138. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.

php

Chapter 1

Introduction to Simulink

The best way to follow the details of this book is to have a copy of Simulink and work
the examples as you read the text. The examples described in the book are all in the
Numerical Computing with Simulink (NCS) library that is available as a download from
The MathWorks (www.mathworks.com). The files are located in an ftp directory on the site.
As you work your way through this text, the Simulink and MATLAB files you will
run are in boldface Courier type. When you need to run a model or M-file, the text
shows the exact MATLAB command you need to type.
After you download the NCS library, place it on the MATLAB path using the “Set
Path” command under the MATLAB file menu. Alternatively, you can save the NCS files
and use the MATLAB directory browser (at the top of the MATLAB window) or the cd
command to change to the directory that contains the NCS library.

1.1 Using a Picture to Write a Program


In order to understand the Simulink models that we use to illustrate the mathematical princi-
ples, this chapter provides the reader with a brief introduction to Simulink and its modeling
syntax. In my experience, the more familiarity a user has with the modern click-and-drag
technique for interfacing with a computer, the easier it is to build (and understand) a Simulink
model.
In essence, a Simulink model provides a visual depiction
of the signal flow in a system. Conceptually, signal flow di-
agrams indicate that a “block” in the diagram (as represented
by the figure at left) causes an operation on the input, and the
result of that operation is the output (which is then possibly the
input to the next block). The operation can be as simple as a “gain block,” where the output
is simply the product of the input and a constant (called the gain).
Signal flow in the diagram splits, so several different blocks have the same input.
Then the signal can be coalesced into a single signal through addition (subtraction) and
multiplication (division). The diagram illustrates this; the “output” y is y = K1 u − K2 u
(or y = (K1 − K2 )u). The power of this type of diagram is that K1 or K2 may represent an

1
2 Chapter 1. Introduction to Simulink
Downloaded 09/09/15 to 130.237.29.138. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Figure 1.1. Simulink library browser.

operator which might be a matrix, a difference equation, a differential equation, integration,


or any of a large number of nonlinear operations.
The signals in a block diagram (y, u, and any intermediate terms not explicitly named)
are usually functions of time. However, any independent variable may be used as the
underlying simulation variable. (For example, it may be the spatial dimension x, or it might
simply be interpreted as an integer representing the subscript for a sequence of values.)
The Simulink environment consists of a library of elementary building blocks that are
available to build a model and a window where the user builds the model. Figure 1.1 shows
the Simulink library browser. Open this browser by typing
simulink

at the MATLAB command line (or alternatively by clicking on the Simulink icon that
appears below the menu at the top of the MATLAB window). In either case, the result is
that you will open the Simulink browser and a window for building the model.
The browser consists of a catalog of 16 types of blocks. The catalog is a grouping of the
blocks into categories that make it easier for the user to find the appropriate mathematical
1.1. Using a Picture to Write a Program 3
Downloaded 09/09/15 to 130.237.29.138. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

element, function, operation, or grouping of elements. A quick look at the list shows
that the first element in the catalog is the “Commonly Used Blocks.” This, as the name
implies, is redundant in that it contains blocks from other elements in the catalog. The
second set of elements in the library is denoted “Continuous.” This element contains the
operator blocks needed to build continuous time ordinary differential equations and perform
numerical integration. Similarly, the library element “Discrete” contains the operators
needed to develop a discrete time (sampled data) system. All math operations are in the
“Math Operations” catalog element.
To understand how to build a Simulink model, let us build a simple system.
In many applications, simple trigonometric transformations are required to resolve
forces into different coordinates. For example, if an object is moving in two dimensions
with a vector velocity v at an angle θ relative to the x-axis of a Cartesian coordinate system
(see figure), then the velocity along the x-axis is v cos(θ ) and along the y-axis is v sin(θ ).

A Simulink model that will compute this is in the figure


at the right. If you do not want to build this model from
scratch, then type
Simplemodel

at the MATLAB command line. However, if this is the first


time you will be using Simulink, you should go through the
exercise of building it. Remember that the model building
uses a click-and-drag approach. As we discussed above, the
trigonometric functions in the blocks are operators in the sense
that they operate on the input signal v to create the output.
To build the model, open Simulink and use the empty model window that opens or, if
the empty window is not open, click on the blank paper icon at the upper left of the Simulink
library browser (the circled icon in the Simulink library browser, Figure 1.1). The empty
model window that is open will appear with the name “Untitled.” All of the mathematical
functions needed for building this model are in the Math Operations section of the browser.
This section of the browser is opened by clicking on the words “Math Operations” in the
browser or by clicking on the + symbol at the “Math Operations” icon in the right side of
the browser window. (The browser is set up to work the same as the browser in Windows.)
Math Operations contains an icon for all of the math operations available for use in Simulink
models (in alphabetic order). We will need the Trigonometric Function block. To insert
this block in the model, click on it and drag it into the “untitled” model window. We will
need two of these blocks, so you can drag it twice. Alternatively, after the first block is in
the model window, you can right click on the block in the diagram (which will create a copy
of the block) and then (still holding down the right click button on the mouse) drag the copy
to another location in the diagram.
4 Chapter 1. Introduction to Simulink
Downloaded 09/09/15 to 130.237.29.138. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

We will assume that the velocity v is a MATLAB variable that is in the MATLAB
workspace. To bring this variable into the Simulink model, a block from the Sources library
is required. To open this library, locate the Sources Library in the Simulink Browser.
This will open a large number of Simulink blocks that provide sources (or inputs) for the
model. The “Constant” block allows you to specify a value in MATLAB (created using the
MATLAB command window), so click on it and drag it into the untitled model window.
To make this input the velocity v, double click on the Constant block to open the “Block
Parameters” window. In general, almost all Simulink blocks have some form of dialog that
sits (virtually) behind the block; open these dialogs by double clicking the block. As we
go through the steps in building a model, we will investigate some of the dialogs. It is a
good idea to spend some time familiarizing yourself with the contents of these dialogs by
browsing through the library one block at a time and opening each of their dialogs to see
what is possible. For now, in the “Block Parameters” window change the Constant value to
v, and click OK to close the “Block Parameters” window.
We are now ready to create the signal flow in the diagram. Look carefully at the icons
in the model. You will see arrowheads at either the input or output (or both) for each of
the blocks. You can connect blocks manually or automatically. To connect them manually,
click the mouse on the arrowhead at the output of the constant block, drag the line to the
input of the Trigonometric Function block (either one), and release the mouse button when
the icon changes from a plus sign to a double plus sign. This should leave a line connecting
the input to the trig block. To connect the second trig block, start at the input arrow of
this block and drag the line to the point on the previous connection that is closest to the
block. This will take a little getting used to, so try it a couple of times. The last part of
the modeling task is to change the sin function (the default for the trigonometric function
from the library) to a cos. This block has a dialog behind it that allows changes, so double
click on the block that will become the cosine and use the pull down menu in the dialog
called “Function” to select cos. Two additional boxes in the dialog allow you to specify the
output type (auto, real, or complex) and the sample time for the signal. We can ignore these
advanced functions for now. Try to move the blocks around so they look like the blocks in
the Simplemodel figure above.
As you were connecting the first two blocks, a message from Simulink should have
appeared, telling you that there is an automatic way of connecting the blocks. Do this by
clicking (and thereby highlighting) the block that is the input and, while holding down the
control (Ctrl) key, clicking on the block that this input will go to. Simulink will then create
(and neatly route) a line to connect the two blocks.
This simple model introduces you to click and drag icon-based mathematical models.
It is simple, obviously too simple for the work needed to create it. It would be far easier to
do this in MATLAB.
Simulink provides a visual representation of the calculations involved in a process. It
is easier to follow complex calculations visually, particularly if they involve flow in time.
Toward this end, it is very possible to build a diagram that obscures the flow rather than
enhances it. We call such a diagram a “spaghetti Simulink model” (like spaghetti code).
To avoid this, it is important to make the connections clear and the model visually easy to
navigate. Simulink allows you to do this by dragging the icons around the diagram to make
it look better. It is a good idea to get used to this right from the start. Therefore, spend a
few minutes manipulating the diagram with the mouse. In addition, blocks move (nudged
1.2. Example 1: Galileo Drops Two Objects from the Leaning Tower of Pisa 5
Downloaded 09/09/15 to 130.237.29.138. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

up or down and back and forth) with the arrow keys. Simply highlight the block and press
the arrow key to move it one grid point.
To flip a block, highlight it and use Ctrl + i, and to rotate a block, highlight it and use
Ctrl + r. Once again, try these steps. If you want to save the example you created, click the
floppy disk icon at the top of the model window and save the model in any directory you
want. (Be careful not to overwrite the model “Simplemodel” in the NCS directory.)

1.2 Example 1: Galileo Drops Two Objects from the


Leaning Tower of Pisa
To illustrate a Simulink model that solves a differential equation, let us build a model that
simulates the “experiment” that is attributed to Galileo. In the experiment, he went to the
upper level of the Leaning Tower of Pisa (Figure 1.21 ) and dropped a heavy object and a light

Figure 1.2. Leaning Tower of Pisa.

1 This photograph is from my personal collection. It was taken during a visit to Pisa in May of 2006. If Galileo

performed the experiment, he most likely would have used the upper parapet at the left of the picture. (Because
of the offset at the top, it would have been difficult to use the very top of the tower.)
6 Chapter 1. Introduction to Simulink
Downloaded 09/09/15 to 130.237.29.138. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

object. The experiment demonstrated that the objects both hit the ground at the same time.
Is it true that this would happen? Let us see (this model is in the NCS library, where it is
called Leaningtower—you can open it from the library, but if this is your first experience
with Simulink, use the following instructions to create the model instead).
Thanks to Newton, we know how to model the acceleration due to gravity. Denote
the acceleration at the surface of the earth by g (32.2 ft per sec per sec). Since the force on
the object is mg and Newton’s first law says that
F = ma,
we have
d 2x
m = −mg.
dt 2
From this, it follows immediately that the mass of the object does not enter into the calcu-
lation of the position (and velocity), and the underlying equation of motion is
d 2x
= −g.
dt 2
We assume that Galileo dropped the balls from the initial location of 150 ft, so the initial
velocity is dx(0)
dt
= 0 and the initial position is x(0) = 150.
Even though this formulation of the equation of motion explicitly shows that Galileo’s
experiment has to work, we continue because we are interested in seeing if the experimental
results would in fact have shown that the objects would touch the ground at the same
time. Initially we model just the motion as it would be in a vacuum. A little later in this
section, we will add air drag to the model. The model of any physical device follows
this evolutionary path. Understanding the physical environment allows the developer to
understand the ramifications of different assumptions and then add refinements (such as air
drag) to the model.
The equation above is probably the first differential equation anyone solves. It has a
solution (in the foot-pound-second [fps] system) given by
dx(t)
= −32.2t,
dt
x(t) = −16.1t 2 + 150.
Since the experiment stops when the objects hit the ground, the final time for this experiment
is when x(t) = 0. From the analytic solution, we find that this time is

150
t= .
16.1
Go into MATLAB and compute this value. MATLAB’s full precision for the square root
gives
>> format long
>> sqrt(150/16.1)

ans =

3.05233847833680
1.2. Example 1: Galileo Drops Two Objects from the Leaning Tower of Pisa 7
Downloaded 09/09/15 to 130.237.29.138. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

We will return to this calculation after we use Simulink to model and solve this
equation because it will highlight a feature of Simulink that is numerically very important.
Now, to build the Simulink model of the motion we need to create the left-hand side
of the differential equation and then integrate the result twice (once to get the velocity and
then again to get the position).
Five types of Simulink blocks are required to complete this model:

• Three input blocks are used to input the constant g into the equation and to provide
the initial position and to provide a value to test the position against to determine
whether the object has reached the ground.
• Two integrator blocks are needed to compute the velocity and position from the
acceleration.
• One block will perform the logic test to see when the object hits the ground.
• One block will receive the signal from the logic block to stop the simulation.
• One block will create a graph of the position and velocity as a function of time.

These blocks are in sections of the Simulink library browser as follows:

• The inputs are in the Sources library.


• The integrator is in the Continuous library.
• The block to test to see if the object has hit the ground is a Relational Operation, and
it is in the Logic and Bit Operations library.
• The block to stop the simulation is in the Sinks library.
• The graph is a Scope block and is in the Sinks library.

So let us start building the model. As we did above, open up the Simulink browser
and a new untitled model window. Accumulate all of the blocks in the window before we
start to make connections. Thus, open the Sources, Continuous, Logic and Bit Operations,
and Sinks libraries one by one, and grab the icons for a Constant, an Integrator, a Relational
Operator, and the Stop and drag them into the untitled model window.
The integrator block in the Continuous library uses the Laplace operator 1s to denote
integration. This is a bit of an abuse of notation, since strictly speaking this operator
multiplies the input only if it is the Laplace transform of the time signal. However, Simulink
had its origins with control system designers, and consequently the integration symbol
remains in the form that would appear in a control system block diagram.
In fact, the integrator symbol invokes C-coded numerical integration algorithms that
are the same as those in the MATLAB ODE suite to perform the integration. The C-coded
solvers are compiled into linked libraries that are invoked automatically by Simulink when
the simulation is executed. (Simulink handles all of the inputs, outputs, initial conditions,
etc. that are needed.) We will talk a little more about the ordinary differential equation
solvers later, but if the reader is interested in more details about the numerical integration
solvers, consult Chapter 7 of NCM [29].
8 Chapter 1. Introduction to Simulink
Downloaded 09/09/15 to 130.237.29.138. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Figure 1.3. Integrator block dialog.

Make copies of the integrator and the constant block (since we need two integrators
and three constants); as before, either copy it by right clicking or drag a second block into
the model from the browser.
Make the connections in the model. Next, change the Constant block values by double
clicking to open its dialog box. Change the first of these to make the value –g, change the
second to make the value 0 (which will be used to test when the position of the object is at
the “ground”), and then change the third so its value is 150 (the initial position of the object
at the top of the Leaning Tower of Pisa).
Modify the integrator block to bring the initial conditions into the model. When
you double click the integrator block, the “Block Parameters” menu, shown in Figure 1.3,
appears.
In this menu, you can change the way the numerical integration handles the integral.
The options are as follows:

• Force an integration reset (to the initial condition) when an external reset event occurs.
This reset can be increasing as a function of time (i.e., whenever the reset signal is
increasing, the integrator is reset), it can be decreasing, or it can be either (i.e., the
integration will take place only if the reset signal is unchanging), and finally, the reset
can be forced when the reset signal crosses a preset threshold.
• The initial conditions can be internal or external. If it is internal, there is a box called
“Initial condition” (as shown above) for the user to specify the value of the initial
1.2. Example 1: Galileo Drops Two Objects from the Leaning Tower of Pisa 9
Downloaded 09/09/15 to 130.237.29.138. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Figure 1.4. Simulink model for the Leaning Tower of Pisa experiment.

condition. When it is set to external, an additional input to the integrator appears on


the integrator icon. We will use this external initial condition to input the height of
the leaning tower.

• The output of the integrator can be limited (i.e., it can be forced to stay constant if
the integration exceeds some minimum or maximum value).

Other options are available that will be discussed as we encounter the need for them.
Set one of the integrators to have an external initial condition, and leave the other at
its default value. (The default is internal with an initial condition of 0.) Then connect the
blocks, as we did before, so the model looks like Figure 1.4.
The default time for the simulation is 10 sec, which is ample time for the object to hit
the ground. Before we start the simulation, we need to specify a value for g (we used the
value −g in the dialog for the Constant, and it must be created). To do this, in MATLAB
type the command

g = 32.2;

Now start the simulation by clicking the right pointing “play” arrow (highlighted with
a circle in Figure 1.4). The simulation will run. Double click on the Scope icon and then
click the binoculars (at the top of the Scope plot window) to scale the plot properly. The
result should look like Figure 1.5.
10 Chapter 1. Introduction to Simulink
Downloaded 09/09/15 to 130.237.29.138. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Figure 1.5. Scope block graph for the Leaning Tower simulation.

Notice that the simulation stopped at a time just past 3 sec. We can see how accurately
Simulink determined that time by zooming in on the plot. If you put the mouse pointer over
the zero crossing point and click, the plot scale will change by about a factor of three. If
you do this some number of times, you will see that the crossing time is about 3.0523. The
plot will not resolve any finer than that so we cannot see the zero crossing time any better
than this.
The default for Simulink is to use the variable step differential equation solver ode45.
This variable step solver forces the integration to take as long a step as it can consistent
with an accuracy of one part in 1000 (the default relative tolerance). Simulink also sends
(by default) the time points at which the integration occurred back to MATLAB. The time
values are in a vector in MATLAB called tout. To see what the zero crossing time was,
get the last entry in tout by typing

tout(end)

To get the full precision of the calculation, type

format long

The answer should be 3.05233847833684. Remember that the stop time computed
above with MATLAB (using the solution of the equation) was 3.05233847833680, a dif-
ference of 4 in the last decimal place (i.e., a difference of 4 × 10−14 , which is a little more
than the computation tolerance variable in MATLAB called eps). How can the Simulink
numerical integration compute this so accurately?
1.2. Example 1: Galileo Drops Two Objects from the Leaning Tower of Pisa 11
Downloaded 09/09/15 to 130.237.29.138. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

This remarkable accuracy in the numeric calculation of the stopping time is because
of a unique feature of Simulink. The variable step integration algorithms that are used to
solve the differential equations in a Simulink model will compute the solution at time steps
that are as big as possible consistent with the relative tolerance specified for the algorithm.
If, in the process of computing the solution, a discontinuity occurs between any two times,
the solver forces an interpolation to determine the time at which the discontinuity occurred.
Only certain Simulink blocks cause the solver to interpolate. These are as follows:

• Abs—the absolute value block.


• Backlash—a nonlinear block that simulates a mechanical system’s backlash.
• Dead zone—a nonlinear system in which outputs do not change until the absolute
value of the input exceeds a fixed value (the variable called deadzone).
• Hit crossing—a block that looks at any signal in the Simulink diagram to see if it
matches a particular value (the hit).
• Integrator—one of the options in the integrator is to reset the integration. This re-
set value triggers the zero crossing algorithm. The integrator also triggers the zero
crossing algorithm if the integration is limited.
• MinMax—this block computes the minimum or maximum of a signal. When an
input to this block exceeds the maximum or is below the minimum, the interpolation
algorithm calculates the new maximum or minimum accurately.
• Relational operator—this operation, in this problem, detects the crossing of the ground
(zero crossing in this case) of the object.
• Saturation—a signal entering this block is limited to be between an upper and lower
bound (the saturation values). The solver interpolates the time at which the signal
crosses the saturation values.
• Sign—this block is +1 or −1, depending on whether the signal is positive or negative.
The solver interpolates the time at which the signal changes sign.
• Step—this is an input function that jumps from one value (usually 0) to another value
(usually 1) at a specified time.
• Subsystem—a subsystem is a block that contains other blocks. Their use makes
diagrams easier to read. They also allow simulations to have blocks that go on and
off. Blocks inside a subsystem do not appear at the level of the system, but you can
view them by double clicking the subsystem block. Subsystems come on (are enabled)
using a signal in the Simulink model that connects to an icon on the subsystem. If you
place an Enable block in a subsystem, the icon automatically appears at the top level
of the subsystem. Whenever the system enable or disable occurs, the solver forces a
time step.
• Switch—there is a manual switch that the user can “throw” at any time. The solver
computes the time the switch state changes.
12 Chapter 1. Introduction to Simulink
Downloaded 09/09/15 to 130.237.29.138. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Now that we have simulated the basic motion of Galileo’s experiment, let us add the
effects of air resistance to the model and see if, in fact, the objects hit the ground at the same
time.
Air drag creates a force that is proportional to the square of the speed of the object. To
first order, an object with cross sectional area A moving at a velocity v in air with density
ρ will experience a drag force given by
1 2
fDrag = ρv A.
2
(In the model so far we have assumed that the force from gravity is downward and is
therefore negative, but the air drag force is up so it is positive.) In the fps unit system we
have been using, the value of ρ is 0.0765 lbf/ft3 . Let us assume that the objects are spherical
and that their diameters are 0.1 and 0.05 ft each. (If they are made of the same material, the
large object will then be 8 times heavier than the small object.)
The acceleration of the objects is now due to the force from the air drag combined
with the force from gravity, so the differential equation we need to model is now
 2
d 2x 1 dx
= ρA − g.
dt 2 2 dt
To get the air drag force for each object we need to know their cross-sectional areas. Since
the cross-sectional area is πr 2 , the acceleration from the air drag for the large object is
1
2
ρπ r 2 = ρ2 (0.1)2 π = 0.005πρ and the acceleration for the small object is 12 ρπ (0.05)2 =
.00125πρ (they differ by a factor of 4).
To create the new model, we need to add the air drag terms. Thus, we need a way to
add the force from the air resistance to the force from gravity. This uses a Sum block from
the Math library. This block is a small circle (or a rectangle—my personal preference is
the circle since it makes it easy for the eye to distinguish summations from the other icons
that are mostly rectangular) with two inputs, (each of which has a small plus sign on it). So
click and drag this block into the leaning tower model. To get the square of the velocity, we
need to take the output of the first integration (the integration that creates the velocity from
the acceleration) and multiply it by itself. The block that does this is the Product block in
the Math library. Drag a copy of this block into the model also.
We will start by creating the model for the heavy object alone. Connect the output of
the integrator to the Product block as we did before (using either of the two inputs, it does
not matter which one), and then grab the second input to the Product block and drag it until
it touches the line that you just connected (the line from the integrator). This will cause
the two inputs to the Product block to be the same thing (the velocity), so the output is the
square of the velocity. Notice how easy it is to create a nonlinear differential equation in
Simulink. The next step is to multiply the velocity squared by 0.005πρ or 0.003825. Use
the Gain block from the Math library to do this. Click and drag a copy of this block into
the model then double click on this Gain block and change the value in the dialog to be
0.003825.
Figure 1.6 shows the resulting Simulink model, which is in the NCS library. Open it
with the MATLAB command:
Leaningtower2
1.2. Example 1: Galileo Drops Two Objects from the Leaning Tower of Pisa 13
Downloaded 09/09/15 to 130.237.29.138. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Figure 1.6. Leaning Tower Simulink model with air drag added.

Figure 1.7. Scope dialog showing how to change the number of axes in the Scope plot.

Note that we changed the Scope block to view both the position and the velocity of
the objects. This was done by double clicking the Scope icon and then selecting the “Scope
Parameters” dialog by double clicking the second menu item at the top of the Scope window.
(This is the icon to the right of the printer icon; it is the icon for a tabbed dialog.) The dialog
that opens looks like Figure 1.7.
Note that the number of axes in the Scope is the result of changing the value in the
“Number of Axes” box. We have made it two, which causes the Scope block to have two
inputs. We then connected the first input to the Velocity and the second to the Position lines
in the model.
14 Chapter 1. Introduction to Simulink
Downloaded 09/09/15 to 130.237.29.138. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Velocity
0

-20

-40

-60

-80
0 0.5 1 1.5 2 2.5 3 3.5

Position
150

100

50

-50
0 0.5 1 1.5 2 2.5 3 3.5
Time

Figure 1.8. Leaning Tower simulation results when air drag is included.

If you run this model, the results in the Scope block will resemble the graphs in
Figure 1.8.
Notice that the air drag causes the object to hit the ground later than we determined
when there was no drag (3.35085405691268 seconds instead of 3.05233847833684, about
0.3 seconds later).
Now let us compare the light and heavy object. We could do this by going back to the
model and changing the cross-sectional area to that of the smaller object. However, there
is a feature of Simulink that makes this type of calculation extremely easy. The feature is
the automatic “vectorization” of the model.
To exploit this feature, open the Gain block in the model (by double clicking) and
enter both the values for the large and the small object. Do this using MATLAB’s vector
notation. Thus the Gain block dialog will have the values [0.003825 0.000945]. (Include
the square brackets, which make the value in the dialog equal to the MATLAB vector, as
shown in Figure 1.9.)
After running this model with the 2-vector for the drag coefficients, the Scope shows
plots for the position and velocity of both of the objects (see Figure 1.10).
The heavier object hits the ground well after the light object. The velocity curve in the
top graph shows why. The speed of the heavier object comes to a maximum value of about
1.2. Example 1: Galileo Drops Two Objects from the Leaning Tower of Pisa 15
Downloaded 09/09/15 to 130.237.29.138. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Figure 1.9. Adding the second object to the Leaning Tower simulation by vector-
izing the air drag.

70 ft/sec, whereas the lighter object ends up at about 90 ft/sec. This difference is from the
increased air drag force on the object because the heavier object has a larger cross-sectional
area.
This difference is too large for Galileo not to have noticed, so it does lead us to suspect
that he never really did the purported experiment. (It is not clear from Galileo’s writings
that he understood the effect of drag, but if he did, he could have avoided this by making
the objects the same size.) In fact, it is very probable that Galileo relied on the thought
experiment he talks about in his 1638 book on the Copernican theory, Two New Sciences
[4]. In this thought experiment he argued that in a vacuum, by tying the two objects together
with a short rope, if the heavier object were to hit the ground first, at some point the rope
would become taut and the light object would begin dragging the heavier. That implies
that the combined object would hit the ground a little later than would have been the case
had no rope been connecting them. This meant that the combined object (which is heavier
than either one) would hit the ground a little later than the single heavy object. However,
since the combined weight of the two objects is greater than the single heavy object, this
violates the premise that the heavier object must hit the ground first. This deduction was
the reason Galileo believed that the Aristotelian statement that the heavy object falls faster
was wrong, and that prompted him to perform many experiments with inclined planes to
try to understand the dynamics of falling bodies [14].
Since this is the first Simulink model with any substance that we have built, let us use
it to illustrate some other features of Simulink.
First, let us clean up the model and annotate it. It is a good idea to do this as you
create the model so that when you return to the model later (or give the model to someone
else to use), it is clear what is simulated. The first thing to do is to assign a name to the
16 Chapter 1. Introduction to Simulink
Downloaded 09/09/15 to 130.237.29.138. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Velocity
0

-50

-100
0 0.5 1 1.5 2 2.5 3 3.5

Position
150

100

50

-50
0 0.5 1 1.5 2 2.5 3 3.5
Time

Figure 1.10. Simulating results. The Leaning Tower Simulink model with a heavy
and light object.

variables in the diagram, and the second is to name all of the blocks so their functions are
clear. It is also helpful to add color to the diagram to indicate the generic function of the
blocks.
To add a variable name onto a line in the Simulink model, simply double click on the
line. This causes an insertion point to appear on the line where you can type any text. The
annotation is arbitrary.
To annotate the model you created, enter the names in the model, or if you have not
created a model, open the model Leaningtower3 by typing Leaningtower3 at the MATLAB
command line. This will open the model with the annotation shown in Figure 1.11.
Simulink automatically changed from a scalar to a vector in the model when we made
the gain a MATLAB vector. After making the change, to see that the variables in the model
are vectors corresponding to the two different drag accelerations you must right click the
mouse anywhere in the model window and select Format from the menu; this will open the
submenu shown as part of Figure 1.11.
In this menu, we selected “Wide Nonscalar Lines” and “Signal Dimensions” (note
that they are checked). After you do this, all of the vector signals in the diagram have a
wider line, and the signal dimensions (vectors of size 2 here) are on the signal lines in the
model (as shown in Figure 1.11). To change the color of a block, highlight the block and
1.3. Example 2: Modeling a Pendulum and the Escapement of a Clock 17
Downloaded 09/09/15 to 130.237.29.138. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Figure 1.11. Right clicking anywhere in the diagram opens a pull-down menu
that allows changes to the colors of the blocks, bold vector line styles, and other model
annotations.

right click. Select “Background Color” from the resulting pop-up menu and then move the
mouse pointer to the right to select the desired color.
There are other features that Simulink supports which you can discover on your own
by playing with the model. As we work our way through the exercises and examples in this
book, you will learn a lot more.
In the next section, we continue creating some simple models by simulating a pendu-
lum clock. For the interested reader, [30] has a very nice discussion of how Galileo came
to realize that objects with different masses had the same motions. The Leaning Tower
experiment that showed that the masses would actually move the same had to wait for the
invention of the vacuum pump at the end of the 17th century.

1.3 Example 2: Modeling a Pendulum and the


Escapement of a Clock
The next step in our introduction to Simulink is to investigate a pendulum clock and the
mechanism that allows clocks to work: the escapement. This example introduces control
systems and how they are simulated. It also continues to discuss both linear and nonlinear
differential equations.
18 Chapter 1. Introduction to Simulink
Downloaded 09/09/15 to 130.237.29.138. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

The escapement mechanism is one of the earliest examples of a feedback control


system. An escapement provides the sustaining force for the motion of the clock while
ensuring that the pendulum and the clock movement stay in synchronization. Many famous
mathematicians and physicists analyzed clocks and early forms of escapements during the
17th and 18th centuries. We start by describing the escapement mechanism for a mechanical
pendulum clock; we then show how to build a Simulink model of the clock.

1.3.1 History of Pendulum Clocks


Humans have been building timekeepers that use the sun or water since at least 1400 BC. The
Egyptian clepsydra (from the Greek kleptei, to steal, and hydor, water) was a water-filled
bucket with a hole. The water level was a measure of the elapsed time. Sundials provided
daylight time keeping. The first mechanical clocks appeared in the 13th century, with the
earliest known device dating to about 1290. Who invented the first clock is lost to history,
but the main development that made these devices possible is the escapement, a gear with
steep sloping teeth. A gear tooth “escapes” from the escapement, causing the gear to rotate
until the next tooth engages the opposite side of the escapement. The rotation of the gear
registers a count by the clock.
At the same time the tooth escapes, the driver imparts energy (through the escaping
tooth) into the pendulum, which overcomes the friction losses at the pivot. The escapement
thus serves two purposes: it provides the energy to keep the clock in motion, and it provides
the means for counting the number of oscillations.
Christiaan Huygens invented an escapement similar to that shown in Figure 1.12 in
1656. This type of mechanism was responsible for the emergence of accurate mechanical
clocks in the eighteenth century. The mechanism relies on the escapement (the parts labeled
1 and 2 in Figure 1.12).2 With this mechanism, he was able to build a clock that was accurate
to within 1 sec per day. Previous clock mechanisms did not have the regulation capability
of the Huygens escapement, so they would slow down as the springs unwound or weights
that drove the clock dropped down. Earlier clocks required daily resetting to ensure that
they were accurate to only the nearest hour.
The pendulum mechanism provides the timing for the clock and the escapement
provides the forces and connections that

• provide energy to the pendulum so the clock does not stop because of friction;

• regulate the speed of the gear motions to the natural period of the pendulum so that
the timing of the clock is accurate, depending only on the pendulum motion;

• decouple the pendulum and the drive;

• provide the feedback to ensure that the force from the driver (springs or weights) and
wear in the various mechanical parts do not adversely affect the time displayed by
the clock.
2 This copyright figure is from a document titled “How a Clock Works” available from Erwin Sattler Clocks of

America. You can download the document from the web page http://www.sattlerclocks.com/ck.php. I would like
to thank Marcus Orvando, president of Sattler Clocks of America, for permission to use this diagram.
1.3. Example 2: Modeling a Pendulum and the Escapement of a Clock 19
Downloaded 09/09/15 to 130.237.29.138. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Figure 1.12. Components of a pendulum clock.

Before we go into the details of the design of the escapement, let us look at how it
works. The escapement is on a shaft attached to the clock case through a bushing called a
back cock. The pendulum mount does not connect to this shaft. The pendulum suspension
allows the pendulum to swing with minimal friction unencumbered by the escapement. As
the pendulum swings, it alternately engages the left and right side of the escapement anchor
(1). In the process a force from the escapement wheel (2) goes to the pendulum through the
crutch (4) and the crutch pin (5). The crutch assembly also forces the escapement to rotate
in synchronism with the pendulum. The pendulum itself (3) moves back and forth with a
period that is very closely determined by its length. (Once again we return to Galileo, who
demonstrated this in 1582.) The pendulum includes a nut at its bottom (not shown), whose
adjustment changes the effective length and thereby adjusts the period of the pendulum.
The escapement wheel (2) has a link to all of the gears in the gear train (they are not all
shown in Figure 1.12) that turns the hands (8) of the clock.
For the remainder of this description, we focus on the escapement anchor (1) and its
two sides. On the two sides of the anchor are triangular teeth; as the anchor rotates, one
of the two sides of each tooth alternately enters and exits the escapement gear, hence the
names entrance and exit pallets. If you look carefully at the anchor in Figure 1.12, you
20 Chapter 1. Introduction to Simulink
Downloaded 09/09/15 to 130.237.29.138. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

will see them: they are triangular pins that pass through each end of the anchor. As the
pendulum moves to the left, it forces the anchor to rotate and ultimately disengage the right
exit pallet face from the escapement wheel (2). When it does, the exit pallet on the opposite
side of the anchor engages the next tooth of the escapement wheel (9), and the escapement
gear moves one tooth. If the pendulum is set to swing at a period of 1 sec (as is the case for
the mechanism in Figure 1.12), the result of the motion of the escapement gear is to move
the second hand on the clock by one second (which implies that there are 60 teeth on the
escapement gear).
When the right face of the anchor engages the gear, the anchor and the escapement
wheel interact. The escapement wheel, which is torqued by the drive weight (7), applies a
force back through the anchor (1) and then, through the crutch and crutch pin (4 and 5), to the
pendulum. The alternate release and reengagement of the anchor and escape wheel provides
the energy to the pendulum that compensates for the energy lost to friction. As a by-product
of this interplay of the pendulum and the escapement wheel, we hear the distinctive and
comforting “tick-tock” sound that a clock makes.

1.3.2 A Simulation Model for the Clock


This Simulink model of the clock is in the NCS library, and you can open it using the
command Clocksim. The clock model has two parts: the model of the pendulum, and the
model of the escapement. The pendulum model comes from the application of Newton’s
laws by balancing the force due to the acceleration with the forces created by gravity. Let
us assume the following:

• The pendulum angle is θ .


• The mass of the pendulum is m.
• The length of the pendulum is l.
• The inertia of the pendulum is J . (If we assume that the mass of the pendulum is
concentrated at the end of the shaft, the inertia is given by J = ml 2 .)
• The damping force coefficient is c (Newtons/radians/sec).

Then the equation of motion of the pendulum is

d 2 θ (t) dθ (t)
J = −c − mgl sin(θ (t)).
dt 2 dt
Substituting ml 2 for J gives

d 2 θ (t) c dθ (t) g
=− 2 − sin(θ (t)).
dt 2 ml dt l

These dynamics are in the pendulum clock Simulink model shown in Figure 1.13.
This model uses Simulink primitive blocks for integrators, summing junctions, gains, and
1.3. Example 2: Modeling a Pendulum and the Escapement of a Clock 21
Downloaded 09/09/15 to 130.237.29.138. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Pend. Angle

Damping Accel.
dampcoef

Display
c/(m*len^2)
Variables

Thet2dot 1 Thetadot
Pendulum AngleForce 0.1148 1
Force Escapement Accel. s
xo s
Escapement Force from escapment
Model Initial
over the pendulum mass Pend. 0.2
Angle
Units of
2
dampcoef = 0.01 acceleration m/s
g = 9.8
plength = 0.2485
1/plength g*sin(u)
Gravity Accel. Pend. Angle

Gravity Force
1/length
g*sin(Theta)

Figure 1.13. Simulink model of the clock.

the sine function (from the Continuous and the Math Operations libraries). We also used a
new concept, called a subsystem, to create a block called “Escapement Model.” Inside this
block are Simulink primitives that model the escapement. Open the subsystem by double
clicking, or view it using the model browser.
Let us follow the signal flow in the model. We start at the output of the summing junc-
tion, where the angular acceleration of the pendulum, Theta2dot, is the result of subtracting
the three terms:

• the damping acceleration mlc 2 θ̇ from the equation above (dampcoef*Thetadot),

• the gravity acceleration from the equation above (g/plength*sin(Theta)),


• the acceleration created by the escapement that we develop next.

The Simulink model creates the variables representing the angular position and ve-
locity, Theta and Thetadot, by integrating the angular acceleration Theta2dot. A pendulum
clock only sustains its oscillation if the pendulum starts at an angle that causes the escape-
ment to operate. Consequently, an initial condition is used in the last integrator (we use 0.2
radians, about 11.5 degrees) to start the clock.
A feature of Simulink is the ability to create a subsystem to simplify the model.
Typically, a subsystem is a Simulink model that groups the equations for a particular common
function into a single block. The details of the block are in the subsystem and are not visible
until the subsystem block is opened (by double clicking or browsing), but its functionality
is captured so that the user can see the interactions. The clock’s single subsystem is the
model for the escapement. This “Escapement Model” block has the equations shown in
Figure 1.14. These nonlinear escapement mechanism equations consist of the logic needed
to model the force created by the escapement.
22 Chapter 1. Introduction to Simulink
Downloaded 09/09/15 to 130.237.29.138. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Clock Escapement M odel

Restore
Sign
1 |u|
<=
Pendulum
Abs
Angle Relational
Penhigh 0.15 Operator1
1
Force
>= Product1

Relational
Penlow 0.1 Operator2

du/dt
<
Derivative Relational
Operator3
0 penlow1

Creates a force that is applied when the pendulum is at the end of its swing

Figure 1.14. Blocks in the subsystem “Escapement Model.”

The escapement works in the same way as you would push a swing. A small accurately
timed push occurs when the exit pallet leaves the escapement. The push is always in
the direction of the pendulum’s motion and it occurs just after the pendulum reaches its
maximum or minimum swing (depending on the sign of the angle).
The attributes of the escapement model are as follows:

• Since the pendulum motion is symmetric, the calculations use positive angles (with
the absolute value function block). The force applied has the correct sign because
we multiply it by +1 or −1, depending on the sign of the angle. (The block called
“Restore Sign” does this.)

• The pendulum angle at which the escapement engages (applies an acceleration) is


denoted by Penlow. (As can be seen, it is given a value of 0.1 radians.)

• The angle of the pendulum at which the escapement disengages (jumps from one gear
tooth to the next) is denoted by Penhigh (with a value of 0.15 radians).

• The escapement applies the force only when the pendulum is accelerating (i.e., when
the pendulum is moving toward the center of its swing). We check to see if the
derivative of the pendulum angle is positive or not, and multiply the force by 1 when
it is and by 0 when it is not in the “Relational Operator 3” block.
1.3. Example 2: Modeling a Pendulum and the Escapement of a Clock 23
Downloaded 09/09/15 to 130.237.29.138. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

The plot at right shows the force


applied by the escapement model (the
Y axis) vs. the pendulum angle (X
axis). Notice that the angle at which
the force engages is 0.1 and –0.1 radi-
ans, and the angle at which the force
stops is 0.15 and –0.15 radians as re-
quired. We used the Math Opera-
tions and Logic libraries to develop
this model, so let us go through the
logic systematically.
The absolute value of the pendu-
lum angle is the first operation. This
block is the first one in the Math Oper-
ations library. At the conclusion of the
logic, the direction of the force comes from the sign of the pendulum angle. In the model
this is done by multiplying the force created (which will always be positive) by the sign of
the pendulum angle. When the absolute value of the pendulum angle is less than or equal to
0.15, the “Relational Operator1” block is one; otherwise it is zero. When the angle is greater
than or equal to 0.1 the “Relational Operator2” block is one; otherwise it is zero. The last
part of the logic insures that the only time the force is applied is when the pendulum angle is
getting smaller (in the absolute sense). This is accomplished by checking that the derivative
of the pendulum angle is negative. (The derivative block is in the Continuous library). The
product of all of these terms causes the output to be one if and only if the pendulum angle
is between 0.1 and 0.15 and the pendulum angle is decreasing, or the pendulum angle is
between −0.1 and −0.15 and the pendulum angle is increasing.
The simulation is set up to run for 1000 sec, and the output in the Scope block shows
the pendulum angle and the escapement acceleration. After you run the model, you can
reveal the details of the plot by using the mouse to encircle an area on the plot to zoom
in on. If you do this (it was done here between 412 and 421 sec), the plot resembles
Figure 1.15.
The early part of the simulation shows that the pendulum angle grows from its initial
value (of 0.2 radians) to 0.2415 radians. This stable value for the maximum pendulum angle
is a consequence of the escapement.
At this point, numerical experiments with the clock can investigate different ques-
tions. For example, the fact that the escapement force is determined by some device that
converts potential energy into kinetic energy (weights, a spring, a pneumatic device that uses
variations in air pressure, etc.) means that over its operation the force that the escapement
applies to the pendulum will decrease. To understand the effect of this decreasing force
on the time keeping of the clock, simulate the escapement with different values of Gain in
the Gain block labeled “Force from escapement over the pendulum mass.” Evaluate the
change, if any, in the period of swing of the pendulum, and the amplitude of the swing when
you change this value (see Example 1.2).
24 Chapter 1. Introduction to Simulink
Downloaded 09/09/15 to 130.237.29.138. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Figure 1.15. Results of the clock simulation for times around 416 sec. Upper figure
is the pendulum angle, and the lower figure is the acceleration applied to the pendulum by
the escapement.

1.4 Example 3: Complex Rotations—The Foucault


Pendulum
Léon Foucault, in 1848, noticed that a pendulum mounted in the chuck of a rotating lathe
always moved back and forth in the same plane even if the chuck rotated. This gave him the
idea that he could demonstrate that the earth rotated by setting in motion a long pendulum
and observing the path of motion over the period of a day. In a series of experiments
with gradually longer pendulums, he became convinced that his concept was valid. In
February of 1851, he unveiled a public demonstration for the Paris Exposition, where, at the
Eglise Ste.-Geneviève in Paris, he set up a pendulum that was 67 meters long. The original
pendulum, shown in Figure 1.163 , has been back at the Panthéon since 1995.
The Foucault pendulum both illustrates the mechanics of a body moving in a rotating
frame and is the simplest example of the complex motions that result from gyroscopic forces.
We will investigate these forces in detail in Chapter 3. For this introduction to Simulink,
we have looked at Galileo’s experiment, the pendulum for use in a clock, and now the
Foucault pendulum. The dynamics are not too complex, but they do require that the full
three dimensions be included. (However, one of these motions, the vertical direction, may
be ignored.) The model we create can also be used as a simple example of the Coriolis
effect that causes weather patterns to move from west to east (in the northern hemisphere).
3 The original church is now a public building called the Panthéon on the Place du Panthéon in Paris. This

photgraph is from the Wikipedia web site [51].


1.4. Example 3: Complex Rotations—The Foucault Pendulum 25
Downloaded 09/09/15 to 130.237.29.138. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Figure 1.16. Foucault pendulum at the Panthéon in Paris.

1.4.1 Forces from Rotations


A particle moving with constant speed along a
circular path is always changing its direction of
travel; it is accelerating all of the time. The forces
associated with this change in direction are the
centrifugal and centripetal forces. The figure at
right illustrates the motion and the vectors asso-
ciated with the location of the particle as it moves
over an interval t. The vectors in the diagram
are the radial location at the two times t + t;
the unit vectors for the radial motion, ur (t); and
the direction perpendicular to the radial motion,
uθ (t). To restrict the particle to motions with a
constant radius, we assume that r(t) = r ur (t), where r is the radius (a scalar constant).
Differentiating this to get the linear velocity of the particle gives
dr(t) dur (t)
v(t) = =r .
dt dt
From the figure above, the derivative of the unit vector ( dudtr (t) ) is given by calculating the
difference in this unit vector over the time t. Since t is small, the directions of the unit
vector uθ over this interval can be assumed constant. In addition, the magnitude of the
perturbation |uθ (t + t) − uθ (t)| is the small arc length θ.
Putting these together gives the derivative dudtr (t) as

dur (t) ur (t + t) − ur (t) ur (t) + uθ θ − ur (t) θ


= lim = lim = lim uθ = uθ ω.
dt t→0 t t→0 t t→0 t
Here ω is the angular velocity of the particle’s motion. Therefore we have v(t) = uθ ωr or,
equivalently, that the magnitude of the velocity (the particle’s speed) is ωr.
26 Chapter 1. Introduction to Simulink
Downloaded 09/09/15 to 130.237.29.138. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

To get the relationship between the angular acceleration and the particle’s speed we
differentiate the vector velocity using the fact that the radius is constant and the angular
velocity and unit vector perpendicular to the radial motion are changing with time. Thus
the acceleration of the particle is
dv(t) dω duθ
a(t) = = uθ r+ ωr.
dt dt dt
Following steps similar to those we used above for differentiating ur , the derivative of uθ
is − ur ω, where the minus sign comes from the fact that the difference in uθ at the times t
and t+ t points inward (along the radial direction this is negative). Using these values, we
get the acceleration of the particle as (in this expression, α = dω
dt
)
a(t) = uθ αr − ur ω2 r.
This acceleration has two components: tangential and radial. The tangential component
is the instantaneous linear acceleration and its magnitude is αr. The radial component is
the centrifugal acceleration and its magnitude is ω2 r = vr . These two results should be
2

familiar from introductory physics, but we show them here to remind you that motions under
rotations need to account for both the vector magnitude and its directions.

1.4.2 Foucault Pendulum Dynamics


When there are no forces on an object, its trajectory in inertial space is a straight line. If we
view this motion in a rotating coordinate system, the motion will appear curved. Because the
curve is not the true motion of the object but is a consequence of the observer’s motion, to get
the equations of motion for the observer we use a fictitious force, called the Coriolis force.
We have indirectly seen this kind of fictitious force in the centrifugal acceleration
above. Following the derivation in Section 1.4.1, if a three-dimensional vector b is rotating,
then its derivative in an inertial (stationary) frame is
 
db  db 
= + ω × b|Inertial .
dt Inertial dt Rotating
Using this to get the velocity of a rotating vector gives vInertial = vRotating + ω × r. Applying
this result again to differentiate the inertial velocity gives
d
aInertial = (vRotating + ω × r)Rotating + ω × vRotating + ω × (ω × r).
dt
The derivative of the first term on the right must account for the fact that the angular velocity
and the radius vector are both time varying. Thus, we have

aInertial = aRotating + × r + 2ω × vRotating + ω × (ω × r).
dt
This equation gives the acceleration in the rotating coordinate system as

aRotating = aInertial − 2ω × vRotating − ω × (ω × r) − × r.
dt
Since the force on the body in the rotating frame is the mass times the acceleration in the
rotating frame and the force on the body in the inertial frame is the mass times the inertial
1.4. Example 3: Complex Rotations—The Foucault Pendulum 27
Downloaded 09/09/15 to 130.237.29.138. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php


z

Figure 1.17. Axes used to model the Foucault pendulum.

acceleration, the “Coriolis force” that accounts for the perceived motion in the rotating
frame is

FCoriolis = −2mω × vRotating − mω × (ω × r) − m × r.
dt
We can now model the Foucault pendulum. Figure 1.17 shows the coordinate system
we use. The y coordinate comes out of the paper. The origin of these coordinates is the
rest coordinates of the pendulum, and the z axis goes through the point of suspension of the
pendulum. We assume that the pendulum length is L.
In the figure, the Earth is rotating at the angular velocity $, the pendulum
 is at the

latitude λ, and we denote the coordinates of the pendulum with the vector x, y, z .
Since the pendulum is rotating at the Earth’s rate, the Coriolis forces on the pendulum are
 dx dy dz
  
C = −2m(v × $) = −2m dt
, dt
, dt
× −$ cos λ, 0, $ sin λ .

In the vertical direction, the tension in the wire holding the pendulum is approximately
constant (equal to the weight of the pendulum bob mg), so the velocity along the vertical is
essentially zero. Therefore, the Coriolis forces (from the cross product) are
 dy dy

2m dt
$ sin λ, − dx
dt
$ sin λ, dt
$ cos λ .

Now, when the pendulum moves, there is a restoring force from gravity. This force is
proportional to mg sin(θ ), where θ is the pendulum angle, as we saw for the pendulum
above. For the pendulum, the angle is Lx along the x-axis and Ly along the y-axis. We assume
that the pendulum motion is small so the acceleration is mgθ . Thus the accelerations on the
28 Chapter 1. Introduction to Simulink
Downloaded 09/09/15 to 130.237.29.138. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Foucault pendulum are


d 2x dy
= 2$ sin(λ) − (2πfP )2 x,
dt 2 dt
d 2y dx
= −2$ sin(λ) − (2πfP )2 y.
dt 2 dt
We ignore the accelerations in the vertical direction since to first order they are zero.
The term (2πfP )2 = Lg is the square of the period of the pendulum, exactly as was
used in the clock example above. An interesting aspect of this problem is the magnitudes of
the coefficients in the differential equations. The rate of rotation of the earth is essentially
once every 24 hours (it is actually a little less), so
2π 2π
$∼
= = = 0.00007272205.
24 ∗ 60 ∗ 60 86, 400
The coefficient in the model depends on the latitude. Let us assume we are at 45 degrees
north latitude, so the coefficients are
2$ sin(λ) = 0.00010284.
If we assume that the pendulum length is such that the period of the pendulum swing is 1
minute, we obtain that the other coefficient in the differential equation is
 2

(2πfP )2 = = 0.01096622.
60
These coefficients differ by about four orders of magnitude, which will make these equations
difficult to solve numerically. As we will see, Simulink allows the user to accommodate
this so-called stiffness without difficulty.
We can now build a Simulink model for the Foucault pendulum using these differential
equations. First, though, let us compute how long the simulation should be set up to run.
The period of the total motion of the Foucault pendulum depends upon our latitude. This

period is $ sin(λ) = Tsin(λ)
Earth
, where TEarth is the time for one rotation of the earth. (We assume
the earth rotates in 24 hours so, for a latitude of 45 degrees, the period is 1.2219e+005 sec.)
We will make this time the simulation stop time.
Figure 1.18 shows the model for the Foucault pendulum. Once again, to gain famil-
iarity with Simulink and to ensure you know how to build a model like this, you should
create this model yourself. We call this model Foucault_Pendulum in the NCS library.
By now, you should be finding it reasonably easy to picture what the Simulink diagram
portrays. Remember that the picture represents the mathematics and, because the signal flow
represents the various parts of the mathematics, it is important when the model reinforces
this flow. In this picture, you should be able to clearly distinguish the x and y components of
the pendulum motion. We could emphasize this by coloring the two second order differential
equation blocksets with a different color. (The models that are in the NCS library use this
annotation.)
When you run this model, the Scope block creates the oscillation over one period, as
shown in Figure 1.19. As can be seen from the plots, the motions in the east-west and north-
south directions are out of phase by 90 degrees and essentially create a circular motion. The
initial condition in the model sets the pendulum at 1 ft to the north and at exactly zero along
1.4. Example 3: Complex Rotations—The Foucault Pendulum 29
Downloaded 09/09/15 to 130.237.29.138. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Pendulm Freq
Squared

Earth Rate OmegaP^2


at Latitude (Lat) Pend. Accel.

y Axis (E-W)
1 dy/dt 1 Motion
2*OmegaE*sin(Lat)
Coriolis s s
Accel (y) x Axis (N-S)
Integrate y Integrate y
Accel. Vel. Pendulum Freq Motion Scope
Squared

2*OmegaE*sin(Lat) OmegaP^2
dy/dt Coriolis Pend.
Accel. (x) Accel.

Earth Rate
at Latitude
1 Integrate x
s Accel.

dx/dt dx/dt 1
s
Integrate x
Vel.

Figure 1.18. The Simulink model of the Foucault pendulum.

y Axis (E-W)
Motion
1
Motion of Pendulum in y (DFeet)

0.5

-0.5

-1
0 2 4 6 8 10 12 14
Time 4
x 10

x Axis (N-S)
Motion
1
Motion of Pendulum in x (Feet)

0.5

-0.5

-1
0 2 4 6 8 10 12 14
Time 4
x 10

Figure 1.19. Simulation results from the Foucault pendulum Simulink model using
the default solver.
30 Chapter 1. Introduction to Simulink
Downloaded 09/09/15 to 130.237.29.138. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

y Axis (E-W)
Motion
1

0.5

-0.5

-1
0 2 4 6 8 10 12 14
4
x 10
x Axis (N-S)
Motion
1

0.5

-0.5

-1
0 2 4 6 8 10 12 14
Time 4
x 10

Figure 1.20. Simulation results for the Foucault pendulum using a tighter toler-
ance for the solver.

the east-west line. If for some reason the pendulum starts with a motion that is out of the
plane, the pendulum will precess during its motion sweeping out a more elliptic path.
The parameters in the model come from code used by the pre-load function (in the
“Model Properties” dialog under “Edit” in the pull-down menu at the top of the Simulink
model). You can experiment with different latitudes for the pendulum by changing the value
of Lat (by simply typing the new value of Lat at the MATLAB command line).
Let us use this result to explore the numerical integration tools in Simulink. Chap-
ter 7 of Cleve Moler’s Numerical Computing with MATLAB contains a discussion of the
differential equation solvers in MATLAB. The solvers in Simulink are identical, except that
they are linked libraries that Simulink automatically uses when the model runs (because
you clicked the “run” button). The results in Figure 1.19 use the default solver in Simulink
(the default is ode45 with a relative tolerance of 1e-3). If you look carefully at this figure,
you will notice that the amplitude of the pendulum motion is decreasing over time. There
is, however, no physical reason for this. We have not included any pendulum damping in
the model, and the terms that couple the x and y motions should not introduce damping.
To see if this effect is a consequence of the numerical solver, let us go into the model and
change the solver to make it more accurate. Open the “Configuration Parameters” dialog
under the Simulation pull-down menu (or use Ctrl + E), and in the dialog change the relative
tolerance to 1e-5. If you run the simulation, the result appears as shown in Figure 1.20.
1.5. Further Reading 31
Downloaded 09/09/15 to 130.237.29.138. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Notice that this result is what we expect; there is no discernable damping in the
motion and the period is exactly what we predicted. The need for the tighter tolerance in
the calculation is because of the order of magnitude difference of five in the coefficients in
the model, as we noted above. In general, experimentation is required with the differential
equation solver values in order to insure that the solution is correct. The best way to do this
is to try different solvers and different tolerances to see if they create discernable differences
in the solutions. We return to the solvers as we look at other simulations. In particular, we
will look at some very stiff systems and the use of stiff solvers in Chapter 3.
In Chapter 3, we will also explore the more complex motions of objects undergoing
gyroscopic forces when the motion takes place in three dimensions. First, however, we will
look at how Simulink creates simulation models for linear systems, how Simulink handles
vectors and matrices, and, last, when to use Simulink as part of the process of designing
control systems.

1.5 Further Reading


Galileo showed that a falling body’s acceleration is independent of its mass by making
detailed measurements with an inclined plane, as was described in his 1632 Dialogue Con-
cerning the Two Chief World Systems: Ptolemaic and Copernican [14]. Recent and old
versions of his devices are in the Institute and Museum of the History of Science in Flo-
rence, Italy (http://www.imss.firenze.it /), and you can view a digital version of the original
manuscript of Galileo’s “Notes on Motion” (Folios 33 to 196) from this site. The location
for the manuscript is http://www.imss.fi.it/ms72/index.htm. An excellent translation of the
Galileo dialogue describing the inclined plane measurements that he made is in The World
of Mathematics, Volume 2, edited by James R. Newman [30].
There is a wonderful essay by John H. Lienhard from the University of Houston (at
http://www.uh.edu/engines/epi1307.htm) that describes the clock as the first device ever
engineered. The essay ties the clock back to Galileo and traces its history from the early
writings of Francis Bacon to Huygens and Hooke.
The document that you can download from Sattler Clocks (referred to in footnote 2)
has much more detail on the mechanisms involved in the escapement (and in particular the
escapement in Figure 1.12 that was invented by George Graham in 1720) and the other
very interesting features of a pendulum clock. They also have extensive pictures of some
elegantly designed and beautiful clocks.
I used the clock example to develop an analysis of the clock escapement in the IEEE
Control Systems Society Magazine [38]. Shortly after the publication of this article, a set
of articles also appeared in the same magazine on several interesting early control systems,
including the clock [3], [19].
In a recent Science article [37] the authors demonstrated that moths maintain control
during their flight because their antennae vibrate. This vibration, like the motion of the
Foucault pendulum, precesses as the moth rotates, giving the moth a signal that tells it
what changes it needs to make to maintain its orientation. The authors demonstrated this
by cutting the antennae from moths and observing that their flight was unstable. They
subsequently reattached the antennae, and the moths were again able to fly stably.
You should carefully review The MathWorks’s User’s Manual for Simulink [42].
Simulink models can get very large and take a long time to run. The data generated by
32 Chapter 1. Introduction to Simulink
Downloaded 09/09/15 to 130.237.29.138. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

the model can also overwhelm the computer’s memory. Managing the use of memory can
improve the performance of your models. Reference [41] has a good discussion of the
methods available for managing the memory in a Simulink model.

Exercises
1.1 Use the Leaning Tower of Pisa model as the starting point to add a horizontal com-
ponent to the velocity at the instant the objects start. Include the effect of air drag.
Also, add an input to the model to simulate different wind speeds. Experiment with
this model to see how these do or do not affect the experiment.

1.2 In the clock simulation, increase the friction force to see how large it must be before
the escapement ceases working. Perform some numerical experiments with the model
to see if there is any effect on the accuracy because of the increased friction. When
you evaluated the change in the period and amplitude of swing of the pendulum as
you changed the Gain, you should not have seen a significant change. What change in
the model will allow you to see the effect of lower forces applied by the escapement?
Modify the model to look at this, and experiment with different escapement forces.
What is the effect? Why is the effect so small? How does the escapement ameliorate
these forces? Look at Figure 1.12 carefully. The Sattler Company has a spring
mounted on the pendulum that transmits the force from the crutch pin to the pendulum.
Does the Simulink model have this mechanism? How would you go about adding
this mechanism to the model? Is there a good reason for the Sattler clock to use this
spring?

1.3 Experiment with the different Simulink solvers (one by one) to see what effect they
have on the simulation of the Foucault pendulum. Which ones work well? Try
changing the tolerances used for each of the solvers to see if they stop working.

1.4 Create a Simulink model of a mass suspended on a spring under the influence of
gravity. Add a force that is proportional to the velocity of the mass to model the
damping. Pick some parameter values for the mass, the spring constant, the damping,
and, of course, gravity, and simulate the system. Explore what happens when you
increase the value of the damping from zero. Can you explain the behavior you are
seeing in terms of the solution of the underlying differential equation? (If you cannot,
we will see why in the next chapter.)

Potrebbero piacerti anche