0% found this document useful (0 votes)
217 views

Lab 05 PDF

Here are the steps to solve this problem: 1) Write the differential equation for the system: m*y'' + b*y' + k*y = f(t) 2) Convert to first order system: y1 = y y1' = y2 y2' = (f(t) - b*y2 - k*y1)/m 3) Write the transfer function: Y(s)/F(s) = 1/(ms^2 + bs + k) 4) Write an m-file to simulate the system response to a unit step input: function dydt = sys(t,y) m = 10;
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
217 views

Lab 05 PDF

Here are the steps to solve this problem: 1) Write the differential equation for the system: m*y'' + b*y' + k*y = f(t) 2) Convert to first order system: y1 = y y1' = y2 y2' = (f(t) - b*y2 - k*y1)/m 3) Write the transfer function: Y(s)/F(s) = 1/(ms^2 + bs + k) 4) Write an m-file to simulate the system response to a unit step input: function dydt = sys(t,y) m = 10;
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

International Islamic University, Islamabad

Faculty of Engineering and Technology


Iqra College of Technology

Control Technology Lab

LAB # 5: Mathematical Modeling of 1st & 2nd Order System using


MATLAB

Name of Student: …………………………………………

Registration No.: ……………………………………………

Date of Experiment: ………………………………………

Marks obtained: ………………………………………

Remarks: …………………………………………………

Instructor’s Signature: ……………………………...


Lab 05: Mathematical Modeling of 1st and 2nd Order Systems using MATLAB

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

Mass-Spring System Model


Consider the following Mass-Spring system shown in the figure. Where 𝐹𝑠(𝑥) is the spring
force, 𝐹𝑓 (𝑥̇ ) is the friction coefficient, 𝑥(𝑡) is the displacement and 𝐹𝑎(𝑡) is the applied force:

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.

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 (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).

Speed Control example:


Assume the spring force 𝐹𝑠 (𝑥) = 0 which means that𝐾 = 0. Equation (2) becomes
𝑑2 𝑥(𝑡) 𝑑𝑥(𝑡)
𝑀 +𝐵 = 𝐹𝑎 (𝑡) (4)
𝑑𝑡 2 𝑑𝑡
Or
𝑑𝑣(𝑡)
𝑀 𝑑𝑡 + 𝐵𝑣 = 𝐹𝑎 (𝑡) (5)
Equation (5) is a first order linear ODE.

Using MATLAB solver ode45; we can write do the following:

Step I: Create a MATLAB-function speed.m

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

Step II: In MATLAB Command Window, write:


>> v0= 0; %(initial speed)
>>[t,v]=ode45('speed', [0 125],v0);
>> plot(t,v);
>>title('Speed time response to a constant traction force Fa(t) ')
>>xlabel('Time'); ylabel('Velocity');
>>grid

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:

Set Step function Final Value as Fa/M and Gain as B/M.

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.

Mass-Spring System Example:

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

Variables New variable Differential Equation


𝑥(𝑡) 𝑋1 𝑑𝑋1
= 𝑋2
𝑑𝑡
𝑑𝑥(𝑡) 𝑑𝑋2 𝐵 𝐾 𝐹𝑎 (𝑡)
𝑋2 = − 𝑋2 − 𝑋1 (𝑡) +
𝑑𝑡 𝑑𝑡 𝑀 𝑀 𝑀

𝑑𝑋1
𝑋 𝑑𝑋
In vector form, Let 𝑋 = [ 1 ]; 𝑑𝑡 = [𝑑𝑋
𝑑𝑡
] then the system can be written as
𝑋2 2
𝑑𝑡
𝑋2
𝑑𝑋
=[ 𝐵 𝐾 𝐹𝑎 (𝑡)]
𝑑𝑡 − 𝑋2 − 𝑋1 (𝑡) +
𝑀 𝑀 𝑀

The ode45 solver can be now be used:

Step I: Create a MATLAB-function massSpring2.m


function dXdt=mass_spring(t, X)
%flow rate
M=750; %(Kg)
B=30; %( Nsec/m)
Fa=300; %N
K=15; %(N/m)
% dX/dt
dXdt=[0;0];
dXdt(1)=X(2);
dXdt(2)=-B/M*X(2)-K/M*X(1)+Fa/M;

Page 5 of 7
Lab 05: Mathematical Modeling of 1st and 2nd Order Systems using MATLAB

Step II: In MATLAB Command Window, write:


>> X0=[0; 0]; %(initial speed and position)
>>[t,X]=ode45('mass_spring', [0 200],X0);
>>plot(t,X)
>>title('Time Response to a Constant Traction Force Fa(t) ')
>> xlabel('Time');
>>ylabel('Velocity and Displacement');
>>grid;

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

Time Response to a Constant Traction Force Fa(t)


35

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

You might also like