|
7 | 7 | from .statefbk import ctrb, obsv |
8 | 8 |
|
9 | 9 | from numpy import zeros, shape, poly |
10 | | -from numpy.linalg import inv |
| 10 | +from numpy.linalg import solve |
11 | 11 |
|
12 | 12 | __all__ = ['canonical_form', 'reachable_form', 'observable_form'] |
13 | 13 |
|
@@ -68,23 +68,23 @@ def reachable_form(xsys): |
68 | 68 |
|
69 | 69 | # Generate the system matrices for the desired canonical form |
70 | 70 | zsys.B = zeros(shape(xsys.B)) |
71 | | - zsys.B[0, 0] = 1 |
| 71 | + zsys.B[0, 0] = 1.0 |
72 | 72 | zsys.A = zeros(shape(xsys.A)) |
73 | 73 | Apoly = poly(xsys.A) # characteristic polynomial |
74 | 74 | for i in range(0, xsys.states): |
75 | 75 | zsys.A[0, i] = -Apoly[i+1] / Apoly[0] |
76 | 76 | if (i+1 < xsys.states): |
77 | | - zsys.A[i+1, i] = 1 |
| 77 | + zsys.A[i+1, i] = 1.0 |
78 | 78 |
|
79 | 79 | # Compute the reachability matrices for each set of states |
80 | 80 | Wrx = ctrb(xsys.A, xsys.B) |
81 | 81 | Wrz = ctrb(zsys.A, zsys.B) |
82 | 82 |
|
83 | 83 | # Transformation from one form to another |
84 | | - Tzx = Wrz * inv(Wrx) |
| 84 | + Tzx = solve(Wrx.T, Wrz.T).T # matrix right division, Tzx = Wrz * inv(Wrx) |
85 | 85 |
|
86 | 86 | # Finally, compute the output matrix |
87 | | - zsys.C = xsys.C * inv(Tzx) |
| 87 | + zsys.C = solve(Tzx.T, xsys.C.T).T # matrix right division, zsys.C = xsys.C * inv(Tzx) |
88 | 88 |
|
89 | 89 | return zsys, Tzx |
90 | 90 |
|
|
0 commit comments