Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

International Islamic University Islamabad

Faculty of Engineering & Technology


Department of Electrical Engineering

CONTROL SYSTEMS LAB

Experiment No. 2: Mathematical Modeling of physical systems using MATLAB

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

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

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

Submitted To: ………………………………………...

Experiment No. 2: Mathematical Modeling of physical systems using MATLAB Page 1


Objectives:
 To learn about the mathematical modeling of physical systems for the design and analysis
of control systems.
 To learn how MATLAB can be used in solving such models.
Equipment Required:
 Personal Computer (PC)
 MATLAB software (updated)
Theory:
A mathematical model of an electrical circuit can be obtained by applying one or both of
Kirchhoff’s laws whereas Newton’s second law is applied to mechanical systems to derive its
transfer function and state-space models.
Mass-Spring system:
Let we have a mass-spring model as shown in Figure 2.1(a) whose equivalent block
diagram is depicted in Figure 2.1(b).

Figure 2.1 (a): Mass-Spring system Figure 2.1 (b): Block Diagram
Begin the solution by drawing the free-body diagram as shown in Figure 2.2. We assume
that the mass is traveling toward the right. Thus, only the applied force points towards right; all
other forces impede the motion and act to oppose it. Hence, the spring, viscous damper
(friction), and the force due to acceleration point towards left. The spring force is assumed to

be either linear or can be approximated by a linear function ( F s ( x ) = K x ( t ) ) .

Figure 2.2: Free-body diagram of Mass-Spring system

Experiment No. 2: Mathematical Modeling of physical systems using MATLAB Page 2


We can write the differential equation of motion using Newton’s law; sum all the forces
acting on mass and set them equal to zero.
𝑑 2 𝑥(𝑡) 𝑑𝑥(𝑡)
𝑀 + 𝐵 + 𝐾𝑥(𝑡) = 𝐹(𝑡) (2.1)
𝑑𝑡 2 𝑑𝑡
w h e r e , M i s t h e m a s s , B = f v is the friction coefficient, K is spring constant, x(t) is
the displacement a n d F ( t ) is the applied force.
The linear second order differential equation (2.1) describes the relationship between
displacement (x(t)) and applied force (F(t)). It can be used to study the dynamic behavior of x(t)
under various changes in applied force F(t).
Similarly, we can write,
𝑑𝑣(𝑡) 𝑑 2 𝑥(𝑡)
𝑎 = = is the acceleration (2.2)
𝑑𝑡 𝑑𝑡 2
𝑑𝑥(𝑡)
𝑣 = is the speed (2.3)
𝑑𝑡
MATLAB can help to obtain the solution of linear or nonlinear ordinary differential
equations (ODE) using different solvers.
Example of Speed Cruise Control:
Assume the spring force F s ( x ) = 0, which means that K = 0. Eq. (2.1) becomes,

d2 x(t) dx(t)
𝑀 +𝐵 = 𝐹(𝑡) (2.4)
dt 2 dt
dv(t)
𝑀 + 𝐵𝑣 = 𝐹(𝑡) (2.5)
dt
dv(t) 𝐹(𝑡) 𝐵𝑣
or = − (2.6)
dt 𝑀 𝑀
Eq. (2.6) is a first order linear ODE. Using MATLAB solver ode45, we can solve this
equation using following steps.

Step 1: M-file code:


% Create a MATLAB-function (speed.m)
function dvdt = speed(t,v) % function defination
M = 750; % (kg)
B = 30; % (Nsec/m)
F = 300; % (N)
dvdt = (F/M) - (B*v/M);
Step 2: Calling the speed function in command window
>> v0 = 0; % (initial speed)
>> [t,v] = ode45('speed', [0 125],v0); % ode45 solver
>> plot(t,v);
>> title('Speed Response to a constant Traction Force F(t)')

Experiment No. 2: Mathematical Modeling of physical systems using MATLAB Page 3


>> xlabel('Time');
>> ylabel('Speed');
>> grid on

Figure 2.3
Implementation using MATLAB/Simulink:
 Draw the Simulink model diagram as shown in Figure 2.4.

Figure 2.4
 Simulate the model of Figure 2.4 and observe the output as shown in Figure 2.5.

Figure 2.5

Experiment No. 2: Mathematical Modeling of physical systems using MATLAB Page 4


There are many other MATLAB ODE solvers such as ode23, ode113, ode15s etc. to
solve linear or nonlinear ODE’s.
Example of Mass-Spring System:

Assuming the spring force F s ( x ) = K x ( t ) , the mass-spring system is equivalent to,

𝑑 2 𝑥(𝑡) 𝑑𝑥(𝑡)
𝑀 + 𝐵 + 𝐾𝑥(𝑡) = 𝐹(𝑡) (2.7)
𝑑𝑡 2 𝑑𝑡
The second order differential equation will be decomposed into a set of two 1st order
differential equations as follows:

Variable New Variable Differential Equation

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

𝑑𝑋1
𝑋 𝑋̇ 𝑑𝑡
In vector form, Let 𝑋 = [ 1 ]; [ 1 ] = [𝑑𝑋 ]; then the system can be written as:
𝑋2 𝑋2 ̇ 2
𝑑𝑡

𝑋̇ 𝑋2
[ 1] = [ 𝐵 𝐾 𝐹(𝑡)]
𝑋2̇ − 𝑋2 − 𝑋1 +
𝑀 𝑀 𝑀

Now, ode45 solver can be used to obtain the solution.


Step 1: M-file code:
% Create a MATLAB-function (mass_spring.m)
function dXdt = mass_spring (t,X) %function definition
M = 750; %(kg)
B = 30; %(Nsec/m)
F = 300; %(N)
K = 15; %(N/m)
dXdt = [0;0]; % dX/dt
dXdt(1)= X(2); % This is rate of change of displacement (velocity)
dXdt(2) = -(B/M)*X(2)-(K/M)*X(1)+F/M; % This is rate of change of
velocity (acceleration)

Experiment No. 2: Mathematical Modeling of physical systems using MATLAB Page 5


Step 2: Calling the mass_spring function in command window
>> 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 F(t)')
>> xlabel ('Time');
>> ylabel ('Speed and Displacement');
>> legend('X1(Displacement)', 'X2(Velocity)')
>> grid on;

Figure 2.6
Implementation using MATLAB/Simulink:
 Draw the Simulink model diagram as shown in Figure 2.7.

Figure 2.7
 Simulate the model of Figure 2.7 and observe the output as shown in Figure 2.8.

Experiment No. 2: Mathematical Modeling of physical systems using MATLAB Page 6


Figure 2.8

Exercise Problems
Question No. 1:
Find the solution of first order differential equation of RC circuit given in Figure 2.9 using

MATLAB ode45 function. Let Vi = 5𝑉, R = 100kΩ and C = 2uF.


𝒅𝒒(𝒕)
Hint: Use 𝒊 = relationship to form a first order differential equation.
𝒅𝒕

Figure 2.9
Question No. 2:
a. Find the solution of second order differential equation of RLC circuit given in Figure 2.10

using MATLAB ode45 function. Let Vi = 10V, R = 3Ω, L = 5H and C = 0.1F


𝒅𝒒(𝒕)
Hint: Use 𝒊 = relationship to form a second order differential equation.
𝒅𝒕
b. Find the unit step response of given RLC circuit using MATLAB.

Figure 2.10

Experiment No. 2: Mathematical Modeling of physical systems using MATLAB Page 7

You might also like