LCS Lab 3
LCS Lab 3
Where
and
(1)
In the case where:
The differential equation for the above Mass-Spring system can then be written as follows
(2)
B is called the friction coefficient and K is called the spring constant.
1|Page
The linear differential equation of second order (2) describes the relationship between the displacement and the
applied force. The differential equation can then be used to study the time behavior of x(t) under various changes
of the applied force. In reality, the spring force and/or the friction force can have a more complicated expression or
could be represented by a graph or data table. For instance, a nonlinear spring can be designed such that
(3)
Equation (3) represents another possible model that describes the dynamic behavior of the mass-damper system
under external force. Model (2) is said to be a linear model whereas (3) is said to be nonlinear.
Solving the differential equation using MATLAB: The objectives behind modeling the mass-damper system can be
many and may include
Understanding the dynamics of such system
Studying the effect of each parameter on the system such as mass M, the friction coefficient B, and the
elastic characteristic Fs(x).
Designing a new component such as damper or spring.
Reproducing a problem in order to suggest a solution.
The solution of the difference equations (1), (2), or (3) leads to finding x(t) subject to certain initial conditions.
MATLAB can help solve linear or nonlinear ordinary differential equations (ODE). To show how you can solve
ODE using MATLAB we will proceed in two steps. We first see how can we solve first order ODE and second
how can we solve equation (2) or (3).
MATLAB Modeling:
Assume the spring force Fs(x) = Kxr(t). The mass-spring damper is now equivalent to
The second order differential equation has to be decomposed in a set of first order differential equations as follows
2|Page
The ode45 solver can be now be used:
1_ create a MATLAB-function mass_spring.m
Function dXdt=mass_spring(t, X)
%flow rate
M=750; %(Kg)
B=30; %( Nsec/m)
Fa=300; %N
K=15; %(N/m)
r=1;
% dX/dt
dXdt(1,1)=X(2);
dXdt(2,1)=-B/M*X(2)-K/M*X(1)^r+Fa/M;
2_ in MATLAB write
3|Page
Creating M-
file to
Creating
22
produce
M-file for the
parameter plot.
values.
Output:
4|Page
Making Subplots in MATLAB:
Creating
M-file to
make
subplot.
Output:
5|Page
Create M-file to use “sim” function and produce multiple runs and
their plots
Output:
Exercise 3: System response from the stored energy with zero input
Find the response of the above system when there is no input for t ≥0, but when the initial value
of the displacement x(0) is zero and the initial velocity v(0) is 1 m/s.
6|Page
Output:
7|Page
8|Page
INTEGRATOR (Continuous library)
The block for an integrator as shown below looks unusual. The quantity 1/s comes from the
Laplace transform expression for integration. When double-clicked on the symbol for an
integrator, a dialog box appears allowing the initial condition for that integrator to be
specified. It may be implicit, and not shown on the block, as in Figure (a). Alternatively, a
second input to the block can be displayed to supply the initial condition explicitly, as in part
(b) of Figure. Initial conditions may be specific numerical values, literal variables, or
algebraic expressions.
9|Page
SCOPE (Sinks library)
The system response can be examined graphically, as the simulation runs, using the Scope
block in the sinks library. This name is derived from the electronic instrument, oscilloscope,
which performs a similar function with electronic signals. Any of the variables in a Simulink
diagram can be connected to the Scope block, and when the simulation is started, that
variable is displayed. It is possible to include several Scope blocks. Also, it is possible to
display several signals in the same scope block using a MTJX block in the signals & systems
library. The Scope normally chooses its scales automatically to best display the data.
In the Simulink diagram, the appearance of a block can be changed by changing the
foreground or background colors, or by drop shadow or other options available in the format
drop down menu. The available options can be reached in the Simulink window by
highlighting the block, then clicking the right mouse button. The Show Drop Shadow option
is on the format drop-down menu.
10 | P a g e
Mass Spring System Model:
Consider the following Mass-Spring system shown in the figure. Where F s(x) is the spring
force, Ff( ẋ ) is the friction coefficient, x(t) is the displacement and Fa(t) is the applied force:
The differential equation for the above Mass-Spring system can then be written as follows
(1)
For Non-linear such case, (1) becomes
(2)
Modelling of a Second Order System:
Construct a Simulink diagram to calculate the response of the Mass-Spring system. The input
force increases from 0 to 8 N at t = 1 s. The parameter values are M = 2 kg, K= 16 N/m, and
B =4 N.s/m.
Steps:
Draw the free body diagram.
Write the modeling equation from the free body diagram
Solve the equations for the highest derivative of the output.
Draw a block diagram to represent this equation.
Draw the corresponding Simulink diagram.
Use Step block to provide the input fa(t).
In the Step block, set the initial and final values and the time at which the step occurs.
Use the “To Workspace” blocks for t, fa(t), x, and v in order to allow MATLAB to
plot the desired responses. Set the save format to array in block parameters.
Select the duration of the simulation to be 10 seconds from the Simulation >
Parameters entry on the toolbar
Given below is a file that will set up the MATLAB workspace by establishing the values of
the parameters needed for the Simulink simulation of the given model.
M-file for parameter values:
% This file is named exl_parameter.m.
% Everything after a % sign on a line is a comment that
% is ignored by M This file establishes the
% parameter values for exl_model.mdl.
%
11 | P a g e
M=2; %kg
K= 16; %N/m
B=4; % Ns/m
Simulink block diagram:
12 | P a g e
in. This is accomplished with the subplot command. The following M-file uses this command
to produce both plots of displacement and velocity.
M-file to make subplots
% This file is named exl_plot2.m.
% It makes both plots, displacement and velocity.
% Execute exlparameter.m first.
subplot(2,l,1);
plot(t,x); grid % Plots x for the case with B=4. xlabel (‘Time (s) ‘) ;
ylabel (‘Displacement (m) ‘); subplot(2,1,2);
plot(t,v); grid % Plots v for the case with B=4. xlabel(’Time (s)’);
ylabel(’Velocity (m per s)’);
13 | P a g e
Result:
Comments:
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
14 | P a g e