Tartalomjegyzék

CCS 2017 fall. Homework 2. Solutions

Teljes Matlab script kiegészítő függvényekkel.

file:   ccs2017_hf2_mo.m
author: Peter Polcz <ppolcz@gmail.com>
Created on 2017. October 04.
Reviewed on 2017. October 30.
Output:
┌d2017_10_26_hf2_mo
│   - Persistence for `d2017_10_26_hf2_mo` initialized [run ID: 48, 298]Persistence for `2018.01.13. Saturday, 13:03:16` 
│   - Script `d2017_10_26_hf2_mo` backuped

Acetone - human body

A = [
    -6 0 0
    4 0 0
    2 0 0
    ];
B = [ 1 ; 0 ; 0 ];
C = [ 0 0 1 ];

On = obsv(A,C)
Cn = ctrb(A,B)

rank(On)
rank(Cn)

orth(sym(Cn))
null(sym(On))

Hs = minreal(tf(ss(A,B,C,0)))

syms s t
clear H
H(s) = simplify(C/(s*eye(3) - A)*B)

h(t) = ilaplace(H)

disp 'NEM BIBO STABIL'
Output:
On =
     0     0     1
     2     0     0
   -12     0     0
Cn =
     1    -6    36
     0     4   -24
     0     2   -12
ans =
     2
ans =
     2
ans =
[ 1,             0]
[ 0, (2*5^(1/2))/5]
[ 0,     5^(1/2)/5]
ans =
 0
 1
 0

Hs =
 
      2
  ---------
  s^2 + 6 s
 
Continuous-time transfer function.

H(s) =
2/(s*(s + 6))
h(t) =
1/3 - exp(-6*t)/3
NEM BIBO STABIL

Kalman decomposition

Generate a decomposable system

a = 4;
b = 2;
c = 1;
d = 2;
n = a+b+c+d;
r = 2;
m = 2;

A_ = [
    randn(a,a) zeros(a,b) randn(a,c) zeros(a,d)
    randn(b,a) randn(b,b) randn(b,c) randn(b,d)
    zeros(c,a) zeros(c,b) randn(c,c) zeros(c,d)
    zeros(d,a) zeros(d,b) randn(d,c) randn(d,d)
    ];
B_ = [
    randn(a,r)
    randn(b,r)
    zeros(c,r)
    zeros(d,r)
    ];
C_ = [
    randn(m,a) zeros(m,b) randn(m,c) zeros(m,d)
    ];

D = zeros(m,r);

System $(\bar A, \bar B, \bar C, D)$ is in Kalman decomposed form. The transfer function is reducible to an $a$th order system.

sys = ss(A_,B_,C_,D)
H = minreal(tf(sys))
Output:
sys =
 
  A = 
             x1        x2        x3        x4        x5        x6        x7
   x1      -0.5   -0.3638    -1.853    0.4772         0         0   -0.2682
   x2     0.383   -0.5993   -0.2073  -0.07132         0         0   -0.4099
   x3     0.412   -0.5896    0.2704   -0.9383         0         0   -0.7113
   x4    0.4055    0.8535   -0.6528    0.1614         0         0   0.06145
   x5    -1.846   -0.5435    0.6527    0.5406   -0.1569    0.6395    0.5409
   x6   -0.3983   -0.9119   -0.7343    0.9758    0.2778  -0.08098    -1.263
   x7         0         0         0         0         0         0  -0.06273
   x8         0         0         0         0         0         0    0.4489
   x9         0         0         0         0         0         0   -0.3633
 
             x8        x9
   x1         0         0
   x2         0         0
   x3         0         0
   x4         0         0
   x5      1.11    -1.829
   x6   -0.9896     1.384
   x7         0         0
   x8    -1.021    0.6263
   x9    -3.073   -0.2867
 
  B = 
            u1       u2
   x1  -0.1973    1.147
   x2   0.4056   0.5979
   x3   -1.419   -1.281
   x4  -0.7294   -2.203
   x5  -0.5712   0.9424
   x6    0.214  0.09373
   x7        0        0
   x8        0        0
   x9        0        0
 
  C = 
            x1       x2       x3       x4       x5       x6       x7
   y1   -1.122   -1.172  -0.6537   -0.271        0        0  -0.2857
   y2   0.3062   -0.961   -1.229     -0.9        0        0  -0.4624
 
            x8       x9
   y1        0        0
   y2        0        0
 
  D = 
       u1  u2
   y1   0   0
   y2   0   0
 
Continuous-time state-space model.


H =
 
  From input 1 to output...
          0.8715 s^3 - 2.235 s^2 - 2.445 s - 0.7107
   1:  ------------------------------------------------
       s^4 + 0.6675 s^3 - 0.09586 s^2 - 1.903 s - 1.054
 
           1.951 s^3 + 1.016 s^2 - 2.159 s - 2.372
   2:  ------------------------------------------------
       s^4 + 0.6675 s^3 - 0.09586 s^2 - 1.903 s - 1.054
 
  From input 2 to output...
          -0.5539 s^3 - 3.155 s^2 + 3.137 s + 2.491
   1:  ------------------------------------------------
       s^4 + 0.6675 s^3 - 0.09586 s^2 - 1.903 s - 1.054
 
            3.335 s^3 - 1.67 s^2 - 1.875 s - 1.398
   2:  ------------------------------------------------
       s^4 + 0.6675 s^3 - 0.09586 s^2 - 1.903 s - 1.054
 
Continuous-time transfer function.

Transform the system with a random transformation matrix $T$.

T = orth(rand(n));
A = T * A_ * T';
B = T * B_;
C = C_ * T';

sys = ss(A,B,C,D)
Output:
sys =
 
  A = 
             x1        x2        x3        x4        x5        x6        x7
   x1    0.1523   0.07296    0.8678   -0.3707    0.2523    -0.518    0.5848
   x2    0.3413    0.8853   -0.8989    0.1422     -1.69    0.8681    0.4118
   x3    0.2634    0.3483    -1.119    0.2306    -1.091    0.1815   -0.2937
   x4    0.1155    0.5602    0.1735   -0.5832   -0.4761    0.4898    0.7877
   x5    -1.053   -0.2574    0.9874  -0.09348   0.07746   0.08012    0.5716
   x6    0.2275   -0.6336   -0.8442    0.4762   -0.7057    -1.208   -0.8068
   x7    0.7752    0.3596   -0.3789    0.2503    0.6879    0.8246    0.3214
   x8    0.5532   -0.2555   0.01882   -0.2103   -0.2524   -0.7211  -0.08064
   x9   -0.1514    0.1736   -0.5998    0.3085    0.8506   0.04315  -0.07161
 
             x8        x9
   x1   0.02367    -1.849
   x2     1.723     1.083
   x3    0.7351    0.2875
   x4    0.3789   -0.4384
   x5    0.2275    -1.161
   x6    0.1819   -0.6308
   x7    -1.018   0.05423
   x8   -0.6721    -1.149
   x9    0.6585   -0.1295
 
  B = 
              u1         u2
   x1     0.1494    0.05899
   x2    -0.9896    -0.4994
   x3     0.9774     0.9403
   x4    0.05994     0.3105
   x5   0.009022     -1.288
   x6    -0.4181     -2.362
   x7    -0.3026    -0.1257
   x8  -0.004789     -0.583
   x9     0.9461     0.4928
 
  C = 
            x1       x2       x3       x4       x5       x6       x7
   y1   0.9191    0.526   0.6654    -0.22   0.5975   0.3651   0.2066
   y2   0.6904  -0.2248   0.6685   -0.585  -0.1442   -0.644  -0.2197
 
            x8       x9
   y1  -0.5576   0.8717
   y2    -1.12   0.7055
 
  D = 
       u1  u2
   y1   0   0
   y2   0   0
 
Continuous-time state-space model.

Kalman decomposition. Solution

1. Controllability staircase form

Controllability matrix

Cn = ctrb(A,B);

Transformation matrix, which generates the controllability staircase form.

[S1,~,~] = svd(Cn)
Output:
S1 =
  Columns 1 through 7
   -0.0759   -0.2202    0.4133   -0.2260    0.0725    0.6622    0.4495
    0.4337   -0.5940    0.2774    0.5186   -0.0206    0.0617   -0.1963
    0.0328   -0.4306   -0.0202   -0.5254    0.3013    0.0160   -0.3446
    0.1421   -0.2723    0.2780   -0.2200   -0.0827   -0.7021    0.3071
   -0.0531   -0.3240   -0.4401    0.0650   -0.4255    0.0054    0.5690
   -0.6285   -0.3313   -0.0392    0.1628   -0.4033    0.0488   -0.3884
    0.3349    0.2984    0.3699   -0.1747   -0.6980    0.1058   -0.1965
   -0.4503   -0.0393    0.4265   -0.2285   -0.0863   -0.1883    0.0287
    0.2686   -0.1836   -0.4008   -0.4920   -0.2415    0.1244   -0.1796
  Columns 8 through 9
    0.1648   -0.2255
    0.0687    0.2562
   -0.5689   -0.0599
    0.1983   -0.3829
   -0.3921    0.1891
    0.1274   -0.3675
   -0.2981   -0.0742
    0.0556    0.7175
    0.5858    0.2054

The transformation.

A1 = S1' * A * S1
B1 = S1' * B
C1 = C * S1
Output:
A1 =
  Columns 1 through 7
   -0.3758   -1.3003    0.2588   -0.0226   -1.9448    0.3209   -1.1615
    0.6108   -0.7322   -2.0218   -0.2346   -0.2869    0.5046    0.8206
    0.2514   -0.0094    1.0078    0.3701    0.1244    1.1864   -0.0936
    0.0036   -0.0081    0.0294   -0.7449    0.0456   -0.1792   -0.8446
    0.0035    0.0038    0.0375   -0.4177    0.2705    0.0903   -0.5997
   -0.0012   -0.0071    0.0020    0.0287    0.2539   -0.3307    0.7136
   -0.0000    0.0000    0.0000   -0.0000   -0.0000   -0.0000   -0.8524
    0.0000   -0.0000   -0.0000   -0.0000   -0.0000    0.0000    0.5913
   -0.0000    0.0000    0.0000   -0.0000   -0.0000    0.0000   -0.0035
  Columns 8 through 9
    1.1065    0.5074
   -0.9251   -1.1537
    0.0658   -0.6349
    0.8888    0.3264
    0.7149    0.7026
   -0.7189   -0.0519
   -3.1149   -0.2029
   -0.4484    0.5200
    0.0270   -0.0691
B1 =
    0.0173    1.7592
   -0.0104    0.8888
   -0.6966    0.1198
   -1.5527   -1.3901
    0.4687    1.7916
    0.0776   -0.1590
   -0.0000    0.0000
   -0.0000    0.0000
    0.0000    0.0000
C1 =
  Columns 1 through 7
    0.4422   -1.1326   -0.3368   -0.4755   -0.4336    1.0625   -0.0019
    0.8216   -0.0381   -0.7061   -0.6622    0.7052    1.1080   -0.0031
  Columns 8 through 9
   -0.0043   -0.2856
   -0.0069   -0.4624

Order of the controllable subsystem

ab = rank(Cn);

2. Observability staircase form

2.1. Observability staircase form of the controllable subsystem

On1 = obsv(A1(1:ab,1:ab), C1(:,1:ab));
[~,~,S21] = svd(On1);

2.2. Observability staircase form of the uncontrollable subsystem

On2 = obsv(A1(ab+1:end,ab+1:end), C1(:,ab+1:end));
[~,~,S22] = svd(On2);

Second transformation matrix to generate the observability staircase form for both controllable and uncontrollable subsystems.

S2 = blkdiag(S21, S22)
Output:
S2 =
  Columns 1 through 7
   -0.4025   -0.1444   -0.0507   -0.1532    0.2151    0.8630         0
   -0.1443    0.5225   -0.5641    0.1384   -0.5864    0.1577         0
    0.0286    0.7106    0.6273   -0.2931   -0.0141    0.1206         0
    0.0412    0.3005    0.0363    0.8331    0.4483    0.1078         0
   -0.4247    0.3014   -0.3921   -0.3304    0.5722   -0.3720         0
   -0.7964   -0.1414    0.3614    0.2612   -0.2849   -0.2565         0
         0         0         0         0         0         0    0.0068
         0         0         0         0         0         0    0.0150
         0         0         0         0         0         0    0.9999
  Columns 8 through 9
         0         0
         0         0
         0         0
         0         0
         0         0
         0         0
    0.2847   -0.9586
   -0.9585   -0.2846
    0.0124    0.0108

Transformation

A2 = round(S2' * A1 * S2,10)
B2 = round(S2' * B1,10)
C2 = round(C1 * S2,10)
Output:
A2 =
  Columns 1 through 7
   -0.3635    0.6634   -0.4115    0.0095         0         0   -0.2995
   -1.1918   -0.5717    0.1350    0.0071         0         0   -0.8101
   -0.2913    1.7231    0.8327   -0.0280         0         0   -0.0556
    0.2876   -0.4196   -0.7617   -0.5650         0         0   -0.0251
    0.3772    0.8820    0.7062   -0.6568   -0.4383   -0.1505    1.3733
    0.6322   -1.2302    1.6455    0.6576   -0.5123    0.2004   -0.0274
         0         0         0         0         0         0   -0.0627
         0         0         0         0         0         0   -0.5693
         0         0         0         0         0         0    0.0968
  Columns 8 through 9
         0         0
         0         0
         0         0
         0         0
   -2.1720    1.0910
   -1.0634    0.6595
         0         0
    0.2004    0.8999
   -2.7993   -1.5076
B2 =
   -0.3503   -1.5246
   -0.8393    0.4402
   -0.6440   -1.3258
   -1.2281   -1.9733
   -0.4304    0.3029
   -0.4323    0.8973
         0         0
         0         0
         0         0
C2 =
  Columns 1 through 7
   -0.7058   -1.3188    0.9420   -0.1011         0         0   -0.2857
   -1.5546   -0.7834   -0.3633   -0.4195         0         0   -0.4624
  Columns 8 through 9
         0         0
         0         0

Kalman decomposition using minreal

Using minreal the transfer function which generates the Kalman decomposition can be retained easily, however, this does not work all the times. The uncontrollable subsystem is not always decomposed (since the uncontrollable subsystem is already redundant).

[H,U] = minreal(sys);

A1 = round(U*A/U,10)
B1 = round(U*B,10)
C1 = round(C/U,10)
Output:
5 states removed.
A1 =
  Columns 1 through 7
   -0.5797   -0.0258   -0.0677   -0.9946         0         0   -0.8293
    1.3511    0.6350   -0.7757   -0.9852         0         0   -0.1198
   -0.8743   -0.4973   -0.4451    0.0742         0         0   -0.2124
    0.7987   -0.1555    0.5721   -0.2778         0         0    0.0491
   -0.5541    0.3275   -1.7662    1.1994    0.3043   -0.3617   -0.2997
    0.7199    1.1548   -0.1361    0.2474         0   -0.5421    1.3404
         0         0         0         0         0         0   -0.0627
         0         0         0         0         0         0   -0.5425
         0         0         0         0         0         0    0.1978
  Columns 8 through 9
         0         0
         0         0
         0         0
         0         0
   -0.5232    0.5326
   -2.0853    1.6024
         0         0
   -0.1919    0.6588
   -3.0405   -1.1153
B1 =
   -1.3211   -0.9515
    0.3303    0.4931
    0.9422    1.9779
   -0.0899   -1.7633
   -0.3382    0.8192
   -0.5077    0.4752
         0         0
         0         0
         0         0
C1 =
  Columns 1 through 7
   -1.2889    0.5519   -1.0801   -0.0477         0         0   -0.2857
   -1.4193   -0.0907    0.0032   -1.1471         0         0   -0.4624
  Columns 8 through 9
         0         0
         0         0

End of the script.

Output:
└ 1.228 [sec]