MATLAB For Modern Control Systems
MATLAB For Modern Control Systems
Num = [1 11 30];
Den = [1 9 45 87 50];
[z, p, k] = tf2zp(Num, Den)
zp2tf finds the num, and den of zero, pole, and gain.
[num, den] = zp2tf(z, p, k)
Then print the system of num and den in ‘s’ polynomials using.
Parallel configuration: If the two blocks are connected as shown below then the blocks are said
to be in parallel. It would like adding two transfer functions.
Feedback configuration: If the blocks are connected as shown below then the blocks are said to
be in feedback. Notice that in the feedback there is no transfer function H(s) defined. When not
specified, H(s) is unity. Such a system is said to be a unity feedback system.
When H(s) is non-unity or specified, such a system is said to be a non-unity feedback system as
shown below:
Poles and Zeros of System: To obtain the poles and zeros of the system use the MATLAB
command “pole” and “zero”, respectively. You can also use MATLAB command “pzmap” to
obtain the same as follows.
z = zero(sys) %system zeros
p = pole(sys) %system poles
[p, z] = pzmap(sys) %pole and zero in column vector
pzmap(sys) %pole-zero maps in figure
State-Space Representation
Ẋ = AX + BU
Y = CX + DU
sys = ss(A, B, C, D) %ss is state-space
num = [0 0 1 0];
den = [1 14 56 160];
[A, B, C, D] = tf2ss(num, den) % transfer function (TF) to state space (SS), or
[A,B,C,D] = tf2ss(num,den)
A=
-14 -56 -160
1 0 0
0 1 0
B=
1
0
0
C=
0 1 0
D=
0
[num, den] = ss2tf(A, B, C, D) % TF to SS
A = [0 1 0;0 0 1;-5.008 -25.1026 -5.03247];
B = [0;25.04;-121.005];
C = [1 0 0];
D = [0];
[num,den] = ss2tf(A,B,C,D)
num =
0 0 25.0400 5.0080
den =
1.0000 5.0325 25.1026 5.0080
For MIMO system:
[num, den] = ss2tf(A, B, C, D, iu) % where iu is input number.
For first input iu = 1 = U1
For second input iu = 2 = U2
For third input iu = 3 = U3
A = [0 1 0;0 0 1;-9 -8 -7];
B = [7; 8; 9];
C = [2 3 4];
D = 0;
[num, den] = ss2tf(A, B, C, D, 1)
Tss = ss(A, B, C, D) %Form state-space model
Ttf = tf(Tss) %Transform from state-space to transfer function in polynomial form
--------------
s^2 + 4 s + 25
Chapter – 2
A = [0 -2;1 -3];
dt = 0.2;
phi = expm(A*dt) % finding state transition matrix for a moment (dt = 0.2)
phi =
0.9671 -0.2968
0.1484 0.5219
Example
1st method to obtain Responses
clear;
clc;
clf;
t = linspace(0,20);
A = [0 1;-2 -3];
B = [0;1];
C = [1 -1];
D = [0];
sys = ss(A,B,C,D); % for one input (u(t) = u1(t))
u = t; % ramp input u1(t) = t
x0 = [1;2]; %initial condition x(0)
XZIR = initial(sys,x0,t); % Zero Input Response for X(t)
XZSR = lsim(sys,u,t); % Zero State Response for X(t)
XTOTAL = XZIR+XZSR; % Total Response of X(t)
Y = C.*XTOTAL; % Output or System Response Y(t)
plot(t,u,'B',t,XZIR,'G',t,XZSR,'Y',t,XTOTAL,'R',t,Y,'R--
','LineWidth',1); % Plot all the responses
xlabel('Time(s)'); %
ylabel('Responses');
legend('U(t)','XZIR(t)','XZSR(t)','X(t)','Y(t)'); % Giving
legend based on their respective.
clear;
clc;
clf;
t = linspace(0,10);
A = [0 1;-2 -3];
B = [0;1];
C = [1 -1];
D = [0];
sys = ss(A,B,C,D); % for one input (u(t) = u1(t))
u = t; % ramp input u1(t) = t
x0 = [1;2]; %initial condition x(0)
[y,T,x] = lsim(sys,u,t,x0); % for calculating output and
state response
subplot(321),plot(t,u); % Plot U(t)
xlabel('Time(s)'),ylabel('U(t)');
subplot(322),plot(T,x(:,1)); % Plot X_1(t) of X(t)
xlabel('Time(s)'),ylabel('X_1(t)');
subplot(323),plot(T,x(:,2)); % Plot X_2(t) of X(t)
xlabel('Time(s)'),ylabel('X_2(t)');
subplot(324),plot(T,x(:,:)); % Plot X(t)
xlabel('Time(s)'),ylabel('X(t)');
subplot(325),plot(T,y); % Plot Y(t)
xlabel('Time(s)'),ylabel('Y(t)');
Y = C.*x; % for checking y(t)
subplot(326),plot(t,Y); % Plot Y(t)
xlabel('Time(s)'),ylabel('Y(t)');
Chapter – 3
Examples
clc; % clear command window
clear; % Clear workspace
clf; % clear figure
A = [0 1;-2 -3];
B = [0;1];
Qc = ctrb(A,B);
n = det(Qc);
if abs(n) < eps
disp('The system is not completely controllable.')
else
disp('The system is completely controllable.')
end
B = [0;1;0;0];
Qc = ctrb(A,B);
n = det(Qc);
if abs(n) < eps
disp('Satellite is uncontrollable with radial thruster
only.')
else
disp('Satellite is controllable with radial thruster
only.')
end
Chapter – 4
State-feedback design (Pole-placement design)
Examples
A = [0 1;0 0];
B = [0;1];
J = [-1+j -1-j];
K = acker(A,B,J)
K =
2 2
Full-order Observer design
Examples
A = [0 1;20.6 0];
C = [1 0];
J = [-8 -8];
Ke = acker(A',C',J)
Ke =
16.0000 84.6000
A = [0 20.6;1 0];
C = [0 1];
J = [-10 -10];
Ke = acker(A',C',J)
Ke =
120.6000 20.0000
Examples