You are on page 1of 18

Question No 1

clear
A=[-0.8 0.02;-0.02 0];
B=[0.05 1; 0.001 0];
C=[1 0;0 1];
D=0;
Qc=ctrb(A,B) %Judging system controllability

Qc =
0.0500 1.0000 -0.0400 -0.8000
0.0010 0 -0.0010 -0.0200

if rank(Qc)==size(A)
disp('System is controlable');
else
disp('System is not controlable');
end

System is controlable

p=[-8 -7];
if rank(A)==size(A)
disp('Reasonable number of poles and system configuration');
else
disp(' Pole number and system configuration unreasonable ');
end

Reasonable number of poles and system configuration

K=place(A,B,p)

K =
1.0e+03 *
-0.0200 7.0000
0.0082 -0.3500

A1=A-B*K;
B1=B;
C1=C;
ROOTSnew=eig(A1)

ROOTSnew =
-8.0000
-7.0000

ROOTSold=eig(A)

ROOTSold =
-0.7995
-0.0005





Question No 2

a.

A=[0 1 0 0 0;-0.1 -0.5 0 0 0;0.5 0 0 0 0;0 0 10 0 0;0.5 1 0 0 0];
B=[0;1;0;0;0];
C=[0 0 0 1 0];
Qc=ctrb(A,B)

Qc =
0 1.0000 -0.5000 0.1500 -0.0250
1.0000 -0.5000 0.1500 -0.0250 -0.0025
0 0 0.5000 -0.2500 0.0750
0 0 0 5.0000 -2.5000
0 1.0000 0 -0.1000 0.0500
if rank(Qc)==5
disp('System is controlable');
else
disp('System is not controlable')
end

System is not controlable

b.

I=eye(5);
syms s;
E=s*I-A;
F=collect(inv(E));
G=C*F*B

G =
50/(10*s^4 + 5*s^3 + s^2)
num=[50];
den=[10 5 1 0 0];
Gf=tf(num,den)


Gf =

50
--------------------
10 s^4 + 5 s^3 + s^2

Continuous-time transfer function.

sys=ss(Gf)


sys =

a =
x1 x2 x3 x4
x1 -0.5 -0.4 0 0
x2 0.25 0 0 0
x3 0 0.125 0 0
x4 0 0 0.25 0

b =
u1
x1 32
x2 0
x3 0
x4 0

c =
x1 x2 x3 x4
y1 0 0 0 20

d =
u1
y1 0

Continuous-time state-space model.


c.

A1=[-0.5 -0.4 0 0;0.25 0 0 0;0 0.125 0 0;0 0 0.25 0];
B1=[32;0;0;0];
C1=[0 0 0 20];
Qc1=ctrb(A1,B1)

Qc1 =
32.0000 -16.0000 4.8000 -0.8000
0 8.0000 -4.0000 1.2000
0 0 1.0000 -0.5000
0 0 0 0.2500
if rank(Qc1)==size(A1)
disp('System is controlable');
else
disp('System is not controlable');
end

System is controlable


d.

G1=C*inv(s*eye(size(A))-A)*B

G1 =
50/(s^2*(10*s^2 + 5*s + 1))
sys=tf(50,[10, 5, 1, 0, 0])


sys =

50
--------------------
10 s^4 + 5 s^3 + s^2

Continuous-time transfer function.
t=[0:0.1:100];
y=step(sys,t);
plot(t,y)





e.

Question No 3
a.
A=[-0.0366 0.0271 0.0188 -0.4555;0.0482 -1.0100 0.0024 -4.0208;0.1002
0.3681 -0.707 1.42;0 0 1 0];
d=eig(A)

d =
0.2758 + 0.2576i
0.2758 - 0.2576i
-0.2325 + 0.0000i
-2.0727 + 0.0000i
b.
Q=poly(A)

Q =
1.0000 1.7536 -0.6472 0.0625 0.0686
Q1=localpoly(Q)
0 10 20 30 40 50 60 70 80 90 100
0
0.5
1
1.5
2
2.5
x 10
5

Q1 =
X1^4 + 1.75*X1^3 - 0.647*X1^2 + 0.0625*X1 + 0.0686
c.
B1=[0.4422;3.5446;-5.52;0];
B2=[0.1761;-7.5922;4.49;0];
Qc1=ctrb(A,B1);


dimA=size(A)

dimA =
4 4

if rank(Qc1)==size(A)
disp(' Only when U1 has role in controllability of the system ');
else
disp(' Only when U1has no role in controllability of the system ');
end

Only when U1 has role in controllability of the system

Qc2=ctrb(A,B2);


if rank(Qc2)==size(A)
disp(' Only when U2 has role in controllability of the system ');
else
disp(' Only when U2 has no role in controllability of the system ');
end

Only when U2 has role in controllability of the system


Question 4
A=[0 0 0 1 0 0; 0 0 0 0 1 0; 0 0 0 0 0 1; 7.3809 0 0 0 2 0; 0 -2.1904 0
-2 0 0;0 0 -3.1904 0 0 0];
num=1;
den=poly(A)
sys=tf(num,den);
pzmap(sys)
roots1=eig(A)
B1=[0;0;0;1;0;0];
Qc1=ctrb(A,B1);
dimA=size(A)
if rank(Qc1)==size(A)
disp(' Only when U1 has role in controllability of the system ')
else
disp(' Only when U1 has no role in controllability of the system ')
end
B2=[0;0;0;0;1;0];
Qc2=ctrb(A,B2);
if rank(Qc2)==size(A)
disp(' Only when U2 has role in controllability of the system ')
else
disp(' Only when U2 has no role in controllability of the system ')
end
B3=[0;0;0;0;0;1];
Qc3=ctrb(A,B3);
if rank(Qc3)==size(A)
disp(' Only when U3 has role in controllability of the system ')
else
disp(' Only when U3 has no role in controllability of the system ')
end

den =
1.0000 0.0000 1.9999 0.0000 -19.9653 0.0000 -51.5796
roots1 =
-2.1587 + 0.0000i
2.1587 + 0.0000i
0.0000 + 1.8626i
0.0000 - 1.8626i
0.0000 + 1.7862i
0.0000 - 1.7862i
dimA =
6 6
Only when U1 has no role in controllability of the system
Only when U2 has no role in controllability of the system
Only when U3 has no role in controllability of the system

C=[0 1 0 0 0 0];
syms s
I=eye(6);
E=s*I-A;
F=collect(inv(E));
G=C*F*B2

G =
(6250000*s^2 - 46130625)/(6250000*s^4 - 7440625*s^2 - 101044521)
num=[-6250000 0 46130625];
den=[-6250000 0 7440625 0 101044521];
-2.5 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2 2.5
-2
-1.5
-1
-0.5
0
0.5
1
1.5
2
Pole-Zero Map
Real Axis (seconds
-1
)
I
m
a
g
i n
a
r
y

A
x
i s

(
s
e
c
o
n
d
s
-
1
)
Gf=tf(num,den)
sys_ss=ss(Gf)


Gf =

6.25e06 s^2 - 4.613e07
------------------------------------
6.25e06 s^4 - 7.441e06 s^2 - 1.01e08

Continuous-time transfer function.


sys_ss =

a =
x1 x2 x3 x4
x1 0 0.5952 0 2.021
x2 2 0 0 0
x3 0 2 0 0
x4 0 0 2 0

b =
u1
x1 1
x2 0
x3 0
x4 0

c =
x1 x2 x3 x4
y1 0 0.5 0 -0.9226

d =
u1
y1 0

Continuous-time state-space model.
A1=[0 0.5952 0 2.021;2 0 0 0;0 2 0 0;0 0 2 0];
B1=[1;0;0;0];
Qc=ctrb(A1,B1)
if rank(Qc)==size(A)
disp(' Subsystem is controlable ')
else
disp(' Subsystem is not controlable ')
end

Qc =
1.0000 0 1.1904 0
0 2.0000 0 2.3808
0 0 4.0000 0
0 0 0 8.0000
Subsystem is not controlable
%sys s
num=[-6250000 0 46130625];
den=[-6250000 0 7440625 0 101044521];
[A1 B1 C1 D1]=tf2ss(num,den);
P=[-1+i -1-i -10 -10];
if rank(A1)==4
disp(' ')
else
disp()
end
K=acker(A1,B1,P)
AGK=A1;
BGK=B1;
CGK=K;
DGK=0;
subplot(2,1,1);
rlocus(AGK,BGK,CGK,DGK)% Join root locus of the feedback system
grid
title(' Joint Root Locus Of The Feedback System ')
At=A1-B1*K;
Bt=B1;
Ct=C1;
Dt=D1;
[zI,pI,gainI]=ss2zp(At,Bt,Ct,Dt)
dcg=dcgain(At,Bt,Ct,Dt);
t=0:0.1:10;
yc=step(At,Bt,Ct,Dt,1,t);
yc1=yc/dcg;
subplot(2,1,2);
plot(t,yc1)
grid
title(' After adding a feedback system step response');


K =
22.0000 143.1905 240.0000 216.1671
zI =
2.7168
-2.7168
pI =
-10.0000 + 0.0000i
-10.0000 - 0.0000i
-1.0000 + 1.0000i
-1.0000 - 1.0000i
gainI =
1

help simulink

Simulink
Version 8.1 (R2013a) 13-Feb-2013

Model analysis and construction functions.

Simulation
sim - Simulate a Simulink model.
sldebug - Debug a Simulink model.
simset - Define options to SIM Options structure.
simget - Get SIM Options structure.

Linearization and trimming.
linmod - Extract linear model from continuous-time
system.
linmod2 - Extract linear model, advanced method.
dlinmod - Extract linear model from discrete-time system.
trim - Find steady-state operating point.

Model Construction.
close_system - Close open model or block.
new_system - Create new empty model window.
open_system - Open existing model or block.
load_system - Load existing model without making model
visible.
save_system - Save an open model.
add_block - Add new block.
add_line - Add new line.
delete_block - Remove block.
delete_line - Remove line.
find_system - Search a model.
hilite_system - Hilite objects within a model.
replace_block - Replace existing blocks with a new block.
-20 -15 -10 -5 0 5
-10
-5
0
5
10
0.96
0.99
0.2 0.4 0.58 0.72 0.83
0.91
0.96
0.99
2.5 5 7.5 10 12.5 15 17.5 20
0.2 0.4 0.58 0.72 0.83
0.91
Joint Root Locus Of The Feedback System
Real Axis (seconds
-1
)
I
m
a
g
i n
a
r
y

A
x
i s

(
s
e
c
o
n
d
s
-
1
)
0 1 2 3 4 5 6 7 8 9 10
-0.5
0
0.5
1
1.5
After adding a feedback system step response
set_param - Set parameter values for model or block.
get_param - Get simulation parameter values from model.
add_param - Add a user-defined string parameter to a model.
delete_param - Delete a user-defined parameter from a model.
bdclose - Close a Simulink window.
bdroot - Root level model name.
gcb - Get the name of the current block.
gcbh - Get the handle of the current block.
gcs - Get the name of the current system.
getfullname - get the full path name of a block
slupdate - Update older models to the current release.
addterms - Add terminators to unconnected ports.
boolean - Convert numeric array to boolean.
slhelp - Simulink user's guide or block help.

Masking.
hasmask - Check for mask.
hasmaskdlg - Check for mask dialog.
hasmaskicon - Check for mask icon.
iconedit - Design block icons using ginput function.
maskpopups - Return and change masked block's popup menu
items.
movemask - Restructure masked built-in blocks as masked
subsystems.

Library.
libinfo - Get library information for a system.

Diagnostics.
sllastdiagnostic - Last diagnostic array.
sllasterror - Last error array.
sllastwarning - Last warning array.
sldiagnostics - Get block count and compile stats for a model.

Hardcopy and printing.
frameedit - Edit print frames for annotated model printouts.
print - Print graph or Simulink system; or save graph to
MATLAB file.
printopt - Printer defaults.
orient - Set paper orientation.

See also BLOCKS and SIMDEMOS.




Contents of simulink:

tamslgate - Gateway routine to call T&M SL private
functions for creating widgets

Reference page in Help browser
doc simulink
A=[-0.8468 -8.1598e-008 0.5071;867637000 0 -867637000;1.1636e+004
0.0019 -1.1636e+004];
B=[-0.0262;0;0];
C=[0 0 1];
D=0;
Qc=ctrb(A,B)
if rank(Qc)==size(A)
disp(' System is controlable ')
else
disp(' System is not controlable ')
end
pe=[-2.2986e+004 -300 -0.0286e+004];
w=[0.01 10];
t=0:0.05:10;
K=place(A,B,pe)
bode(A,B,K,0);
title('State Feedback System After Adding Bode Plot ')
grid
[gm pm wpc wgc]=margin(A,B,K,0);
figure;
rlocus(A,B,K,0);
grid
title('After Adding The Root Locus State Feedback System')
At=A-B*K;
Bt=B;
Ct=C;
Dt=D;
[zI PI gain]=ss2zp(At,Bt,Ct,Dt);
dcg=dcgain(At,Bt,Ct,Dt);
figure
yc=step(At,Bt,Ct,Dt,1,t);
yc=yc/dcg;
plot(t,yc);
title('After Adding The State Feedback System Step Response ')
grid

Qc =
1.0e+11 *
-0.0000 0.0000 -0.0000
0 -0.0002 2.6453
0 -0.0000 0.0000
System is controlable
K =
1.0e+05 *
-4.5554 0.0000 4.0989


A=[-0.8468 -8.1598e-008 0.5071;867637000 0 -867637000;1.1636e+004
0.0019 -1.1636e+004];
B=[-0.0262;0;0];
Q=diag([4e+004 0 1e+004]);
R=1;
K=lqr(A,B,Q,R)
bode(A,B,K,0)
title('State Feedback System After Adding Bode Plot')
[gm pm wpc wgc]=margin(A,B,K,0);
figure;
rlocus(A,B,K,0);
title('After Adding The Root Locus State Feedback System')
grid
At=A-B*K;
Bt=B;
Ct=C;
Dt=D;
[zI PI gain]=ss2zp(At,Bt,Ct,Dt);
dcg=dcgain(At,Bt,Ct,Dt);
figure
yc=step(At,Bt,Ct,Dt,1,t);
yc=yc/dcg;
plot(t,yc);
title('After Adding The State Feedback System Step Response ')
grid

K =
-211.0180 -0.0000 0.0013
0 1 2 3 4 5 6 7 8 9 10
0
0.2
0.4
0.6
0.8
1
1.2
1.4
After Adding The State Feedback System Step Response

A=[-0.8468 -8.1598e-008 0.5071;867637000 0 -867637000;1.1636e+004
0.0019 -1.1636e+004];
B=[-0.0262;0;0];
Q=diag([4e+004 0 1e+004]);
R=1;
K=lqr(A,B,Q,R)
bode(A,B,K,0)
title('State Feedback System After Adding Bode Plot')

K =
-211.0180 -0.0000 0.0013

0 1 2 3 4 5 6 7 8 9 10
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
After Adding The State Feedback System Step Response
-100
-50
0
50
M
a
g
n
i t
u
d
e

(
d
B
)
10
-2
10
-1
10
0
10
1
10
2
10
3
10
4
10
5
-135
-90
-45
0
P
h
a
s
e

(
d
e
g
)
State Feedback SystemAfter Adding Bode Plot
Frequency (rad/s)
A=[-0.8468 -8.1598e-008 0.5071;867637000 0 -867637000;1.1636e+004
0.0019 -1.1636e+004];
B=[-0.0262;0;0];
Q=diag([4e+004 0 1e+004]);
R=1;
K=lqr(A,B,Q,R)
bode(A,B,K,0)
title('State Feedback System After Adding Bode Plot')
[gm pm wpc wgc]=margin(A,B,K,0);
figure;
rlocus(A,B,K,0);
title('After Adding The Root Locus State Feedback System')
grid

K =
-211.0180 -0.0000 0.0013


A=[-0.8468 -8.1598e-008 0.5071;867637000 0 -867637000;1.1636e+004
0.0019 -1.1636e+004];
B=[-0.0262;0;0];
C=[0 0 1];
D=0;
w=[0.01 10];
t=0:0.05:10;
p=[-4e+004 0 -1e+004];
op=[-20 -30];
x0=[1 2 3];
xh0=[-1 -2 -3];
k=place(A,B,p);
T=[0 1 0;1 0 0];
e=[C;T];
ei=inv(e);
[mm nn]=size(C);
p=ei(:,1:mm);m=ei(:,mm+1:nn);
-2.5 -2 -1.5 -1 -0.5 0 0.5
x 10
4
-1500
-1000
-500
0
500
1000
1500
0.999
1
1
0.86 0.965 0.986 0.993 0.996 0.998
0.999
1
1
5e+03 1e+04 1.5e+04 2e+04 2.5e+04
0.86 0.965 0.986 0.993 0.996 0.998
After Adding The Root Locus State Feedback System
Real Axis (seconds
-1
)
I
m
a
g
i n
a
r
y

A
x
i s

(
s
e
c
o
n
d
s
-
1
)
a11=C*A*p;
a12=C*A*m;
a21=T*A*p;
a22=T*A*m;
b1=C*B;
b2=T*B;
Lr=place(a22',a12',op);Lr=Lr';
f=a22-Lr*a12;
g=b2-Lr*b1;
d=f*Lr+(a21-Lr*a11);
n=p+m*Lr;
Ak=f-g*k*m;
Bk=d-g*k*n;
Ck=k*m;
Dk=k*n;
[zk pk gk]=ss2zp(Ak,Bk,Ck,Dk,1);
zk,pk,gk
[Ac Bc Cc Dc]=series(A,B,C,D,Ak,Bk,Ck,Dk);
rlocus(Ac,Bc,Cc,Dc);
title(' Dimensionality reduction state observer system root locus ')
grid
axis([-6 1 -6 6]);
figure
[mc pc]=bode(Ac,Bc,Cc,Dc,1,w)
bode(Ac,Bc,Cc,Dc);
title(' Bode diagram of the system ')
grid
[gm pm wpc wgc]=margin(mc,pc,w)
[At,Bt,Ct,Dt]=feedback(A,B,C,D,Ak,Bk,Ck,Dk);
[zt pt gaint]=ss2zp(At,Bt,Ct,Dt,1);
dcg=dcgain(At,Bt,Ct,Dt)
ycc=lsim(At,Bt,Ct,Dt,ones(201,1),t,[x0 xh0(1:2)]);
ycc=ycc/dcg;
[zt pt gt]=ss2zp(At,Bt,Ct,Dt,1);
zt,pt
Ct=[eye(nn) zeros(nn,nn-mm);n*C m];
Dt=zeros(2*nn,1);t2=[0:0.02:2]';
w0=T*xho'-Lr*C*x0';
w0=w0';
x_xh=initial(At,Bt,Ct,Dt,[x0 w0],t2);
figure
plot(t2,[x_xh(:,1) x_xh(:,4)]);grid
title(' Observing the actual state of x1 * x1 and response curve ');
figure;
plot(t2,[x_xh(:,2) x_xh(:,5)]);grid
title(' Observing the actual state of x2*x2 and response curve ');
figure;
plot(t2,[x_xh(:,3) x_xh(:,6)]);grid
title(' Observing the actual state of x3*x3 and response curve ');

zk =
1.0e+03 *
-9.9435
-0.0003
pk =
1.0e+04 *
-0.9367
-2.9046
gk =
1.0439e+06
mc =
1.0000
0.9995
pc =
179.9991
179.9755
gm =
1.0000
pm =
Inf
wpc =
0.0077
wgc =
NaN
dcg =
-4.8027e+09
zt =
1.0e+04 *
-2.9046
-0.9367
-0.0142
pt =
1.0e+04 *
-4.0000
-1.0000
0.0000
-0.0020
-0.0030


[Ac Bc Cc Dc]=series(A,B,C,D,Ak,Bk,Ck,Dk);
rlocus(Ac,Bc,Cc,Dc);
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
0
500
1000
1500
2000
2500
3000
3500
4000
Observing the actual state of x3*x3 and response curve
title(' Dimensionality reduction state observer system root locus ')
grid


bode(Ac,Bc,Cc,Dc);
title(' Bode diagram of the system ')
grid


x_xh=initial(At,Bt,Ct,Dt,[x0 w0],t2);
figure
plot(t2,[x_xh(:,1) x_xh(:,4)]);grid
title(' Observing the actual state of x1 * x1 and response curve ');
figure
-5 -4 -3 -2 -1 0 1 2
x 10
4
-4000
-3000
-2000
-1000
0
1000
2000
3000
4000
0.998
0.999
1
1
0.85 0.95 0.98 0.991 0.996
0.998
0.999
1
1
1e+04 2e+04 3e+04 4e+04 5e+04
0.85 0.95 0.98 0.991 0.996
Dimensionality reduction state observer systemroot locus
Real Axis (seconds
-1
)
I
m
a
g
i n
a
r
y

A
x
i s

(
s
e
c
o
n
d
s
-
1
)
-80
-60
-40
-20
0
20
M
a
g
n
i t
u
d
e

(
d
B
)
10
-1
10
0
10
1
10
2
10
3
10
4
10
5
10
6
0
45
90
135
180
P
h
a
s
e

(
d
e
g
)
Bode diagramof the system
Frequency (rad/s)


plot(t2,[x_xh(:,1) x_xh(:,4)]);grid
title(' Observing the actual state of x1 * x1 and response curve ');
figure

You might also like