echo on % Define a discrete system F = rand(6) F = 0.9501 0.4565 0.9218 0.4103 0.1389 0.0153 0.2311 0.0185 0.7382 0.8936 0.2028 0.7468 0.6068 0.8214 0.1763 0.0579 0.1987 0.4451 0.4860 0.4447 0.4057 0.3529 0.6038 0.9318 0.8913 0.6154 0.9355 0.8132 0.2722 0.4660 0.7621 0.7919 0.9169 0.0099 0.1988 0.4186 g = rand(6,1) g = 0.8462 0.5252 0.2026 0.6721 0.8381 0.0196 h = rand(1,6) h = 0.6813 0.3795 0.8318 0.5028 0.7095 0.4289 i = rand(1,1) i = 0.3046 % Compute the controllability matrix Qc = [ g , F*g , F*F*g , F^3*g , F^4*g , F^5*g ] Qc = 0.8462 1.6230 4.0813 11.6081 33.8766 98.8313 0.5252 1.1402 4.0908 12.1168 35.3956 103.2825 0.2026 1.1948 3.2614 9.7209 28.3315 82.7317 0.6721 1.4885 4.8748 14.2531 41.5536 121.3218 0.8381 2.0508 5.7001 16.7048 48.7672 142.3057 0.0196 1.4281 4.2556 12.3033 35.9678 104.9889 % Compute the inverse Qcin = inv(Qc) Qcin = -5.0333 -5.5489 -6.2157 3.6667 8.3243 -0.4253 -2.1197 -4.1007 -1.1671 -0.0470 5.0250 0.1924 9.4163 4.3044 1.8403 0.5851 -13.1805 2.6405 120.5959 120.3248 135.6179 -59.9760 -181.2921 -23.7236 101.9773 122.2189 95.7908 -81.0404 -137.4378 -11.7768 -49.4202 -56.0887 -48.7668 34.7680 68.7937 6.7146 % Extract the last row q = Qcin(6,:) q = -49.4202 -56.0887 -48.7668 34.7680 68.7937 6.7146 % Build the transformation matrix T = [ q ; q*F ; q*F*F ; q*F^3 ; q*F^4 ; q*F^5 ] T = -49.4202 -56.0887 -48.7668 34.7680 68.7937 6.7146 -6.1840 -0.5371 -10.9405 -4.9470 13.1246 2.9189 -1.1208 -3.6305 4.9214 5.3051 -1.9762 -2.6369 -0.1103 2.5185 -4.9599 -3.1803 2.2272 2.3807 -0.2786 -2.2360 3.8594 2.6306 -1.3310 -1.2574 0.6943 2.3565 -2.5580 -2.0555 1.2509 1.3483 % Perform the similarity transformation Fh = T*F/T Fh = -0.0000 1.0000 0.0000 0.0000 0.0000 -0.0000 -0.0000 0.0000 1.0000 -0.0000 0.0000 0.0000 0.0000 -0.0000 -0.0000 1.0000 -0.0000 -0.0000 -0.0000 0.0000 0.0000 0.0000 1.0000 -0.0000 -0.0000 0.0000 0.0000 -0.0000 -0.0000 1.0000 0.0194 -0.1207 -0.0754 -0.1308 2.1890 2.1886 gh = T*g gh = 0.0000 0.0000 0.0000 -0.0000 0.0000 1.0000 hh = h/T hh = 0.0164 -0.0391 -0.2037 -0.4661 1.2219 1.8854 ih = i ih = 0.3046 % Using the controls toolbox, these tasks can be performed more easily S = ss(F,g,h,i) a = x1 x2 x3 x4 x5 x1 0.95013 0.45647 0.92181 0.41027 0.13889 x2 0.23114 0.01850 0.73821 0.89365 0.20277 x3 0.60684 0.82141 0.17627 0.05789 0.19872 x4 0.48598 0.44470 0.40571 0.35287 0.60379 x5 0.89130 0.61543 0.93547 0.81317 0.27219 x6 0.76210 0.79194 0.91690 0.00986 0.19881 x6 x1 0.01527 x2 0.74679 x3 0.44510 x4 0.93181 x5 0.46599 x6 0.41865 b = u1 x1 0.84622 x2 0.52515 x3 0.20265 x4 0.67214 x5 0.83812 x6 0.01964 c = x1 x2 x3 x4 x5 y1 0.68128 0.37948 0.83180 0.50281 0.70947 x6 y1 0.42889 d = u1 y1 0.30462 Continuous-time system. % By default, the controls toolbox assumes the system to be continuous. % Let us assume, it is! G = tf(S) Transfer function: 0.3046 s^6 + 1.219 s^5 + 0.5551 s^4 - 0.4263 s^3 - 0.1808 s^2 - 0.00231 s + 0.01045 --------------------------------------------------------------------------- s^6 - 2.189 s^5 - 2.189 s^4 + 0.1308 s^3 + 0.07541 s^2 + 0.1207 s - 0.01942 % If we want to convert to a discrete system, we can do this as follows: % By default, C2D assumes a ZOH at every input. % Let us assume, T = 0.1 sec. Sd = c2d(S,0.1) a = x1 x2 x3 x4 x5 x1 1.10547 0.05379 0.10157 0.04714 0.01773 x2 0.03338 1.01175 0.08285 0.09319 0.02525 x3 0.06857 0.08750 1.02745 0.01211 0.02251 x4 0.06091 0.05457 0.05379 1.04219 0.06482 x5 0.10324 0.07306 0.10720 0.08953 1.03319 x6 0.08703 0.08788 0.10280 0.00779 0.02323 x6 x1 0.00830 x2 0.08329 x3 0.05027 x4 0.10162 x5 0.05742 x6 1.04904 b = u1 x1 0.09347 x2 0.05895 x3 0.02683 x4 0.07553 x5 0.09509 x6 0.00987 c = x1 x2 x3 x4 x5 y1 0.68128 0.37948 0.83180 0.50281 0.70947 x6 y1 0.42889 d = u1 y1 0.30462 Sampling time: 0.1 Discrete-time system. Gd = tf(Sd) Transfer function: 0.3046 z^6 - 1.692 z^5 + 3.895 z^4 - 4.755 z^3 + 3.245 z^2 - 1.172 z + 0.1748 --------------------------------------------------------------------------- z^6 - 6.269 z^5 + 16.32 z^4 - 22.59 z^3 + 17.54 z^2 - 7.248 z + 1.245 Sampling time: 0.1 diary off