Lab 05 PDF
Lab 05 PDF
Remarks: …………………………………………………
Lab 05: Mathematical Modeling of 1st & 2nd Order System using
MATLAB
Objectives: The objective of this exercise is to grasp the important role mathematical models
of physical systems in the design and analysis of control systems. We will learn how MATLAB
helps in solving such models.
List of Equipment/Software
Following equipment/software is required:
MATLAB
Personal Computer
Where
𝑑𝑣(𝑡) 𝑑2 𝑥(𝑡)
𝑎= = is the acceleration,
𝑑𝑡 𝑑𝑡 2
𝑑𝑥(𝑡)
𝑣= is the speed, (1)
𝑑𝑡
and
𝑥(𝑡) is the displacement.
According to the laws of physics
𝑀𝑎 + 𝐹𝑓 (𝑣) + 𝐹𝑠 (𝑥) = 𝐹𝑎 (𝑡) (2)
In the case where:
𝑑𝑥(𝑡)
𝐹𝑓 (𝑣) = 𝐵𝑣 = 𝐵
𝑑𝑡
𝐹𝑠 (𝑥) = 𝐾𝑥(𝑡)
The differential equation for the above Mass-Spring system can then be written as follows
𝑑2 𝑥(𝑡) 𝑑𝑥(𝑡)
𝑀 𝑑𝑡 2 + 𝐵 𝑑𝑡 + 𝐾𝑥(𝑡) = 𝐹𝑎 (𝑡) (3)
B is called the friction coefficient and K is called the spring constant.
The linear differential equation of second order (3) describes the relationship between the
displacement and the applied force. The differential equation can then be used to study the time
Page 2 of 7
Lab 05: Mathematical Modeling of 1st and 2nd Order Systems using MATLAB
behavior of 𝑥(𝑡) 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.
Equation (3) represents another possible model that describes the dynamic behavior of the mass-
damper system under external force, Model (3) is said to be a linear model.
The solution of the difference equations (2), (3) leads to finding 𝑥(𝑡) 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 (3).
function dvdt=speed(t, v)
%flow rate
M=750; %(Kg)
B=30; %( Nsec/m)
Fa=300; %N
% dv/dt=Fa/M-B/M v
dvdt=Fa/M-B/M*v;
Page 3 of 7
Lab 05: Mathematical Modeling of 1st and 2nd Order Systems using MATLAB
Simulink Implementation:
Write a script to initialize the variables:
M=750; %(Kg)
B=30; %( Nsec/m)
Fa=300; %N
sim('Lab07a.mdl')
Draw a Simulink diagram as follows:
Output:
Speed Time Response to a Constant Traction Force Fa(t)
10
6
Speed
0
0 20 40 60 80 100 120 140
Time
Page 4 of 7
Lab 05: Mathematical Modeling of 1st and 2nd Order Systems using MATLAB
There are many other MATLAB ODE solvers such as ode23, ode45, ode113, ode15s, etc… The
function dsolve will result in a symbolic solution. Do ‘doc dsolve’ to know more. In MATLAB
write
>>dsolve(‘Dv=Fa/M-B/M*v’, ‘v(0)=0’)
Note that using MATLAB ODE solvers are able to solve linear or nonlinear ODE’s. We will see
in part II of this experiment another approach to solve a linear ODE differently. Higher order
systems can also be solved similarly.
Assume the spring force𝐹𝑠 (𝑥) = 𝐾𝑥(𝑡). The mass-spring damper is now equivalent to
𝑑2 𝑥(𝑡) 𝑑𝑥(𝑡)
𝑀 2
+𝐵 + 𝐾𝑥(𝑡) = 𝐹𝑎 (𝑡)
𝑑𝑡 𝑑𝑡
The second order differential equation has to be decomposed in a set of first order differential
equations as follows
𝑑𝑋1
𝑋 𝑑𝑋
In vector form, Let 𝑋 = [ 1 ]; 𝑑𝑡 = [𝑑𝑋
𝑑𝑡
] then the system can be written as
𝑋2 2
𝑑𝑡
𝑋2
𝑑𝑋
=[ 𝐵 𝐾 𝐹𝑎 (𝑡)]
𝑑𝑡 − 𝑋2 − 𝑋1 (𝑡) +
𝑀 𝑀 𝑀
Page 5 of 7
Lab 05: Mathematical Modeling of 1st and 2nd Order Systems using MATLAB
Simulink Implementation:
Write a script to initialize the variables:
M=759; B=30; Fa=300; K=15;
sim('Lab02b.mdl')
Set Step function Final Value as Fa/M, Gain as B/M and Gain1 as K/M
30
25
Velocity and Displacement
20
15
10
-5
0 20 40 60 80 100 120 140 160 180 200
Time
Page 6 of 7
Lab 05: Mathematical Modeling of 1st and 2nd Order Systems using MATLAB
Exercises 1
Consider the mechanical system depicted in the figure.
The input is given by 𝑓(𝑡), and the output is given by 𝑦(𝑡).
Determine the transfer function from 𝑓(𝑡) to 𝑦(𝑡) and using
MATLAB, write a m-file and plot the system response to a unit
step input. Let 𝑚 = 10, 𝑘 = 1 and 𝑏 = 0.5. Show that the peak
amplitude of the output is about 1.8.
Exercise 2:
Find the solution of 1st order differential
equation of RC circuit given below using Matlab
ode45 function. Let 𝑣𝑖𝑛 = 5𝑉, 𝑅 = 100𝐾Ω and 𝐶 =
2µ𝐹.
𝑑𝑞(𝑡)
Hint: Use 𝑖 = 𝑑𝑡 relation to form a first order
differential equation.
Exercise 3:
Find the unit step response of RLC circuit given below
using Matlab. Also solve 2nd order differential equation
using Matlab ode45 function.
Let 𝑣𝑖𝑛 = 10𝑉, 𝑅 = 15𝐾Ω, 𝐿 = 1100𝑛𝐻 and 𝐶 =
3.3𝑝𝑓.
𝑑𝑞(𝑡)
Hint: Use 𝑖 = 𝑑𝑡 relation to form a second order
differential equation.
Page 7 of 7