Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Numerical improvements in statefbk.py
* `numpy.linalg.solve` instead of matrix inversion.
* Better controllability matrix rank check.
  • Loading branch information
mp4096 committed Nov 20, 2016
commit 29e7f950d9979ae87def54f4feb0920584ffa952
7 changes: 4 additions & 3 deletions control/statefbk.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def acker(A, B, poles):

# Make sure the system is controllable
ct = ctrb(A, B)
if sp.linalg.det(ct) == 0:
if np.linalg.matrix_rank(ct) != a.shape[0]:
raise ValueError("System not reachable; pole placement invalid")

# Compute the desired characteristic polynomial
Expand All @@ -138,7 +138,7 @@ def acker(A, B, poles):
pmat = p[n-1]*a**0
for i in np.arange(1,n):
pmat = pmat + p[n-i-1]*a**i
K = sp.linalg.inv(ct) * pmat
K = np.linalg.solve(ct, pmat)

K = K[-1][:] # Extract the last row
return K
Expand Down Expand Up @@ -242,7 +242,8 @@ def lqr(*args, **keywords):
X,rcond,w,S,U,A_inv = sb02md(nstates, A_b, G, Q_b, 'C')

# Now compute the return value
K = np.dot(np.linalg.inv(R), (np.dot(B.T, X) + N.T));
# We assume that R is positive definite and, hence, invertible
K = np.linalg.solve(R, np.dot(B.T, X) + N.T);
S = X;
E = w[0:nstates];

Expand Down