Capitulo 9 Practical MATLAB Modeling With Simulink Programming and Simulating
Capitulo 9 Practical MATLAB Modeling With Simulink Programming and Simulating
Spring-Mass-Damper
Systems
This chapter covers several essential aspects and approaches how to build simulation
models of spring-mass-damper systems in MATLAB and Simulink environments. The
equations of motions of one, two, three degree of freedom spring-mass-damper systems
are derived and MATLAB/Simulink models are built based on the derived mathematical
formulations. Free and forced motions of the spring-mass-damper systems are
studied, and linear and non-linear behaviours of the spring-mass-damper systems are
considered. The developed simulation models of one, two and three degree of freedom
systems can be applied for multipled degree of freedom systems.
C u u + Ku ( t )
u = - (9-1)
M
295
© Sulaymon L. Eshkabilov 2020
S. L. Eshkabilov, Practical MATLAB Modeling with Simulink, https://doi.org/10.1007/978-1-4842-5799-9_9
Chapter 9 Spring-Mass-Damper Systems
The second-order ODE, shown in Equation (9-1), can be represented by the next two
differential equations by introducing a new variable, as explained in Part 1 of the book,
to solve the second-order ODEs numerically.
ìu1 = u2
ï (9-2)
í C u2 u2 + Ku1
ïu 2 = -
î M
The given system model will be of a stiff-type ODE if the magnitude of its mass is much
Ns N
smaller than its stiffness and damping, for instance: M = 1 kg , C = 1001 , K = 1000 .
m m
Let’s write a script in a function file (SMDode.m) with three input arguments (M, C, K)
based on the first ODEs shown in Equation (9-2). We are using the ODE solver ode15s since
the given problem is a stiff ODE type. Note that we also introduce the Jacobian
matrix of the given system in Equation (9-2) as the nested function function dfdu =
Jacobian(t, u). The expression shown in Equation (9-2) is coded within the nested
function function dudt = f(t, u). Having the Jacobian matrix defined speeds up the
simulation process of the MATLAB ODE solvers.
function SMDode(Mass,Damping, Stiffness)
%{
SMDode.m. Spring-Mass-Damper system behavior analysis
with the given Mass, Damping and Stiffness values.
Note: an order of input argument data is important.
The system's damper has non-linear properties expressed
with D*|u'|*u' e.g., abs(velocity)*velocity
Solver ode15s is employed; yet, other solvers, viz.
ODE15S, ODE23S, ODE23T, ODE23TB, can be used, as well.
%}
if nargin < 1
% Some default values for parameters: Mass, Damping & Stiffness
% in case not specified by the user
Mass = 1; % [kg]
Damping=1001; % [Ns/m]
Stiffness=1000; % [N/m]
end
296
Chapter 9 Spring-Mass-Damper Systems
figure;
plot(t,u(:,1),'r-', t, u(:,2), 'b-.', 'MarkerSize', 5,...
'LineWidth', 1.5);
title(['\it Spring-Mass-Damper System: ',...
'M = ' num2str(Mass), '[kg]' '; D = ' num2str(Damping),...
'[Ns/m]', '; S = ' num2str(Stiffness), '[N/m]']);
xlabel('time t')
grid on
axis tight
axis([tspan(1) tspan(end) -0.1 0.1]); % Axis limits are set
hold on
Acceleration=-(Damping/Mass)*abs(u(:,2)).*u(:,2)-...
(Stiffness/Mass)*u(:,1);
plot(t, Acceleration,'k--', 'MarkerSize', 3, 'LineWidth', 1);
legend('Displacement', 'Velocity', 'Acceleration');
ylabel('Displacement, Velocity, Acceleration')
hold off; xlim([0, 3])
% -----------------------------------------------------------
% Nested functions: Mass, Damping and Stiffness are provided
% by the outer function.
%------------------------------------------------------------
function dudt = f(t, u)
% Derivative function. Mass, Damping and Stiffness are provided
% by the outer function or taken default (example values)
dudt = [ u(2);
-(Damping/Mass)*abs(u(2))*u(2)-(Stiffness/Mass)*u(1) ];
end
297
Chapter 9 Spring-Mass-Damper Systems
% -----------------------------------------------------------
function dfdu = Jacobian(t, u)
% Jacobian function. Mass, Damping and Stiffness are provided by
% the main function or taken default values for no inputs.
dfdu = [ 0, 1;
-(Stiffness/Mass), -(Damping/Mass)*abs(u(2))-...
(Damping/Mass)*u(2)*sign(u(2)) ];
end %
% -----------------------------------------------------------
end % SMDode.m
From the simulation results plotted in Figure 9-1, it is clear that the system is over-
damped. In studies of spring-mass-damper systems, it is important to study not only the
overall system behavior but also its natural frequency, damping level (lightly damped, under-
damped, and over-damped case scenarios), and influence of the system parameter changes.
All of these studies can be introduced additionally into a simulation model of the system.
Let’s reconsider the previous problem of the single degree of freedom SMD system to
study its free motion when the system is linear, i.e., u is not present: Mu + Cu + Ku = 0 .
This can be rewritten by dividing it by M (mass), as shown here:
C K
u + u + u = 0 (9-3)
M M
K C
= wn2 ; = 2zwn (9-4)
M M
where ωn is the natural frequency of the system and ζ is the damping ratio.
The problem formulation can be rewritten again like this:
where the unknown coefficients A and B are computed from the initial conditions
( u ( 0 ) = u0 , u ( 0 ) = u 0 ) using the next general equations:
u0 r2 - u 0
A= (9-7)
r2 - r1
u 0 - u0 r1
B= (9-8)
r2 - r1
By plugging the general solution into the given problem formulation of Equation (9-5),
we obtain the following characteristic equation:
299
Chapter 9 Spring-Mass-Damper Systems
The roots (roots r1 and r2) of this quadratic characteristic equation are as follows:
r1, 2 = (-2zwn ± ( 2zwn )
2
)
- 4wn2 / 4wn2
(9-10)
The roots (r1 and r2) depend on the parameters, namely, ωn and ζ. Let’s look at four
case scenarios [1, 2] to compute them.
Case Scenario I. Undamped. ζ = 0.The problem formulation is as follows:
The solutions of the differential equation in (9-11) are r1 = i ωn; r2 = − i ωn, and the
solutions for real system cases are available for: M > 0 and K > 0 .
The solution is as follows:
u 0
u ( t ) = u0 cos (wn t ) + sin (wn t ) (9-12)
wn
Note that this solution is obtained using some substitutions, such as the Euler
formula we’ve used in previous chapters (eiθ = cos θ + i sin θ) and the general solution
formulation shown earlier in Equation (9-6).
The following is another formulation of the solution:
æ u 2 ö
u ( t ) = ç u02 + 02 ÷ sin (wn t + j ) (9-13)
ç wn ÷
è ø
æw u ö
j = tan -1 ç n 0 ÷ (9-14)
è u 0 ø
where φ is the phase shift angle. Note that both solution formulations, shown in
Equations (9-12) and (9-13), are equivalent and can be derived from one another.
Case Scenarios II. Underdamped. 0 < c2 < 4 MK or 0 < ζ < 1. The roots of the general
solution in Equation (9-6) are as follows:
r1 = é -z + i
ëê
(1 - z ) ùûú w
2
n
(9-15)
r2 = é -z - i
êë (1 - z ) ùúû w
2
n
(9-16)
300
Chapter 9 Spring-Mass-Damper Systems
Damping is present, and the damped natural frequency of the system will be as
follows:
wd = wn (1 - z ) 2
(9-17)
æ u zw + u 0 ö
u ( t ) = e -zwnt ç uo cos (wd t ) + 0 n sin (wd t ) ÷
è wd ø (9-18)
Case Scenario III. Overdamped. c2 > 4 MK or ζ > 1. The roots of the general solution
equation shown in Equation (9-6) are as follows:
r1 = é -z -
ëê
(z 2
- 1) ù wn
ûú
(9-19)
r2 = é -z +
ëê
(z 2
- 1) ù wn
ûú
(9-20)
The coefficients of the general solution equation shown in Equation (9-6) are as
follows:
é z ù u 0
A = u0 ê ú- (9-21)
êë 2 z - 1 úû 2wn z 2 - 1
2
é z ù u 0
B = u0 ê ú+ (9-22)
êë 2 z 2 - 1 úû 2wn z 2 - 1
301
Chapter 9 Spring-Mass-Damper Systems
r1 = r2 = -wn (9-24)
The coefficients of the general solution equation shown in Equation (9-6) are as
follows:
A = u0 , B = u 0 + wn u0 (9-25)
u ( t ) = ( A + Bt ) e -wnt (9-26)
Here we have skipped some of the details of deriving solutions in four case scenarios.
A few essential details of the derived formulations shown in Equations (9-7) to (9-26) can
be found in [3].
A complete simulation model of the previous case scenarios can be programmed
with a nested function. Out=SMDsysSim(M, D, S, ICs, t) embedded within the
m-file SMDsysSIM_compare.m that simulates all four scenarios based on five input entries,
namely, M, D, S, ICs, t. The input entries are mass (M), damping (D), stiffness (S),
initial conditions (ICs), and time vector (t).
302
Chapter 9 Spring-Mass-Damper Systems
dut1=diff(ut1);
dut2=diff(ut2);
dut3=diff(ut3);
dut4=diff(ut4);
figure(1)
plot(t, ut1, 'b-', 'linewidth', 1.5), hold on
plot(t, ut2, 'r-.', 'linewidth', 1.5)
plot(t, ut3, 'k:', 'linewidth', 2)
plot(t, ut4, 'g--', 'linewidth', 1.5)
xlabel('time, [s]'); ylabel('System response, [m]'), grid on,
title('1-DOF Spring-Mass-Damper System simulation - 4 Scenarios'),
legend('No damping: \zeta=0',' Underdamped: 0<\zeta<1',...
'Overdamped: \zeta>1','Critically damped: \zeta=1'), hold off
figure(2)
plot(ut1(2:end), dut1, 'b-', 'linewidth', 1.5),
hold on
plot(ut2(2:end), dut2, 'r-.','linewidth', 1.5)
plot(ut3(2:end), dut3, 'k:', 'linewidth', 2)
plot(ut4(2:end), dut4, 'g--', 'linewidth', 1.5)
xlabel('time, [s]');
ylabel('System response, [m]')
grid on, title('Phase plot: Displacement vs. velocity')
legend('No damping: \zeta=0',' Underdamped: 0<\zeta<1',...
'Overdamped: \zeta>1','Critically damped: \zeta=1')
xlim([-.1 .1]), ylim([-.025 .025]), axis square
hold off; shg
303
Chapter 9 Spring-Mass-Damper Systems
The simulation results of this simulation model demonstrate the influence of the
damping ratio values, ζ (Figure 9-2 and Figure 9-3) on the system behaviours. For
instance, having ζ under a critical damping (under-damped case) value leads to decay
(damping) of the system response, but the decay rate will be exponential depending on
the value of ζ. If there is no damping present, then the system response oscillates at its
natural frequency value of ωn. Conversely, in over-damped and critically damped cases,
the system response does not oscillate.
304
Chapter 9 Spring-Mass-Damper Systems
0.02
-0.02
-0.04
-0.06
-0.08
-0.1
0 1 2 3 4 5
time, [s]
305
Chapter 9 Spring-Mass-Damper Systems
0.005
du(t), [m/s]
-0.005
-0.01
-0.015
-0.02
-0.025
-0.1 -0.05 0 0.05 0.1
u(t), [m]
Moreover, we can study the influence of initial conditions on the system response
u(t) to see how much time is required for the system to come to a complete stop. Now, by
modifying the previous script, SMDsysSIM_compare.m, we can write another simulation
model, SMDsysSIM_compare_ICs.m, that simulates three case scenarios: under-damped,
critically damped, and over-damped with three different initial conditions.
306
Chapter 9 Spring-Mass-Damper Systems
307
Chapter 9 Spring-Mass-Damper Systems
308
Chapter 9 Spring-Mass-Damper Systems
Figure 9-4. Study the influence of initial conditions of the system on its responses
309
Chapter 9 Spring-Mass-Damper Systems
md 2 y Cdy
+ + Ky = F ( t ) (9-27)
dt 2 dt
where external force F(t) is a periodic wave function that can be expressed via the
Fourier series approximation as follows:
¥
400 400 80
F ( t ) = å (1 - cos np ) sin ( np t ) = sin (p t ) - sin ( 3p t ) + sin ( 5p t ) - (9-28)
n =1 p 3p p
Now, the final formulation of the system model in Equation (9-27) will be as follows:
First simulation model. Using Equation (9-29), we create a simulation model with
MATLAB scripts. The periodic wave function formulation in Equation (9-28) can be
expressed as a function called F=func_pulse(t, n).
310
Chapter 9 Spring-Mass-Damper Systems
function F=func_pulse(t, n)
%HELP. t is time vector. n is number of terms in pulse approximation.
F(1,:)=(200/pi)*(1-cos(pi))*sin(pi*t);
for ii=2:n
F(:,:)=F(:,:)+(200/(ii*pi))*(1-cos(ii*pi))*sin(ii*pi*t);
end
We express the second-order ODE, which is the left side of Equation (9-29), via the
anonymous function handle DDx and embed the force function F=func_pulse(t, n)
within an m-file called Sim_func_pulse.m with the ode45 solver. This simulates the
system behavior and plots the simulation results. Note that in this simulation model,
zero initial conditions are taken. The simulation results of the model aer shown in
Figure 9-6 and Figure 9-7.
subplot(212)
yyaxis left
plot(t,Xt(:,1),'k-')
ylabel('Displacement x(t), [m]')
yyaxis right
plot(t, Xt(:,2),'b-.','linewidth', 1.5)
legend('x(t)','dx(t)')
ylabel('Velocity dx(t), [m/s]')
xlabel('time [sec]'), grid on, axis tight
figure
plot(Xt(:,1), Xt(:,2)),
xlabel('x(t)'), ylabel('dx(t)')
title('Phase plot; x vs. dx'), grid on
axis square
function F=func_pulse(t,n)
%HELP. t is time vector. n is number of terms in pulse approximation.
F(1,:)=(200/pi)*(1-cos(pi))*sin(pi*t);
for ii=2:n
F(:,:)=F(:,:)+(200/(ii*pi))*(1-cos(ii*pi))*sin(ii*pi*t);
end
end
312
Chapter 9 Spring-Mass-Damper Systems
313
Chapter 9 Spring-Mass-Damper Systems
Figure 9-7. Phase plot: displacement versus velocity of the SMD system excited
with a periodic rectangular wave force
Now let’s employ the Simulink modeling approach to simulate the system behavior.
The second simulation model is built in Simulink. In Simulink, there are a few
blocks with which periodic pulse signals can be generated (see [4] for more details
about how to build Simulink models). They are signal generator, pulse generator, series
of step function, signal builder, and repeating sequence. Pulses__Input.mdl (shown
in Figure 9-8) is the final model of the spring-mass-damper system subject to external
force, namely, repeated pulses.
314
Chapter 9 Spring-Mass-Damper Systems
The simulation results (input signal versus system response, displacement versus
velocity in the Plots–Scope block, displacement versus velocity in the Phase Plot block)
of the Simulink model (Pulses__Input.mdl) shown in Figure 9-8 are well converged
with the results in Figures 9-6 and 9-7 from the m-file Sim_func_pulse.m. The simulation
results obtained from the Scope block called [Plots] and the XY Scope block called
[Phase Plot] are not shown here. The x-y axis limits of the XY Scope block, shown in
[Phase Plot], are set to [-0.8 0.8 -8 8]. Note that the parameters of the [Signal Generator]
block are as follows:
Amplitude: -100
Frequency: 0.5
Units: Hertz
The values of the other gain parameters M, C, and K, of the model (Pulses__Input.
mdl), are 10, 0.5, and 1000, respectively.
Let’s consider another case with a sinusoidal periodic forced motion of a single-DOF
SMD system with F(t) = F0 cos (ωt).
315
Chapter 9 Spring-Mass-Damper Systems
md 2 y Cdy
Equation (9-27), which is + + Ky = F ( t ) , has a general solution, shown
dt 2 dt
here:
where ω is the applied force’s frequency and φ is the phase shift. The constants A and X
are computed from the initial conditions [1, 2, 3].
x 0 - X cosq
A= (9-31)
sinj
f0
X= (9-32)
(w 2
n -w ) + ( 2zw w )
2 2
n
2
F0
where f 0 = is normalized force magnitude. The phase θ is computed from the
m
following formulation:
2zwnw
q = tan -1 (9-33)
wn2 - w 2
XK X wn2 1
= = (9-34)
F0 f0
(1 - r ) + ( 2z r )
2 2 2
2z r
q = tan -1 (9-35)
1- r2
316
Chapter 9 Spring-Mass-Damper Systems
317
Chapter 9 Spring-Mass-Damper Systems
Again, in our simulation studies of damping ratio (ζ) with the normalized system
amplitude (Figure 9-9) and the phase shift (Figure 9-10), we can conclude that the
resonance peak occurs when the system’s natural frequency equals the periodic
excitation force’s excitation frequency as expected in theoretical evaluations, and the
system behavior will become uncontrollable. To avoid such circumstances, we need to
apply damping. Note that in the script, the function atan2 is used to evaluate the phase
angle θ(r) values since it computes the values of θ(r) in the range of [0, π], whereas the
é p pù
tan function computes in the range of ê - , ú , which is not appropriate in this case.
ë 2 2û
318
Chapter 9 Spring-Mass-Damper Systems
Figure 9-9. Influence of the damping ratio (ζ) on the normalized system response
amplitude
319
Chapter 9 Spring-Mass-Damper Systems
Figure 9-10. Influence of the damping ratio (ζ) on the system phase θ change
320
Chapter 9 Spring-Mass-Damper Systems
1
2
1
1
2
1
( )
2
3 2 1
1
2
2 1 ( )
1
2 1
a)
3 2 1
2 2 − 1 2 + 1 1 − 1 2 + 1 1 ( )
2 1 b)
Using the free-body diagram of the system and applying D’Alembert’s principle for
acting forces on each mass, we can write the equations of motion of the system.
For mass 1:
321
Chapter 9 Spring-Mass-Damper Systems
For mass 2:
Note that m1, m2, c1, c2, c3, k1, k2 are the system parameters of mass, damping, and
stiffness, respectively. x1 and x2 are displacements of mass 1 and 2, respectively, and
x1 , x 2 , x1 , x2 are the velocities and accelerations of mass 1 and mass 2, respectively.
By introducing new state variables, we rewrite Equations (9-36) and (9-37) as a
system of first-order ODEs. To avoid confusion, the variables are renamed as x1 = y1 and
x2 = y2.
ì x1 = y 2
ï 1
ï y 2 = é F ( t ) - ( c1 + c 2 ) y 2 + c 2 y 4 - k1 y1 + k1 y 3 ùû
ï m1 ë
í (9-38)
ï x2 = y4
ï 1
ï y 4 = éc 2 y 2 - ( c 2 + c 3 ) y 4 + k1 y1 - ( k1 + k2 ) y 3 ùû
î m2 ë
Based on the system model defined in Equation (9-38), we write the MATLAB
models, named SMsysSIM.m and two_DOF_sys_sim_ALL.m, and build a Simulink model
named Two_DOF_SMsys.mdl for the case when the external force, F(t) = F0 sin (10t), is
applied.
322
Chapter 9 Spring-Mass-Damper Systems
function DX=SMsys1(t, y)
k1=90; k2=85; c1=2; c2=1; c3=3; m1=5; m2=3; F0=3.3;
Dx(1)= y(2);
Dx(2)=(1/m1)*(F0*sin(10*t)-(c1+c2)*y(2)+c2*y(4)-k1*y(1)+k1*y(3));
Dx(3)= y(4);
Dx(4)= (1/m2)*(c2*y(2)-(c2+c3)*y(4)+k1*y(1)-(k1+k2)*y(3));
DX=[Dx(1); Dx(2); Dx(3); Dx(4)];
end
end
This function file (SMsysSIM.m) computes the displacement and velocity values of
mass 1 and 2 and plots them in a single plot without figure attributes, such as plot title,
legends, etc.
The next m-file (two_DOF_sys_sim_ALL.m) computes the displacement and velocity
values of mass 1 and 2 with the ODE solvers (ode23, ode23s, ode23tb, and ode113)
and the Simulink model (Two_DOF_SMsys.mdl) and plots them separately with all the plot
attributes, as shown in Figure 9-14, Figure 9-15, and Figure 9-16.
% two_DOF_sys_sim_ALL.m
clearvars; close all
ICs=[1; 1.5; -1; 1];
k1=90; k2=85; c1=2; c2=1; c3=3; m1=5; m2=3; F0=3.3;
F=@(t, y)[y(2);(1/m1)*(F0*sin(10*t)-(c1+c2)*y(2)+c2*y(4)- ...
k1*y(1)+k1*y(3)); y(4); ...
(1/m2)*(c2*y(2)-(c2+c3)*y(4)+k1*y(1)-(k1+k2)*y(3))];
t=0:.005:5;
Opts=odeset('OutputFcn',@odeplot,'reltol', 1e-4, 'abstol', 1e-6);
ode45(F, t, ICs, Opts)
xlabel('\it time'), ylabel('x_1, dx_1, x_2, dx_2'), grid on
legend('x_1(t)', 'dx_1(t)', 'x_2(t)', 'dx_2(t)')
title('Simulation of 2-DOF system')
%% Testing different solvers with different ODE settings
% ODE45 with fixed time step of 0.005
ts=0:.005:5; % fixed time step of 0.005
[t1, y1]=ode45(F, ts, ICs, []);
%% ODE23tb with variable time step
323
Chapter 9 Spring-Mass-Damper Systems
t=[0, 5];
[t2, y2]=ode23tb(F, t, ICs, []);
%% ODE23 calls an embedded function SMsys. A fixed time step of 0.005
[t3, y3]=ode23(@SMsys, ts, ICs);
%% ODE113 with the varying step size and function handle
[t4, y4]=ode113(@(t, y)[y(2); (1/m1)*(F0*sin(10*t)- ...
(c1+c2)*y(2)+c2*y(4)-k1*y(1)+k1*y(3)); y(4);
(1/m2)*(c2*y(2)-(c2+c3)*y(4)+k1*y(1)-(k1+k2)*y(3))],t, ICs);
%% SIMULINK model: Two_DOF_SMsys.slx with ODE23S & rel. error tol. 1e-6
OPTs=simset('reltol', 1e-6, 'solver', 'ode23s');
XOUT=sim('Two_DOF_SMsys', t, OPTs); % Simulates model: Two_DOF_SMsys.slx
figure('name', 'Displacement: x1')
plot(t1,y1(:,1), 'b-o'), hold on
plot(t2,y2(:,1), 'r--s')
plot(t3,y3(:,1), 'm-.x'),
plot(t4,y4(:,1), 'g:+')
plot(XOUT.tout, XOUT.yout{1}.Values.Data, 'k-'), grid on
legend('ode45','ode23tb','ode23',...
'ode113','Simulink(ode23s ~var)')
title('Displacement of body mass: m_1')
xlabel('time, [sec]'), ylabel('x_1(t)')
figure('name', 'Displacement: x2')
plot(t1,y1(:,3), 'b-o'), hold on
plot(t2,y2(:,3), 'r--s')
plot(t3,y3(:,3), 'm-.x'),
plot(t4,y4(:,3), 'g:+')
plot(XOUT.tout, XOUT.yout{2}.Values.Data, 'k-'), grid on
legend('ode45','ode23tb','ode23',...
'ode113','Simulink(ode23s ~var)')
title('Displacement of body mass: m_2')
xlabel('time, [sec]'), ylabel('x_2(t)')
% Function called by ODE23TB
function DX=SMsys(t,y)
k1=90; k2=85; c1=2; c2=1; c3=3; m1=5; m2=3; F0=3.3;
324
Chapter 9 Spring-Mass-Damper Systems
Dx(1)= y(2);
Dx(2)=(1/m1)*(F0*sin(10*t)-(c1+c2)*y(2)+c2*y(4)-k1*y(1)+k1*y(3));
Dx(3)= y(4);
Dx(4)= (1/m2)*(c2*y(2)-(c2+c3)*y(4)+k1*y(1)-(k1+k2)*y(3));
DX=[Dx(1); Dx(2); Dx(3); Dx(4)];
end
Note that the Simulink model (Two_DOF_SMsys.mdl) takes all the parameter (m1, m2,
k1, k2, c1, c2, c3, F0) values and initial condition values (defined in the integrator
blocks with these variable names: ICs(1), ICs(2), ICs(3), ICs(4)) from the
simulation m-file called two_DOF_sys_sim_ALL.m. Note that the input plot (the sine
wave in the Simulink model Two_DOF_SMsys.mdl) has Amplitude set to F0 and Frequency
(rad/sec) set to 10.
326
Chapter 9 Spring-Mass-Damper Systems
Figure 9-15. Displacement of body mass 1 computed with different ODE solvers of
MATLAB/Simulink
327
Chapter 9 Spring-Mass-Damper Systems
Figure 9-16. Displacement of body mass 2 computed with different ODE solvers of
MATLAB/Simulink
The simulation results in Figure 9-14 and 9-15 show that all of the employed ODE
solvers (ode23, ode23tb, ode23s, ode45, ode113) have resulted in well-converged
solutions.
328
Chapter 9 Spring-Mass-Damper Systems
The equations of motion of the system with respect to its free-body diagrams
(Figure 9-17) can be expressed with the system of second-order differential equations
shown in Equation (9-39):
ì m1 x1 ( t ) + ( k1 + k2 ) x1 ( t ) - k2 x 2 ( t ) + ( c1 + c 2 ) x1 ( t ) - c 2 x 2 ( t ) = F1 ( t )
ï
ïm2 x2 ( t ) - k2 x1 ( t ) + ( k2 + k3 ) x 2 ( t ) - k3 x 3 ( t )
í
ï + ( c 2 + c 3 ) x 2 ( t ) - c 2 x1 ( t ) - c 3 x 3 ( t ) = F2 ( t )
ï m3 x3 ( t ) - k3 x 2 ( t ) + ( k3 + 2k4 ) x 3 ( t ) - c 3 x 2 ( t ) + c 3 x 3 ( t ) = F3 ( t (9-40)
)
î
Note that m1, m2, m3, c1, c2, c3, k1, k2, and k3 are the system parameters of mass, damping
and stiffness, respectively. x1, x2, and x3 are the displacements of mass 1, 2, 3, respectively.
x1 , x 2 , and x 3 are the velocities, and x1 , x2 , and x3 are the accelerations of mass 1, 2, 3,
respectively. F1(t), F2(t), and F3(t) are applied external forces on mass 1, 2, 3, respectively.
1( ) 2( ) 3( )
1 2 3
1 2 3 4
1 2 3
a)
1 2 3 4
b)
1 1 (− 2 1 + 2 2) (− 3 2 + 3 3) 4 3
1 2 3
1 2 3
Figure 9-17. Three degrees of freedom system: a) a physical model of the system
with three masses rolling on a flat surface without any friction; b) free body
diagram of the system
329
Chapter 9 Spring-Mass-Damper Systems
Note that the system equations in Equation (9-39) and Equation (9-40) are second-
order ODEs, which are linear and time invariant. They are coupled by the coordinate
systems of x1(t), x2(t), and x3(t). Therefore, these equations must be solved
simultaneously. For numerical simulations, the following values for the system
parameters are taken: m1 = 2.5 [kg]; m2 = 2.0 [kg]; m3 = 3.0 [kg];
éN ù éN ù éN ù é Ns ù é Ns ù é Ns ù
k1 = 25 ê ú ; k2 = 5 ê ú ; k3 = k4 = 30 ê ú ; c1 = 2.5 ê ú ; c 2 = 0.5 ê ú ; c 3 = 3.5 ê ú .
ëm û ëm û ëm û ëm û ëm û ëm û
We simulate this system with forced and free motion.
–– Forced motion (vibration) case with zero initial conditions:
e.g.: F1(t) = 20 sin (120t); F2(t) = 0; F3(t) = 20Φ(t − t0);
Note that F3(t) is a Heaviside step function Φ(t − t0) applied at t0 = 0.
–– Free motion (vibration) case. No external forces are
applied: F1(t) = F2(t) = F3(t) = 0;. There is an initial
(excitation) displacement applied on mass 1 only:
x1 ( 0 ) = 0.5, x 2 ( 0 ) = 0 , x 3 ( 0 ) = 0 ; x1 ( 0 ) = 0 , x 2 ( 0 ) = 0 , x 3 ( 0 ) = 0 ; .
Note that before writing a simulation model, we rewrite the system equations
in Equation (9-39) via first-order ODEs. The system has three second-order
(acceleration) variables, x1 , x2 , and x3 , which will be substituted with new variables,
i.e., x1 = y1 , x1 = y 2 , x1 = y 2 ; x 2 = y 3 , x 2 = y 4 , x2 = y 4 ; x 3 = y 5 , x 3 = y6 ,an
nd x3 = y 6 . Using these
new variables, we can write the next system of first-order coupled ODE equations.
ì x1 = y 2
ï
ï y = æ 1 ö ( F ( t ) - ( k + k ) y + k y - ( c + c ) y + c y )
ï 2 çè m1 ÷ø 1 1 2 1 2 3 1 2 2 2 4
ï
ï x 2 = y 4
í (9-41)
ï y 4 = (1 / m2 ) ( F2 ( t ) + k2 y1 - ( k2 + k3 ) x 3 + k3 y 5 - ( c 2 + c 3 ) y 4 )
ï x = y
ï 3 6
ï æ 1 ö
ï y 6 = ç ÷ ( F3 ( t ) + k3 y 3 - ( k3 + 2k4 ) y 5 + c 3 y 4 - c 3 y6 )
î è m3 ø
Based on the formulations in Equation (9-41), we write a function file called three_
MASS.m with the ode45 solver. Note that the function file contains a nested function called
third_DOF(t, y) that defines the system equations given in Equation (9-41).
The system parameter values and external forces are also defined within this nested
function. The Heaviside step function is expressed via MATLAB’s built-in function step().
330
Chapter 9 Spring-Mass-Damper Systems
% three_MASS.m
% HELP. Simulation of highly coupled three degree of freedom system.
clearvars; clc
t=0:.01:120; % Simulation time span
IC=[0;0;0;0;0;0]; % Case # 1
% IC=[0.5; 0; 0; 0; 0; 0]; % Case # 2
for k=1:t(end)-20
% Note: Displacement magnitudes of x1, x2, x3 increased
% by the factor of 10 for better visualization
plot(-20,0,'*', 20,0, '*', -10+10*xyz(k+20,1), 0, 'r-o',...
-5+10*xyz(k+20,3),0,'g-o',...
10+10*xyz(k+20,5),0,'b-o','markersize', 35, ...
'markerfacecolor', 'c');
331
Chapter 9 Spring-Mass-Damper Systems
This simulation model includes forced (Case #1) and free (Case #2) motion inputs,
such as input forces and nonzero initial conditions (for mass 1) for forced and free
motion cases, respectively.
Moreover, it incorporates the commands to call and execute the Simulink model of
the system, as shown in Figure 9-18. Note that the Simulink model, ThreeDOFsys.slx,
takes the numerical values of all the parameters, and the initial conditions are set inside
the integrator blocks from the simulation function file, three_MASS.m. The external
force magnitudes of the Simulink model are initiated by selecting Model Properties ➤
Callbacks ➤ InitFcn.
Note that in the Simulink model ThreeDOFsys.slx, the [Sine Wave] block is
used for an input force signal F1(t) applied on mass 1 with the following parameters:
Amplitude =1, Frequency=120, Phase=0, Bias =0, Sample time=0. It has the following
output formulation: O(t) = Amplitude * sin (Frequency * t + Phase) + Bias. The input
332
Chapter 9 Spring-Mass-Damper Systems
force signal is F1(t) = O(t) * F1, where F1 is a constant gain value. The force applied on
mass 3 has a constant value equal to F3. The force applied on mass 2 is 0. Thus, F2 = 0,
and it is ignored in the model.
333
Chapter 9 Spring-Mass-Damper Systems
Forced motion case. In this case, we take all zero initial conditions and two nonzero
applied external forces:
IC=[0;0;0;0;0;0]; % Case # 1
F1=20*sin(120*t);F2=0; t0=0; F3=20*stepfun(t,t0); % Case # 1
By simulating the model (three_MASS.m) that recalls and executes the Simulink
model (threeDOFsys.slx), we obtain the simulation results shown in Figure 9-19 and
an animation plot (not shown here) demonstrating the motion of the three masses with
respect to each other.
Figure 9-19. Simulation of the three degree of freedom coupled system with forced
vibration
The simulation results in Figure 9-19 show that the MATLAB model results match
with the ones from the Simulink model.
334
Chapter 9 Spring-Mass-Damper Systems
Free motion case. In this case, we take all zero initial conditions and two nonzero
applied external forces.
IC=[0.5;0;0;0;0;0]; % Case # 2
F1=0; F2=0; F3=0; % Case # 2
The simulation results of Case #2 (free motion, shown in Figure 9-20) show that the
small initial displacement (nonzero) on mass 1 result in displacements in the other two
masses as well. The computed results by the MATLAB and Simulink models converge
perfectly even though different solvers and step sizes are used.
Figure 9-20. Simulation results of free motion of the three-DOF SMD system
335
Chapter 9 Spring-Mass-Damper Systems
[ M ] x + [C ] x + [ K ] x = [ B ] F (t ) (9-42)
with the initial conditions x ( 0 ) = x 0 and x ( 0 ) = x 0 , where [M], [C], [K] are mass, damper,
and spring matrices, and [B] is a column force matrix of F(t) applied force. By dividing
both sides of Equation (9-1) by [M] or multiplying by [M−1] and introducing new
variables, second-order ODEs are converted into first-order ODEs. The introduction of
new variables, for instance, for a second-order system will be x = y1 , x = y 2 , and x = y 2 .
With these substitutions, the next system of two differential equations is obtained.
ìï y1 = y 2
í (9-43)
îï y 2 = ë M û [ B ] F ( t ) - ë M û [ K ] y1 - ë M û [C ] y 2
é -1 ù é -1 ù é -1 ù
é y1 ù é [0] y1 + [ I ] y2 ù
y = ê ú = ê ú=
ë y 2 û êë éë M ùû [ B ] F ( t ) - éë M ùû [ K ] y1 - éë M ùû [C ] y 2 úû
-1 -1 -1
é [0] ù é [0] y1 + [ I ] y2 ù
ê ú+ê ú (9-44)
êë éë M ùû [ B ] F ( t ) úû êë - éë M ùû [ K ] y1 - éë M ùû [C ] y 2 úû
-1 -1 -1
y ( t ) = f ( t ) + [ A ] y ( t ) (9-45)
336
Chapter 9 Spring-Mass-Damper Systems
é 0 I ù
A=ê ú (9-46)
êë - éë M ùû [ K ] - éë M ùû [C ]úû
-1 -1
é y1 ( t ) ù é 0 ù é y1 ( 0 ) ù é x 0 ù
y (t ) = ê ú , f ( t ) = ê M -1 BF t ú , y 0 = ê ú=ê ú (9-47)
ë y2 (t )û ë ( )û ë y 2 ( 0 ) û ë x 0 û
To summarize, after evaluating matrix [A] and a force vector f(t), if the given system is
subject to external force, we can solve the equation y ( t ) = f ( t ) + [ A ] y ( t ) numerically.
Example. Let’s consider previously studied three-DOF SMD system.
F1 ( t ) = 0 ; F2 ( t ) = 20 F ( t - t 0 ) ; F3 ( t ) = 0 ;
Note that F2(t) is the Heaviside step function Φ(t − t0) of maginutude 20 applied at
t0 = 0.
We write the simulation model script of the problem, MASS3.m, with a nested
function, DOF3(t, x).
function MASS3
% HELP. Simulation of three-degree-of-freedom system.
t=0:.01:120; % Simulation time span
IC=[0;0;0;0;0;0]; % Case # 1. Forced Motion
337
Chapter 9 Spring-Mass-Damper Systems
338
Chapter 9 Spring-Mass-Damper Systems
function dx = DOF3(t, x)
% HELP: three-degree-of-freedom system simulation
k1=25; k2=5; k3=30; k4=k3; c1=2.5; c2=.5; c3=3.5;
m1=2.5; m2=2; m3=3; M=[m1 0 0; 0 m2 0; 0 0 m3];
K=[k1+k2, -k2, 0; -k2, k2+k3, -k3; 0, -k3, k3+2*k4];
C=[c1+c2, -c2, 0; -c2, c2+c3, -c3; 0, -c3, c3];
% Case 1: External forces applied
F1= 0; t0=0; F2=20*stepfun(t,t0); F3=0;
% Case 2: Free vibration (No force applied)
% F1=0;F2=0;F3=0;
B=[F1;F2;F3]; A=[zeros(3) eye(3); -inv(M)*K, -inv(M)*C];
f=(M\eye(3))*B; dx=A*x+[0;0;0;f];
end
end
339
Chapter 9 Spring-Mass-Damper Systems
Figure 9-21. Simulation results of forced motion of the three-DOF SMD system
340
Chapter 9 Spring-Mass-Damper Systems
341
Chapter 9 Spring-Mass-Damper Systems
342
Chapter 9 Spring-Mass-Damper Systems
The developed simulation models of the three-DOF SMD system with free and
forced motion can be applied for n-DOF systems with minor adjustments to the system
parameters. The matrix approach is relatively simple and computationally efficient.
References
[1] Inman, D. J., 2008, Engineering Vibration (3rd ed.), Pearson Prentice Hall, pp. 15–28,
282–288.
[2] Dimarogonas, A., 1996, Vibration for Engineers (2nd ed.), Prentice Hall, pp. 84–89.
343
Chapter 9 Spring-Mass-Damper Systems
[4] Sulaymon Eshkabilov, Beginning MATLAB and Simulink, Apress, New York: ISBN
(pbk) 978-1-4842-5060-0, ISBN (electronic) 978-1-4842-5061-7 (2019). DOI:
https://doi.org/10.1007/978-1-4842-5061-7.
344