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 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
>> 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 )
Y (S )
G( S )
U (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
sa
• 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,
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)
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.
•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)
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)')
The second order differential equation has to be decomposed in a set of first order differential equations as
follows
In vector form, let
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.