Академический Документы
Профессиональный Документы
Культура Документы
+ + = () (1)
where f(t) is a forcing function applied to the mass. We need to rearrange this slightly to get it into
Simulink format. In most cases we solve for the highest derivative in each differential equation. For the
equation above we have
1
= [() ] (2)
This is a second-order differential equation. To solve this numerically we must integrate it twice. To
begin, start Matlab and type simulink at the prompt. A new window will open containing libraries of
Simulink components. Most of the interesting components are in the Continuous, Math, Source and Sink
libraries. To begin a new Simulink simulation, go to the File menu and click New.
Each integrator block has two ports: an input and an output. The input accepts an expression for a first
derivative and the output gives the results of integration. Since we need to integrate the equation twice, we
will connect two Integrators in series. A schematic view of how to perform double integration is shown at
right. To begin, we feed the input of the first Integrator
with an expression for the second derivative of the
variable. The Integrator integrates this once, and x
produces the first derivative. We send this first
derivative to the second Integrator, which provides the
variable at its output.
1
To do this, we place a Sum block (Math
library) at the input to the first Integrator to
piece together the expressions for the 1 1
1
second derivative. You can control the s s
number and type of inputs to the Sum block 1/m Int1 Int2
Note that the velocity passes through another Gain block before entering the summation. The Gain block
multiplies the velocity by the damping coefficient. In the figure, the Gain block has been flipped so that
it points from right to left. Do this by right-clicking the block and selecting Format Flip Block. Double-
click the block and change the damping coefficient to 0.1.
All that remains is to add the third input into the Sum block. The output of the second Integrator gives the
position coordinate. Multiply this by the spring constant (using another Gain block, with k = 100) and
send the result into the Sum block. Your model should look like the figure on the next page. A Scope block
(Sinks library) has been added to the model in order to be able to quickly plot the output after running the
model.
2
1 1
1
s xdot s
Signal
Generator 1/m Int1 Int2 Scope
.1
c*xdot xdot
c
k*x x
100
To run the simulation click the Start Simulation button at the top of the window. This simple
simulation will run very quickly, almost instantly. Once it is completed you can double-click the Scope
block to see the position of the mass plotted versus time.
Now change the forcing frequency in the Signal Generator to 1.6 Hz and observe the response. As you can
see, the position of the mass blows up at this frequency. Why is this?
You have probably observed that the Scope has very limited plotting capabilities. It is really meant for
performing quick diagnostics on simulations. To obtain better quality plots you can use the XY Graph
block (also in the Sinks library). Here the x-coordinate is time, which is obtained by using a Clock block (in
the Sources library). Modify your model to look like the one in the figure below. After the simulation runs,
double-click the XY Graph block to see the results. You can also use a To Workspace block to send your
output to the Matlab command line for even better plots!
Clock
1 1
1
s xdot s
Signal XY Graph
Generator 1/m Int1 Int2
.1
c*xdot xdot
c
k*x x
100
3
A 2DOF System
The figure at right shows a simple mass-spring system with two masses, two dampers m1
and two springs. As we learned last week, the differential equations of motion are
easy to obtain:
k1 c1
1 1 + 1 ( 1 2 ) + 1 (1 2 ) = 1 ()
2 2 + 1 ( 2 1 ) + 2 2 + 1 (2 1 ) + 2 2 = 2 () m2
where f1(t) and f2(t) are forcing functions on masses 1 and 2, respectively. We need to c2
rearrange this slightly to get it into Simulink format by solving for the highest-order k2
derivatives. For the equations above we have
1
1 = [ () 1 ( 1 2 ) 1 (1 2 )]
1 1
(3)
1
2 = [ () 1 ( 2 1 ) 2 2 1 (2 1 ) 2 2 ]
2 2
The figure above shows one possible implementation of the system of equations in Simulink. There are a
couple of interesting things about this model:
1. The gain blocks are all given as variables, rather than numbers. For example, the gain block for the
first spring is given as k1, rather than giving its value directly.
2. The output of the model is sent to the workspace in the blocks labeled x1 and x2, as is the time
vector, t.
4
Important Note: the To Workspace blocks will send something strange called a Time Series to the
workspace by default, which I am not sure how to make use of. To send it as a simple series of numbers
(like we usually use in Matlab), you must double-click on each To Workspace block and change the Save
Format value to Array.
Of course, this simulation will not work on its own; we need to supply the values for the masses,
stiffnesses and dampers. We do this by writing an ordinary Matlab script, and calling the simulation from
there. Once the simulation has run, we can plot the results as usual. Create the following script in the
same directory as the simulation.
% 2DOF spring/mass/damper system
sim Spring_Mass_2DOF_Sim
plot(t,x1,t,x2)
grid on
xlabel('time (sec)')
ylabel('displacement (m)')
title('Displacement of Mass 1 and Mass 2')
When you first run the simulation, youll find that the plots are somewhat jagged and irregular. This is
because the default time step chosen by Matlab is too large to make a smooth graph. In Simulink, click on
the Simulation menu and choose Model Configuration Parameters. In the Solver Options block, choose Fixed-Step,
and pick 0.001 seconds as the fixed time step. Also, choose 5 seconds as the Stop Time. When you re-run
the simulation, the graphs should be smooth.
0.02
0.01
displacement (m)
-0.01
-0.02
-0.03
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time (sec)