A = [-0.4628, 0.3217, 0.5789, -0.3823, -0.0507;
0.7593, 1.0396, -0.2008, -0.2438, -0.0678;
0.2106, 0.6490, 0.3973, 0.8735, 0.2070;
0.3128, 0.3380, 0.1524, 0.0914, -0.1088;
0.0353, 0.0419, -0.0355, 0.0682, 0.7576];
C = [1.1099, 1.3983, 0.8999, -0.0136, 0.0652];
sys = ss(A, B, C, D, dt,'InputName','u','OutputName',{'y'});
Q = [1 0 0 0 0 0;0 2 0 0 0 0;0 0 5 4 0 0;0 0 0 5 0 0; 0 1 0 0 5 1;0 0 0 0 0 1];
Q1 = (Q+Q')/2
Q1 =
1.0000 0 0 0 0 0
0 2.0000 0 0 0.5000 0
0 0 5.0000 2.0000 0 0
0 0 2.0000 5.0000 0 0
0 0.5000 0 0 5.0000 0.5000
0 0 0 0 0.5000 1.0000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
A = rand(n_states+1, n_states+1);
A_symmetric = tril(A) + triu(A', 1);
Q2 = A_symmetric
Q2 =
0.6629 0.6854 0.6830 0.7862 0.5655 0.1663
0.6854 0.7813 0.6157 0.7265 0.0305 0.1561
0.6830 0.6157 0.6874 0.8049 0.1267 0.4960
0.7862 0.7265 0.8049 0.8787 0.5216 0.8728
0.5655 0.0305 0.1267 0.5216 0.7036 0.1557
0.1663 0.1561 0.4960 0.8728 0.1557 0.8840
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
QXU = blkdiag(0.1*eye(n_states),sqrt(Q))
QXU =
0.1000 0 0 0 0 0 0 0 0 0 0
0 0.1000 0 0 0 0 0 0 0 0 0
0 0 0.1000 0 0 0 0 0 0 0 0
0 0 0 0.1000 0 0 0 0 0 0 0
0 0 0 0 0.1000 0 0 0 0 0 0
0 0 0 0 0 1.0000 0 0 0 0 0
0 0 0 0 0 0 1.4142 0 0 0 0
0 0 0 0 0 0 0 2.2361 2.0000 0 0
0 0 0 0 0 0 0 0 2.2361 0 0
0 0 0 0 0 0 1.0000 0 0 2.2361 1.0000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
QWV = blkdiag(Q,0.01)
QWV =
1.0000 0 0 0 0 0 0
0 2.0000 0 0 0 0 0
0 0 5.0000 4.0000 0 0 0
0 0 0 5.0000 0 0 0
0 1.0000 0 0 5.0000 1.0000 0
0 0 0 0 0 1.0000 0
0 0 0 0 0 0 0.0100
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
KLQG1 = lqg(sys,Q1,Q,QI,'1dof')
Warning: QN is not symmetric and was replaced by (QN+QN')/2.
KLQG1 =
A =
x1_e x2_e x3_e x4_e x5_e xi1
x1_e -0.6969 0.02017 0.394 -0.3729 -0.06068 0.002294
x2_e 0.2617 0.3901 -0.5879 -0.2157 -0.08427 0.007763
x3_e -0.3262 -0.01802 -0.04461 0.8711 0.1702 -0.003176
x4_e -0.0487 -0.243 -0.04954 0.2184 -0.05898 0.04323
x5_e 0.2911 0.734 -0.09655 -0.2959 0.5634 -0.1273
xi1 0 0 0 0 0 1
B =
e1
x1_e -0.2057
x2_e -0.4308
x3_e -0.4908
x4_e -0.2278
x5_e -0.0579
xi1 0.02
C =
x1_e x2_e x3_e x4_e x5_e xi1
u -2.218 -5.357 0.06196 2.529 1.32 0.8822
D =
e1
u 0
Input groups:
Name Channels
Error 1
Output groups:
Name Channels
Controls 1
Sample time: 0.02 seconds
Discrete-time state-space model.
KLQG2 = lqg(sys,Q1,Q,QI,'2dof')
Warning: QN is not symmetric and was replaced by (QN+QN')/2.
KLQG2 =
A =
x1_e x2_e x3_e x4_e x5_e xi1
x1_e -0.6969 0.02017 0.394 -0.3729 -0.06068 0.002294
x2_e 0.2617 0.3901 -0.5879 -0.2157 -0.08427 0.007763
x3_e -0.3262 -0.01802 -0.04461 0.8711 0.1702 -0.003176
x4_e -0.0487 -0.243 -0.04954 0.2184 -0.05898 0.04323
x5_e 0.2911 0.734 -0.09655 -0.2959 0.5634 -0.1273
xi1 0 0 0 0 0 1
B =
r1 y
x1_e 0 0.2057
x2_e 0 0.4308
x3_e 0 0.4908
x4_e 0 0.2278
x5_e 0 0.0579
xi1 0.02 -0.02
C =
x1_e x2_e x3_e x4_e x5_e xi1
u -2.218 -5.357 0.06196 2.529 1.32 0.8822
D =
r1 y
u 0 0
Input groups:
Name Channels
Setpoint 1
Measurement 2
Output groups:
Name Channels
Controls 1
Sample time: 0.02 seconds
Discrete-time state-space model.
title('1DOF Servo Controller designed')
title('2DOF Servo Controller designed')
Sum_Error = sumblk('e = r - y');
clsys = tf(connect(C,P,Sum_Error,'r','y'))
clsys =
From input "r" to output "y":
0.003938 z^9 + 0.00479 z^8 - 0.01414 z^7 - 0.04427 z^6 + 0.1179 z^5 - 0.08028 z^4 - 0.003101 z^3 + 0.01298 z^2 + 0.007207 z - 0.004974
----------------------------------------------------------------------------------------------------------------------------------------------------
z^11 - 3.254 z^10 + 3.293 z^9 - 0.3241 z^8 - 1.017 z^7 - 0.02715 z^6 + 0.4166 z^5 - 0.0324 z^4 - 0.05791 z^3 - 0.002832 z^2 + 0.005646 z - 4.509e-05
Sample time: 0.02 seconds
Discrete-time transfer function.
clsys_m = minreal(clsys)
clsys_m =
From input "r" to output "y":
0.003938 z^9 + 0.00479 z^8 - 0.01414 z^7 - 0.04427 z^6 + 0.1179 z^5 - 0.08028 z^4 - 0.003101 z^3 + 0.01298 z^2 + 0.007207 z - 0.004974
----------------------------------------------------------------------------------------------------------------------------------------------------
z^11 - 3.254 z^10 + 3.293 z^9 - 0.3241 z^8 - 1.017 z^7 - 0.02715 z^6 + 0.4166 z^5 - 0.0324 z^4 - 0.05791 z^3 - 0.002832 z^2 + 0.005646 z - 4.509e-05
Sample time: 0.02 seconds
Discrete-time transfer function.
title('Constructed closed loop system response')