From 083ed75378a3823e4693e47efefe99d9125ed6dc Mon Sep 17 00:00:00 2001 From: Bill Tubbs Date: Sat, 18 May 2019 15:47:41 -0700 Subject: [PATCH 1/2] Change to code for ctrb and obsv --- control/statefbk.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/control/statefbk.py b/control/statefbk.py index 0fb377a47..fda34cbe5 100644 --- a/control/statefbk.py +++ b/control/statefbk.py @@ -368,7 +368,7 @@ def lqr(*args, **keywords): return K, S, E -def ctrb(A,B): +def ctrb(A, B): """Controllabilty matrix Parameters @@ -391,10 +391,9 @@ def ctrb(A,B): amat = np.mat(A) bmat = np.mat(B) n = np.shape(amat)[0] + # Construct the controllability matrix - ctrb = bmat - for i in range(1, n): - ctrb = np.hstack((ctrb, amat**i*bmat)) + ctrb = np.hstack([bmat] + [amat**i*bmat for i in range(1, n)]) return ctrb def obsv(A, C): @@ -421,10 +420,8 @@ def obsv(A, C): cmat = np.mat(C) n = np.shape(amat)[0] - # Construct the controllability matrix - obsv = cmat - for i in range(1, n): - obsv = np.vstack((obsv, cmat*amat**i)) + # Construct the observability matrix + obsv = np.hstack([cmat] + [cmat*amat**i for i in range(1, n)]) return obsv def gram(sys,type): From 9309259f4824f2126629b168521b41c1afa84915 Mon Sep 17 00:00:00 2001 From: Bill Tubbs Date: Sat, 18 May 2019 16:41:49 -0700 Subject: [PATCH 2/2] Bug fix to osbv --- control/statefbk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/control/statefbk.py b/control/statefbk.py index fda34cbe5..d6eef0e45 100644 --- a/control/statefbk.py +++ b/control/statefbk.py @@ -421,7 +421,7 @@ def obsv(A, C): n = np.shape(amat)[0] # Construct the observability matrix - obsv = np.hstack([cmat] + [cmat*amat**i for i in range(1, n)]) + obsv = np.vstack([cmat] + [cmat*amat**i for i in range(1, n)]) return obsv def gram(sys,type):