Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
25 views

Basic MATLAB Commands For Control

This 3-sentence summary provides the high-level information about the document: The document is a beginner's guide to using MATLAB for control systems that introduces key MATLAB functions for representing and manipulating transfer functions, polynomials, state space models, and performing operations like inverse Laplace transforms, convolution of polynomials, partial fraction expansion. It provides examples of representing common transfer functions and converting between different representations using functions like tf, zpk, ss, residue, ilaplace, conv, and poly.

Uploaded by

AK
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Basic MATLAB Commands For Control

This 3-sentence summary provides the high-level information about the document: The document is a beginner's guide to using MATLAB for control systems that introduces key MATLAB functions for representing and manipulating transfer functions, polynomials, state space models, and performing operations like inverse Laplace transforms, convolution of polynomials, partial fraction expansion. It provides examples of representing common transfer functions and converting between different representations using functions like tf, zpk, ss, residue, ilaplace, conv, and poly.

Uploaded by

AK
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 66

MATLAB for Control: A Beginners’ Guide

Department of Electrical, Computer & Software Engineering,


The University of Auckland,
Auckland, New Zealand.

MATLAB for Control: A Beginners’ Guide 1 / 66


MATLAB for Control: A Beginners’ Guide 2 / 66
Computation of Inverse Laplace Transform
ilaplace: This function gives the inverse Laplace transform of a function which
is represented by a symbolic expression. The following example illustrate this
Example-1: Determine the inverse Laplace transform of
3s + 1
F (s) =
(s2 + 2s + 9)
]
syms s; % s is a symbolic variable
F s = (3 ∗ s + 1)/(s2 + 2 ∗ s + 9);
f=ilaplace(Fs);
This gives

3 ∗ exp(−t) ∗ (cos(2 ∗ 2(1/2)∗t ) − (2(1/2) ∗ sin(2 ∗ 2(1/2)∗t ))/6)

If we want to determine its value for a particular value of t, (say t = 10) then,
the following command should be executed.
t=10;
y=subs(f);

MATLAB for Control: A Beginners’ Guide 3 / 66


MATLAB for Control: A Beginners’ Guide 4 / 66
Manipulation of Polynomials
How to represent a polynomial ?
I A polynomial is often represented by a vector whose successive elements
correspond to the coefficients of polynomial terms in descending power.
Example-2: The polynomial

s5 + 2s4 + 3s3 + 5s2 + 7s + 9

would be represented by a vector [1.0 2.0 3.0 5.0 7.0 9.0]

However, if we represent this by [9.0 7.0 5.0 3.0 2.0 1.0]


this would correspond to the polynomial

9s5 + 7s4 + 5s3 + 3s2 + 2s + 1

Examples:

x3 + 4x + 1 =⇒ [1.0 0.0 4.0 1.0]


4
10x − 3x =⇒ [10.0 0.0 0.0 -3.0 1.0]

MATLAB for Control: A Beginners’ Guide 5 / 66


MATLAB for Control: A Beginners’ Guide 6 / 66
Manipulation of Polynomials
I A frequently used function in control systems in the conv function.
conv:Convolve two polynomials (represented as row vectors of their coefficients).
It is particularly useful for determining the expanded coefficients for factored
polynomials.
Example: Represent the product of the following two polynomials by a vector

x3 + 3x + 2 x2 + 5x + 6 = f1 (x)f2 (x)
 

Solution
f1=[1 3 2];
f2=[1 5 6];
f3=conv(f1,f2);
Similarly

f1=[1 9 7 5 2];
x4 + 9x3 + 7x2 + 5x + 2 x2 − 4x + 6 = f1 (x)f2 (x)
 
=⇒ f2=[1 -4 6];
f3=conv(f1,f2);

MATLAB for Control: A Beginners’ Guide 7 / 66


MATLAB for Control: A Beginners’ Guide 8 / 66
Representation of System by Transfer Functions

tf: This is used to represent a transfer function.


Example-1: Represent the transfer function
s+2
G(s) =
s2 + 5s + 2

G=tf([1 2],[1 5 2]);


Example-2: Represent the transfer function
(s + 3)(s + 5)
G(s) =
s(s + 4)(s + 6)(s2 + 5s + 8)

num=conv([1 3],[1 5]); % Numerator


den1=conv([1 0],[1 4]); % First 2 terms of Denominator
den2=conv([1 6],[1 5 6]); % Last 2 terms of Denominator
den=conv(den1,den2); % Denominator
G=tf(num,den);

MATLAB for Control: A Beginners’ Guide 9 / 66


MATLAB for Control: A Beginners’ Guide 10 / 66
Representation of System by Transfer Functions
poly: This converts roots to polynomial.
poly(V) where V is a vector, is a vector whose elements are the coefficients of
the polynomial whose roots are the elements of V.
Example-1: Consider the function
(x + 1)(x + 2)(x + 3)(x + 5)
I The following command
A=poly([-1 -2 -3 -5]);
would give a vector A=[1 11 41 61 30] which corresponds to the polynomial
x4 + 11x3 + 41x2 + 61x + 30.
Example-2: Represent the transfer function
(s + 3)(s + 5)
G(s) =
s(s + 4)(s + 6)(s + 8)

num=poly([-3 -5]; % Numerator


den=poly([0 -4 -6 -8]); % Denominator
G=tf(num,den);

s2 + 8s + 15
G=
s4 + 18s3 + 104s2 + 192s
MATLAB for Control: A Beginners’ Guide 11 / 66
MATLAB for Control: A Beginners’ Guide 12 / 66
Transfer Function Representation

Given
Y (s) 25
G(s) = = 2
U (s) s + 4s + 25
This can be represented by using
MATLAB Function:tf

Method-I Method-II

num=[0 0 25]; s=tf(’s’)


den=[1 4 25]; G = 25/(s2 + 4 ∗ s + 25);
G=tf(num,den);
Table: Caption

MATLAB for Control: A Beginners’ Guide 13 / 66


MATLAB for Control: A Beginners’ Guide 14 / 66
Transfer Function Representation: Zero Pole Gain Representation

Given
Y (s) 3(s − 1)
G(s) = =
U (s) (s − 2 + i)(s − 2 − i)
This can be represented by using
MATLAB Function:zpk

zeros=[1];
poles=[2-i 2+i];
Gain=3;
G=zpk(zeros,poles,gain);

MATLAB for Control: A Beginners’ Guide 15 / 66


MATLAB for Control: A Beginners’ Guide 16 / 66
Representation of System by Transfer Functions

zpk: This constructs zero-pole model or converts to zero-pole-gain format.


Example-1: Represent the transfer function

s2 + 6s + 5
G(s) =
s4 + 7s3 + 80s2 + 204s
into zero-pole-gain format.

num=[1 6 5]; % Numerator


den=[1 7 80 204 0]; % Denominator
Gtf=tf(num,den); % Transfer function
Gzpk=zpk(Gtf); % zpk is used to create zero-pole-gain model

I This will give


(s + 5)(s + 1)
G(s) =
s(s + 3)(s2 + 4s + 68)

MATLAB for Control: A Beginners’ Guide 17 / 66


MATLAB for Control: A Beginners’ Guide 18 / 66
Representation of System by Transfer Functions

zpk: This constructs zero-pole model or converts to zero-pole-gain format.

Example-2: Represent the transfer function

s4 + 20s3 + 27s2 + 17s + 35


G(s) =
s5 + 8s4 + 9s3 + 20s2 + 29s + 32
into zero-pole-gain format.

num=[1 20 27 17 35]; % Numerator


den=[1 8 9 20 29 32]; % Denominator
Gtf=tf(num,den); % Transfer function
Gzpk=zpk(Gtf); % zpk is used to create zero-pole-gain model

I This will give


(s + 18.59)(s + 1.623)(s2 − 0.214s + 1.16)
G(s) =
(s + 7.042)(s + 1.417)(s2 − 0.4593s + 2.906)

MATLAB for Control: A Beginners’ Guide 19 / 66


MATLAB for Control: A Beginners’ Guide 20 / 66
State Space Representation

Given
   
1 0 1
ẋ = Ax + Bu A= ,B = ,
−2 1 0
   
y = Cx + Du C= 3 −2 , D = 0

MATLAB Function:ss
A=[1 0;-2 1];
B=[1 0]’;
C=[3 -2];
D=[0]; sys=ss(A,B,C,D);

MATLAB for Control: A Beginners’ Guide 21 / 66


MATLAB for Control: A Beginners’ Guide 22 / 66
Partial Fraction Expansion
Given:
2s2 + 3s + 2
G(s) =
s2 + 3s + 2
Represent this function in partial fraction expansion.
MATLAB Function residue
num=[2 3 2];
den=[1 3 2];
[r p k]
=residue(num,den);

I This gives r = [−4 1]0 , p = [−2 − 1]0 , k = 2. This implies


r(1) r(n)
G(s) = k(s) + + ... +
s − p(1) s − p(n)
−4 1
= 2s0 + +
s − (−2) s − (−1)
1 4
=2+ −
s+1 s+2

MATLAB for Control: A Beginners’ Guide 23 / 66


MATLAB for Control: A Beginners’ Guide 24 / 66
Computing Response of Linear Systems

MATLAB for Control: A Beginners’ Guide 25 / 66


Example-1:Simulation of Linear Systems-1
Objective: To compute the output response of the system with the transfer
function
Y (s) s2 + 2s + 3
G(s) = = 3
R(s) s + 2s2 + 3s + 4

for any arbitrary input u(t).


Procedure:
Step-1: Represent the system transfer function

num=[1 2 3]; den=[1 2 3 4];


sys=tf(num,den);
Step-2: Specify the total duration of simulation including the time step of the
integration and input signal of length N number of samples.
N=1000; dt=0.03; % Time step
t=0.0:dt:(N-1)*dt;
t=t’; % Make t a column vector
u=ones(N,1);

MATLAB for Control: A Beginners’ Guide 26 / 66


MATLAB for Control: A Beginners’ Guide 27 / 66
Example-1:Simulation of Linear Systems-2
Step-3: Compute the output response and plot it
y=lsim(sys,u,t);
plot(t,y,’LineWidth’,1.5) grid
xlabel(’Time in Sec’,’FontSize’,18);
ylabel(’Output y(t)’,’FontSize’,18);
title(’Step Response’,’FontSize’,18)
u=ones(N,1);

MATLAB for Control: A Beginners’ Guide 28 / 66


Example-2: Simulation of Linear Systems-1
I Compute both the step and impulse response of the system with the transfer
function
Y (s) s2 + 2s + 3
G(s) = = 3
R(s) s + 2s2 + 3s + 4

Source File: test-lsim2.m


num=[1 2 3]; den=[1 2 3 4];
sys=tf(num,den);N=1000;
t=linspace(0.0,30,N)’;dt=t(2)-t(1);
ustep=ones(N,1);
uimpulse=zeros(N,1);uimpulse(1,1)=1/dt;
ystep=lsim(sys,ustep,t);
yimpulse=lsim(sys,uimpulse,t);
plot(t,ystep,’b’,’LineWidth’,1.5) hold on
plot(t,yimpulse,’r’,’LineWidth’,1.5)
legend(’Step Response’,’Impulse Response’,’FontSize’,18)
grid
xlabel(’Time in Sec’,’FontSize’,18);
ylabel(’Output y(t)’,’FontSize’,18);
title(’Step and Impulse Response’,’FontSize’,18)

MATLAB for Control: A Beginners’ Guide 29 / 66


MATLAB for Control: A Beginners’ Guide 30 / 66
Example-2: Simulation of Linear Systems-2
I The step and impulse response of the system with the transfer function
Y (s) s2 + 2s + 3
G(s) = = 3
R(s) s + 2s2 + 3s + 4
is shown below

MATLAB for Control: A Beginners’ Guide 31 / 66


MATLAB for Control: A Beginners’ Guide 32 / 66
Representation of Cascaded Systems

MATLAB for Control: A Beginners’ Guide 33 / 66


MATLAB for Control: A Beginners’ Guide 34 / 66
Cascaded Systems: Blocks in Series
I Consider the figure below which consists of 2-systems with transfer functions
G1 (s) and G2 (s)

I The relation between the output C(s) and input R(s) is given by
C(s)
= G1 (s)G2 (s) =⇒ C(s) = G1 (s)G2 (s)R(s)
R(s)
I Determine the equivalent block using MATLAB if
s+4 4
G1 (s) = , G2 (s) = 2
s2 + 2s + 10 s + 5s + 2

num1=[1 4]; den1=[1 2 10]; %First Block


num2=[4]; den2=[1 5 2]; %Second Block
sysG1=tf(num1,den1); % First Transfer Function G1 (s)
sysG2=tf(num2,den2); % Second Transfer Function G2 (s)
sysEq=series(sysG1,sysG2); % Equivalent Single Transfer Function

MATLAB for Control: A Beginners’ Guide 35 / 66


MATLAB for Control: A Beginners’ Guide 36 / 66
Cascaded Systems: Blocks in Parallel
I Consider the figure below which consists of 2-systems with transfer functions
G1 (s) and G2 (s)

I The relation between the output C(s) and input R(s) is given by
C(s)
= G1 (s) + G2 (s) =⇒ C(s) = [G1 (s) + G2 (s)] R(s)
R(s)
I Determine the equivalent block using MATLAB if
s+4 4
G1 (s) = 2 , G2 (s) = 2
s + 2s + 10 s + 5s + 2
num1=[1 4]; den1=[1 2 10]; %First Block
num2=[4]; den2=[1 5 2]; %Second Block
sysG1=tf(num1,den1); % First Transfer Function G1 (s)
sysG2=tf(num2,den2); % Second Transfer Function G2 (s)
sysEq=parallel(sysG1,sysG2); % Equivalent Single Transfer Function
MATLAB for Control: A Beginners’ Guide 37 / 66
MATLAB for Control: A Beginners’ Guide 38 / 66
Example-1:Simulating Cascaded Feedback Systems-1

I Consider the figure below which consists of 2-systems with transfer functions
G1 (s) and G2 (s)

I The relation between the output C(s) and input R(s) is given by
 
C(s) G1 (s) G1 (s)
= =⇒ C(s) = R(s)
R(s) 1 + G1 (s)G2 (s) 1 + G1 (s)G2 (s)

Objective: To compute the output c(t) of the closed loop system for step
reference i.e when r(t) = 1(t).

MATLAB for Control: A Beginners’ Guide 39 / 66


MATLAB for Control: A Beginners’ Guide 40 / 66
Example-1:Simulating Cascaded Feedback Systems-2
Step-1: Determine the equivalent block using MATLAB. Let
s+4 4
G1 (s) = 2 , G2 (s) = 2
s + 2s + 10 s + 5s + 2
num1=[1 4]; den1=[1 2 10]; %Feed forward Block
num2=[4]; den2=[1 5 2]; %Feedback Block
sysG1=tf(num1,den1); % First Transfer Function G1 (s)
sysG2=tf(num2,den2); % Second Transfer Function G2 (s)
sysEq=feedback(sysG1,sysG2); % Equivalent Single Transfer Function
Step-2: Simulation of Closed Loop System

Source File: test-lsim-feedback1.m


timestep=0.01;% Integration Timestep
N=1000;
t=0.0:timestep:(N-1)*timestep;t=t’;
r=ones(N,1);
y=lsim(sysEq,r,t);
plot(t,y,’LineWidth’,1.5) grid
xlabel(’Time in Sec’,’FontSize’,16);
ylabel(’Output y(t)’,’FontSize’,16);
title(’Step Response’,’FontSize’,16)
MATLAB for Control: A Beginners’ Guide 41 / 66
MATLAB for Control: A Beginners’ Guide 42 / 66
Example-2:Simulating Cascaded Feedback Systems-1

I Consider the unity feedback system consisting of the controller Gc (s) and system
G(s) which are given by

Objective: To compute the output y(t) of the closed loop system for step
reference i.e when r(t) = 1(t).
Step-1: Determine the equivalent block using MATLAB. Let
s+1 1
Gc (s) = , G2 (s) =
s+2 500s2

numGc=[1 1]; denGc=[1 2]; Gc=tf(numGc,denGc); % Controller Block


numG=[1]; denG=[500 0 0]; G=tf(numG,denG); % System Block
Gseries=series(Gc,G); % Equivalent block in feedforward path
Gclosed=feedback(Gseries,1); % Equivalent Transfer Function

MATLAB for Control: A Beginners’ Guide 43 / 66


MATLAB for Control: A Beginners’ Guide 44 / 66
Example-2:Simulating Cascaded Feedback Systems-2
Step-2: Simulation of Closed Loop System
Source File: test-lsim-feedback2.m
timestep=0.2;% Integration Timestep
N=100000;
t=0.0:timestep:(N-1)*timestep;t=t’;
r=ones(N,1);
y=lsim(Gclosed,r,t);
plot(t,y,’LineWidth’,1.5) grid
xlabel(’Time in Sec’,’FontSize’,16);
ylabel(’Output y(t)’,’FontSize’,16);
title(’Step Response’,’FontSize’,16)

MATLAB for Control: A Beginners’ Guide 45 / 66


MATLAB for Control: A Beginners’ Guide 46 / 66
Concept of Dominant Poles and Zeros

Poles which are closer to the jω-axis are called dominant poles and those
far away from the jω-axis are called non-dominant or insignificant poles

The distance D between the dominant reason and the non-dominant (


insignificant) region is shown in Fig 1. Now comes the important question: how
far from the imaginary axis the poles should be located so that it can be
designated as insignificant or non-dominant. We do not have any clear-cut rules
to determine this. However, as a rule of thumb,

MATLAB for Control: A Beginners’ Guide 47 / 66


MATLAB for Control: A Beginners’ Guide 48 / 66
Dominant Poles and Zeros

Rule of Thumb

If the magnitude of the real part of the pole is at least 5 to 10 times that of
a dominant pole or a pair of complex dominant poles, then the pole may be
regarded as non-dominant (insignificant) from the perspective of preserving
transient response with acceptable error.

a. Similar to the poles, the zeros which are close to the jω-axis in the left-half
s-plane affect the transient response significantly compared to the zeros which
are located far away from the jω-axis ( relative to dominant poles).
b. Although,the regions shown in Figure 1 give us a rough idea about the dominant
and non-dominant regions in the s-plane, while designing the controllers ( e.g.
the pole placement controller), we often desire the dominant poles to be located
near the regions shown in Figure 2 which will ensure ξ = 0.707.

MATLAB for Control: A Beginners’ Guide 49 / 66


MATLAB for Control: A Beginners’ Guide 50 / 66
Dominant Poles & Zeros

Figure: Regions of dominant and insignificant poles in the s-plane for purpose of design

MATLAB for Control: A Beginners’ Guide 51 / 66


MATLAB for Control: A Beginners’ Guide 52 / 66
Correct Procedure of Neglecting the Insignificant Poles
While approximating a higher order system to lower order one, we must ensure
that both the transient and the steady state responses of the original system are
preserved ( with practically acceptable error). The procedure to achieve this are
as follows:
a. Suppose the system is represented as:
K(s + z1 )(s + z2 ) . . . (s + zm )
G(s) = (1)
sN (s + p1 )(s + p2 ) . . . (s + pα )(s + pα+1 ) . . . (s + pn )
b. Assume that there are α-number of insignificant poles located at
s = −p1 , −p2 , . . . , −pα .
c. Represent the terms associated with these poles in time constant form. The
transfer function of Eq. (1) becomes
K (s + z1 )(s + z2 ) . . . (s + zm )
 
G(s) = (2)
p1 p2 . . . pα sN (1 + T1 s)(1 + T2 s) . . . (1 + Tα s)(s + pα+1 ) . . . (s + pn )
1
where Ti = , i = 1, 2, . . . , α.
pi
d. Eliminate the terms (1 + Ti s), i = 1, 2, . . . , α. This gives the approximated
transfer function as:
 
K (s + z1 )(s + z2 ) . . . (s + zm )
G(s) = (3)
p1 p2 . . . pα sN (s + pα+1 ) . . . (s + pn )
MATLAB for Control: A Beginners’ Guide 53 / 66
MATLAB for Control: A Beginners’ Guide 54 / 66
Approximating Higher Order Systems
Consider a system with closed loop transfer function
16000(s + 1)
T(s) = (4)
(s + 2)(s + 8)(s + 40)(s + 50)
The poles at s = −40 and s = −50 are far to the left of jω-axis.Their
contribution to the transient response is negligible ( they decay very quickly to
zero as e−40t and e−50t ). These poles can be neglected without appreciable error
as follows:
We will represent the system as:
16000(s + 1)
T(s) = (5)
1 1
40 × 50(1 + s)(1 + s)(s + 2)(s + 8)
40 50
The approximated transfer function equals to
8(s + 1)
T(s) = (6)
(s + 2)(s + 8)
Note that, following the above method, the steady state value of the original
system is equal to the steady state value of the approximated system. For a unit
step input, it is equal to 0.5. However, if we simply remove the terms (s + 40)
and (s + 50) in Eq. (4), the approximated second order system will have a
different steady state value i.e 1000 to a step input.
MATLAB for Control: A Beginners’ Guide 55 / 66
MATLAB for Control: A Beginners’ Guide 56 / 66
Adding Poles to Closed Loop System:
Original System:
C(s) K K
T(s) = = 2 =⇒ C(s) = R(s)
R(s) s + a1 s + a2 s2 + a1 s + a2
Hence for step input where R(s) = 1/s
K K
c(∞) = css = lim sC(s) = lim = = T(0)
s→0 s→0 s2 + a1 s + a2 a2
Addition of a Pole:
If we add a pole at s = −b to the closed-loop system, the system becomes
C(s) K K
T(s) = = 2 =⇒ C(s) = R(s)
R(s) (s + a1 s + a2 )(s + b) (s2 + a1 s + a2 )(s + b)
Hence for step input where R(s) = 1/s
K K
c(∞) = css = lim sC(s) = lim =
s→0 s→0 (s2 + a1 s + a2 )(s + b) a2 b
Thus the the steady state error of the modified system is reduced. If we want to
have the same steady state error, the gain K should be multiplied by the factor
b.
MATLAB for Control: A Beginners’ Guide 57 / 66
MATLAB for Control: A Beginners’ Guide 58 / 66
Adding Zeros to Closed Loop System:

Addition of a Zero:
If we add a zero at s = −c to the closed-loop system, the system becomes
C(s) K(s + c) K(s + c)
T(s) = = 2 =⇒ C(s) = R(s)
R(s) (s + a1 s + a2 ) (s2 + a1 s + a2 )

Hence for step input where R(s) = 1/s

K(s + c) Kc
c(∞) = css = lim sC(s) = lim =
s→0 s→0 (s2 + a1 s + a2 ) a2
Thus the the steady state error of the modified system is increased. If we want
to have the same steady state error, as of the original system, the gain K of the
modified system should be divided by the factor c.

MATLAB for Control: A Beginners’ Guide 59 / 66


MATLAB for Control: A Beginners’ Guide 60 / 66
MATLAB for Control: A Beginners’ Guide 61 / 66
MATLAB for Control: A Beginners’ Guide 62 / 66
MATLAB for Control: A Beginners’ Guide 63 / 66
MATLAB for Control: A Beginners’ Guide 64 / 66
MATLAB for Control: A Beginners’ Guide 65 / 66
MATLAB for Control: A Beginners’ Guide 66 / 66

You might also like