Lab 2

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 16

FEEDBACK CONTROL SYSTEM

LAB # 2

Prepared By :
Uzma Perveen

NED University of Engineering & Technology


Objective:

 The objective of this session is:


o Mathematical Modeling of Physical Systems
o MATLAB helps in solving such models
Derive a mathematical model for
Mass-Spring System

o Where;
o According to the laws of physics

o In the case where:

o The differential equation for the above Mass-Spring


system can then be written as follows:

-------------------- (1)

• B is called the friction coefficient and


• K is called the spring constant.
o The linear differential equation of second order (2)
describes the relationship between the Displacement and
the Applied Force.

o The differential equation can then be used to study the


time behavior of x(t) under various changes of the
applied force.

o 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 (see
figure 2.1) such that
o In such case, Equation (1) becomes

-------------------- (2)

o Equation (2) represents another possible model that


describes the dynamic behavior of the mass-damper system
under external force.
 Model (1) is said to be a linear model whereas
 Model (2) is said to be nonlinear.
o To decide if a system is linear or nonlinear two properties
have to be verified
 homogeneity and
 superposition.
Assignment: use homogeneity and superposition properties to show that
• model (1) is linear whereas
• model (2) is nonlinear.
Solving the differential equation using MATLAB:

 The objectives behind modeling the mass-damper system can be


many and may include
o Understanding the dynamics of such system
o Studying the effect of each parameter on the system such as
• Mass M,
• Friction coefficient B, and
• Elastic characteristic Fs(x).
o The solution of the difference equations (1), or (2) leads to finding
x(t) subject to certain initial conditions.

 MATLAB can help to solve linear or nonlinear ordinary differential


equations (ODE).
o We first see how can we solve first order ODE and
o Second how can we solve equation (1) or (2).
Speed Cruise Control example:
o Assume the spring force Fs(x) =0 which means that K=0.
Equation (1) becomes

------------------------ (3)

Or

------------------------ (4)

Equation (4) is a first order linear ODE.


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

1. create a MATLAB-function cruise_speed.m

function dvdt=cruse_speed(t,v)
M=750;
B=30;
Fa=300;
%dv/dt=(Fa/M)-(B/M)v
dvdt=Fa/M-B/M*v;
2. create a new MATLAB m-file and write
v0=0;% (initial speed)
[t,v]=ode45('cruse_speed',[0 200],v0);
plot(t,v);
grid on;
title('cruise speed time response to a constant fraction force Fa(t)')
Mass-Spring System Example:
o Assume the spring force Fs(x) = k xr(t). The mass-spring
damper is now equivalent to

o The second order differential equation has to be decomposed


in a set of first order differential equations as follows
o In vector form, let

o Then the system can be written as;


 The ode45 solver can be now be used:

1. create a MATLAB-function mass_spring.m

function dXdt=mass_spring(t,X)
M=705; % (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

>> X0=[0; 0]; %(initial position and speed)

>>[t,X]=ode45('mass_spring', [0 200],X0);

 Exercise
1. Plot the position and the speed in separate graphs.

2. Change the value of r to 2 and 3.


3. Superpose the results and compare with the linear
case r=1 and plot all three cases in the same plot
window. Please use different figures for velocity and
displacement.
1. When r=1 (Linear model)
clear all
close all
clc
X0=[0;0];% (Initial speed and position)
[t,X]=ode45('mass_spring',[0 200],X0);
figure;
plot(t,X(:,1));
xlabel('Time(t)');
ylabel('Position');
title('Mass spring system');
legend('Position ');
grid;
figure;
plot(t,X(:,2),'r');
xlabel('Time(t)');
label('Speed');
title('Mass spring system');
legend('Speed ');
grid;
2. When r=2 (Nonlinear Model)
clear all
close all
clc
X0=[0;0];% (Initial Position and Speed)
[t,X]=ode45('mass_spring',[0 200],X0);
figure;
plot(t,X(:,1));
xlabel('Time(t)');
ylabel('Position');
title('Mass spring system');
legend('Position ');
grid;
figure;
plot(t,X(:,2),'r');
xlabel('Time(t)');
ylabel('Speed');
title('Mass spring system');
legend('Speed ');
grid;

You might also like