Anda di halaman 1dari 36

Lab Session 1

Feedback
Control Systems
BE(EL)

Lecturer
Electrical Engg.Department( NED UET)
Objective:
 The objective of this session is to learn how to represent
polynomials in MATLAB,
o Find roots of polynomials,
o create polynomials when roots are known and
o Obtain partial fractions.
Polynomial Overview:
 MATLAB provides functions for standard polynomial operations, such as
polynomial roots, evaluation, and differentiation. In addition, there are functions
for more advanced applications, such as curve fitting and partial fraction
expansion.

Polynomial Function Summary


Representing Polynomials
 MATLAB represents polynomials as row vectors containing coefficients ordered by
descending powers. For example, consider the equation

To enter this polynomial into MATLAB, use


>> p = [1 0 -2 -5];

Polynomial Roots
The roots function calculates the roots of a polynomial:
By convention, MATLAB stores roots in column
>> r = roots(p) vectors.
2.0946
r=
-1.0473 + 1.1359i
-1.0473 - 1.1359i
o The function poly returns to the polynomial coefficients:
>> p2 = poly(r)
p2 =
1 0 -2 -5

o poly and roots are inverse functions,


Polynomial Evaluation
o The polyval function evaluates a polynomial at a specified value.
o To evaluate p at s = 5, use

>> polyval(p,5)

ans =
110
Convolution and Deconvolution
 Polynomial multiplication and division correspond to the operations convolution
and deconvolution.
o The functions conv and deconv implement these operations.
o Consider the polynomials a(s )=s2+2s+3 and b(s )=4s2+5s+6 .
o To compute their product,
>> a = [1 2 3];
>> b = [4 5 6];
>> c = conv(a,b)
c=
4 13 28 27 18
o Use deconvolution to divide back out of the product:

>>[q,r] = deconv(c,a)
q=
4 5 6 b = [4 5 6];
r=
0 0 0 0 0
Polynomial Derivatives
 The polyder function computes the derivative of any polynomial.
o To obtain the derivative of the polynomial.

>>p= [1 0 -2 -5]
>>q = polyder(p)
q=
3 0 -2

 polyder also computes the derivative of the product or quotient of two polynomials.
o For example, create two polynomials a and b:
>>a = [1 3 5];
>>b = [2 4 6];
 Calculate the derivative of the product a*b by calling polyder with a single output argument:
>>c = polyder(a,b)
c=
8 30 56 38
Transfer Function
• Transfer Function is the ratio of Laplace transform of the
output to the Laplace transform of the input. Consider all initial
conditions to zero.

u(t) y(t)
Plant

If u ( t )  U ( S ) and
y(t )  Y ( S )

• Where is the Laplace operator.


 8
Transfer Function
• The transfer function G(S) of the plant is given as

Y (S )
G( S ) 
U (S )

U(S) G(S) Y(S)

9
Why Laplace Transform?
• Using Laplace transform, we can convert many
common functions into algebraic function of complex
variable s.
• For example 
 sin t  2
s  2
 at 1
e 
sa
• Where s is a complex variable (complex frequency) and
is given as 10

s    j
Partial Fraction Expansion
 ‘residue’ finds the partial fraction expansion of the ratio of two polynomials.
 This is particularly useful for applications that represent systems in transfer function form.
 For polynomials b and a,

where r is a column vector of residues,


p is a column vector of pole locations, and
k is a row vector of direct terms.

 Consider the transfer function


>>b = [-4 8]; r= p=
>>a = [1 6 8]; k=
-12 -4
>>[r,p,k] = residue(b,a) []
8 -2
Transfer Function
Objective:
 The objective of this session is:
o Partial Fraction Expansion,
o Transfer Function Representation
o Pole-Zero location of a Transfer Function
1.1. Obtain the partial fractions of the function F(s) = (s + 1)/ (s2 + s + 1).
close all;
clear all;
clc;
b=[1 1];
a=[1 1 1];
[r,p,k]=residue(b,a) %It finds the residues, pole and direct terms of a partial fraction expan

The result of the command is;


r=
0.5000 - 0.2887i
0.5000 + 0.2887i
p=
-0.5000 + 0.8660i
-0.5000 - 0.8660i
k=
[]
1.2. Define the following transfer function G(S) in MATLAB. G(s) = s (s + 1)
(s + 2) / s (s + 3) (s2 + 4s + 8).
close all;
clear all;
clc;
num=[1 3 2];
den=[1 7 20 24 0];
sys=tf(num,den) %generates the transfer function with the given numerator num and denominator den.

The result of the command is;


Transfer function:
s^3 + 3s^2 +2s
---------------------------
S^4 + 7 s^3 + 20 s^2 + 24 s
1.3. Find the location of the zeros, poles and plot the pole-zero map of the system,
whose transfer function given by;
F(s) = (2s2 + 8s + 6) / (s4 + 6s3 + 12s2 + 24s)
close all;
clear all;
clc;
num=[0 0 2 8 6];
den=[1 6 12 24 0];
[z,p,k]=tf2zp(num,den) % generates the poles, zeros and gain

The result of the command is; The result specifies that the zeros are at s=-3 and -1, the poles are at
s=0, -4.5198, -0.7401 + 2.1822i and
s=-0.7401 - 2.1822i
and the gain is k=2.
k=
2 z = -3 -1 p = 0 -4.5198 -0.7401 + 2.1822i -0.7401 - 2.1822i
Pole-zero map for this function can be obtained by using the following command.
pzmap(num,den)
1.4) Verify the results obtained for example 1.3 by obtaining the transfer function from the calculated
values of zeros, poles and gain.
close all;
clear all;
clc;
z=[-3; -1];
p=[0; -4.5198; -0.7401 + 2.1822i; -0.7401 - 2.1822i];
k=2;
[n,d]=zp2tf(z,p,k);
printsys(n,d,'s') % prints the transfer function as a ratio of two polynomials in the transform variable 's'. The result of
the command is
1.5. Find the Laplace transform of the function
f (t) =e-t (1-sin (t))
clear all;
close all;
clc;
syms t %define the function f(t)
ft=exp(-t)*(1-sin(t));
fs=laplace(ft)

The result of the command is; fs = 1/(s + 1) - 1/((s + 1)^2 + 1)


1.6) Find the inverse Laplace transform of the function F(s) =1/(s + 4).
clear all;
close all;
clc;
syms s t %construct symbolic objects for Laplace transform variable 's' and time variable 't'.
fs=1/(s+4);
ft=ilaplace(fs)
The result of the command is;
ft =
1/exp(4*t)
Exercise 1:
Consider the two polynomials p(s)=s2+2s+1 and q(s)=s+1 .
Use MATLAB to compute
a. p(s )*q(s)
b. Roots of p(s) and q(s)
c. p(-1 ) and q(6)
Exercise 2:
Use MATLAB command to find the partial fraction of the following
a.
b.

Exercise 3: MATLAB M-file Script


Use MATLAB to generate the first 100 terms in the sequence a(n) define recursively by
a(n+1) = p*a(n)*(1-a(n))
with p=2.9 and a(1) = 0.5.
LAB SESSION 2
OBJECTIVE

The objective of this session is

 Mathematical Modeling of Physical Systems

 Solution of mathematical models using ODE45 solver in


MATLAB
SIMPLE MASS-SPRING SYSTEM
According to the laws of kinematics

“Sum of all the input forces must be equal to output forces”

Where
Differential equation for above system can be written as

Equation (1)

where
‘B’ is called the friction coefficient and ‘K’ is called the spring constant.

 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
 a nonlinear spring can be designed
 In such case, Equation (1) becomes
Equation (2)

 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.

 To decide if a system is linear or nonlinear two properties have to be verified


-homogeneity and
-superposition.
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,
 •Friction coefficient B, and
 •Elastic characteristic Fs(x).
 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).
 We first see how can we solve first order ODE and
 Second how can we solve equation (1) or (2).
SPEED CRUISE CONTROL EXAMPLE:
Assume the spring force Fs(x) =0 which means that K=0. Equation (1) becomes

Equation (3)

Or

Equation (4)

Equation (4) is a first order linear ODE.


USING MATLAB SOLVER ode45

Write a function in script file & save it with .m extension.

function dvdt=cruise_speed(t,v)
M=750;
B=30;
Fa=300;
dvdt=Fa/M-B/M*v; %dv/dt=(Fa/M)-(B/M)v
create a new MATLAB m-file and write
v0=0;% (initial speed)
[t,v]=ode45('cruise_speed',[0 200],v0);
plot(t,v);
grid on;
title('cruise speed time response to a constant fraction force Fa(t)')

 Post Lab Task

Explain the curve shown in figure. Also change the


parameters defined in function, observe the variation &
comment.
Assume the spring force Fs(x) = k xr(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
In vector form, let

Then the system can be written as;


create a MATLAB-function mass_spring.m

function dXdt=mass_spring(t,X)

M=750; % (Kg)
B=15; % (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;
1.When r=1 (Linear model )
clear all; close all; clc;
X0=[0;0];
[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;
2.When r=2 (Nonlinear Model)
Write the same code as above by varying the value of r
POST LAB TASK

Plot the position and the speed in separate graphs by using the codes used in lab procedure.
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. Use
different figures for velocity and displacement.
4. Change the values of each parameters, such as
 Mass M,
 Friction coefficient B, and
 Elastic characteristic k.
Compare the results and describe the effects.

Anda mungkin juga menyukai