Skip to content

Commit b9e4455

Browse files
committed
Replaced inv with solve in canonical forms class
Also made unity elements of the A, B matrices float -- just in case.
1 parent af36e84 commit b9e4455

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

control/canonical.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from .statefbk import ctrb, obsv
88

99
from numpy import zeros, shape, poly
10-
from numpy.linalg import inv
10+
from numpy.linalg import solve
1111

1212
__all__ = ['canonical_form', 'reachable_form', 'observable_form']
1313

@@ -68,23 +68,23 @@ def reachable_form(xsys):
6868

6969
# Generate the system matrices for the desired canonical form
7070
zsys.B = zeros(shape(xsys.B))
71-
zsys.B[0, 0] = 1
71+
zsys.B[0, 0] = 1.0
7272
zsys.A = zeros(shape(xsys.A))
7373
Apoly = poly(xsys.A) # characteristic polynomial
7474
for i in range(0, xsys.states):
7575
zsys.A[0, i] = -Apoly[i+1] / Apoly[0]
7676
if (i+1 < xsys.states):
77-
zsys.A[i+1, i] = 1
77+
zsys.A[i+1, i] = 1.0
7878

7979
# Compute the reachability matrices for each set of states
8080
Wrx = ctrb(xsys.A, xsys.B)
8181
Wrz = ctrb(zsys.A, zsys.B)
8282

8383
# 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)
8585

8686
# 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)
8888

8989
return zsys, Tzx
9090

0 commit comments

Comments
 (0)