Performing Mathematical Operation and Performance Analysis in MATLAB
Performing Mathematical Operation and Performance Analysis in MATLAB
Performing Mathematical Operation and Performance Analysis in MATLAB
I. INTRODUCTION
MATLAB allows designers to perform complicated SYS=SERIES(SYS1,SYS2,OUTPUTS1,INPU
mathematical calculations in fast and efficient manner. TS2) connects two LTI models. SYS1 and SYS2
Partial fraction expansion, simplification, pole-zero are in series such that the outputs of SYS1
determination, Laplace transform, inverse Laplace specified by OUTPUTS1 are connected to the
transform, state-space model generation are some of the inputs of SYS2 specified by INPUTS2. The
mathematical operation that can be very easily performed vectors OUTPUTS1 and INPUTS2 contain
in MATLAB. Performing Laplace and inverse Laplace indices into the outputs and inputs of SYS1 and
transforms are mathematical methods. They are widely SYS2, respectively. The resulting LTI model
used in control systems. After performing Laplace SYS maps u1 to y2.
transforms, different mathematical operations can be If OUTPUTS1 and INPUTS2 are omitted, SERIES
applied to them. Students will learn to implement them connects SYS1 and SYS2 in cascade and returns
using MATLAB. SYS = SYS2 * SYS1
SYS = SERIES (SYS1, SYS2,'name') connects SYS1
To view the step response of a particular system for a and SYS2 by matching I/O names. The output names
particular transfer function, unit step function is given as an of SYS1 and input names of SYS2 should be fully
input. The output is then the step response. specified.
If SYS1 and SYS2 are arrays of LTI models, SERIES
II. THEORY AND METHODOLOGY returns an LTI array SYS of the same size where
SYS(:,:,k)=SERIES(SYS1(:,:,k),SYS2(:,:,k),OUTPUT
MATLAB Functions: S1,INPUTS2) .
1|P a g e
o PRINTSYS: Print system in pretty format o TF: Creation of transfer functions or
and is used to print state space systems with conversion to transfer function. Creation:
labels to the right and above the system SYS = TF(NUM,DEN) creates a
matrices or to print transfer functions as a continuous-time transfer function SYS with
ratio of two polynomials. numerator(s) NUM and denominator(s)
PRINTSYS (NUM, DEN,'s') or PRINTSYS DEN. The output SYS is a TF object.
(NUM,DEN,'z') prints the transfer function as o ZPK Create zero-pole-gain models or
a ratio of two polynomials in the transform
convert to zero-pole-gain format. Creation:
variable 's' or 'z'.
SYS = ZPK (Z, P, K) creates a continuous-
o FEEDBACK: Feedback connection of two time zero-pole-gain (ZPK) model SYS with
LTI models. zeros Z, poles P, and gains K. The output
SYS = FEEDBACK (SYS1, SYS2) SYS is a ZPK object.
an LTI model SYS for the closed - o The sym command creates symbolic
loop feedback system
variables and expressions. For example, the
commands x = sym('x'); a = sym('alpha');
create a symbolic variable x with the value
x assigned to it in the MATLAB workspace
and a symbolic variable ‘a’ with the value
alpha assigned to it. An alternate way to
create a symbolic object is to use the syms
Negative feedback is assumed and the resulting system command:
SYS maps u to y. To apply positive feedback, use the
syntax:
o pretty(X) prints symbolic output of X in a
SYS = FEEDBACK (SYS1, SYS2, +1). format that resembles typeset mathematics.
o laplace(f) computes the Laplace transform
o STEP: Step response of LTI models of f.
[Y,T] = STEP(SYS) returns the output o ilaplace(F) computes the Inverse Laplace
response Y and the time vector T used for transform of F.
simulation. No plot is drawn on the screen. o SIMPLIFY Simplify representation of
If SYS has NY outputs and NU inputs, and
Uncertain objects
LT = length(T), Y is an array of size [LT
NY NU] where Y(:,:,j) gives the step o SIMPLIFY Simplify representation of
response of the j-th input channel. Uncertain objects
[Y,T,X] = STEP(SYS) also returns, for a B = SIMPLIFY(A) performs model-
state-space model SYS, the state trajectory reduction-like techniques to detect and
X, a LT-by-NX-by-NU array if SYS has eliminate redundant copies of uncertain
NX states. elements. Depending on the result, the
o POLY: Convert roots to polynomial. CLASS of B may be lower than A. The
POLY(A), when A is an N by N matrix, is a AutoSimplify property of each uncertain
row vector with N+1 elements which are element in A determines what reduction
methods are used. After reduction, any
the coefficients of the characteristic
uncertain element which does not actually
polynomial, DET(lambda*EYE(SIZE(A)) -
affect the result is deleted from the
A) .
representation.
o RESIDUE: Partial-fraction expansion
(residues). [R,P,K] = RESIDUE(B,A) finds
the residues, poles and direct term of a o TF2SS: Transfer function to state-space
partial fraction expansion of the ratio of two conversion.
polynomials B(s)/A(s). If there are no [A,B,C,D] = TF2SS(NUM,DEN) calculates
multiple roots, the state-space representation of the system:
x = Ax + B
B(s) R(1) R(2) R(n)
---- = -------- + -------- + ... + -------- + K(s)
y = Cx + Du
A(s) s - P(1) s - P(2) s - P(n) o Time limit is selected using t=[ lower
limit : interval : upper limit]. For example, t
Vectors B and A specify the coefficients of the =
numerator and denominator polynomials in descending [ 0:0.1:20]
powers of s. The residues are returned in the column
vector R, the pole locations in column vector P, and the
direct terms in row vector K. The number of poles is n
= length(A)-1 = length(R) = length(P). The direct term
coefficient vector is empty if length(B) < length(A),
otherwise length(K) = length(B)-length(A)+1.
2|P a g e
2
1.6
MATLAB CODE:
1.4
Segment 1: 1.2
wheel velocity
1
clc; 0.8
numc=[1 1]; 0
0 0.5 1 1.5 2 2.5 3
[num,den]=series(numg,deng,numc,denc); Segment 3:
printsys(num,den)
[num_c, den_c]= cloop(num,den,-1); numy=32;
printsys(num_c,den_c) deny=poly([0 -4 -8]);
[r,p,k]=residue(numy,deny)
Segment 4:
Segment 2:
numf=150*[1 2 7];
num=[5400]; denf=[1 5.4 0];
den=[2 2.5 5402]; F=tf(numf,denf)
t=[0:0.005:3];
[y,x,t]=step(num,den,t);
figure(1)
plot(t,y), grid
xlabel('time [sec]')
ylabel('wheel velocity')
Segment 5:
numg=[-2 -4];
deng=[-7 -8 -9];
k=20;
G=zpk(numg,deng,k)
3|P a g e
Segment 6: Segment 8:
Segment 9:
syms s
A=[0 1 0;0 0 1; -1 -2 -3];
B=[10;0;0];
C=[1 0 0];
D=0;
I=[1 0 0;0 1 0;0 0 1];
Y=C*((s*I-A)^-1)*B+D;
4|P a g e
zeta3=1; REFERENCES
den3=[1 2*zeta3 1];
zeta4=0; [1] Norman S. Nise, “Control Systems Engineering”,
den4=[1 2*zeta4 1]; available Edition, John Wiley & Sons Inc.
zeta5=2; [2] https://www.mathworks.com/campaigns/products/trials
den5=[1 2*zeta5 1]; .html
[y1,x,t]=step(num,den1,t);
[y2,x,t]=step(num,den2,t);
[y3,x,t]=step(num,den3,t);
[y4,x,t]=step(num,den4,t);
[y5,x,t]=step(num,den5,t);
figure(2)
plot(t,y1,t,y2,t,y3,t,y4,t,y5)
xlabel('Wnt')
ylabel('y(t)')
title('step response of 2nd order systems for
variousvalues of zeta'),grid
1.8
1.6
1.4
1.2
y(t)
0.8
0.6
0.4
0.2
0
0 2 4 6 8 10 12 14 16 18 20
Wnt
V. DISCUSSION
VI. CONCLUSION
5|P a g e
6|P a g e
F
cc