Skip to content

Commit ace1683

Browse files
billtubbsmurrayrm
authored andcommitted
Change to code for ctrb and obsv (#300)
More pythonic implementation with small speedup.
1 parent c0092e0 commit ace1683

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

control/statefbk.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ def lqr(*args, **keywords):
368368

369369
return K, S, E
370370

371-
def ctrb(A,B):
371+
def ctrb(A, B):
372372
"""Controllabilty matrix
373373
374374
Parameters
@@ -391,10 +391,9 @@ def ctrb(A,B):
391391
amat = np.mat(A)
392392
bmat = np.mat(B)
393393
n = np.shape(amat)[0]
394+
394395
# Construct the controllability matrix
395-
ctrb = bmat
396-
for i in range(1, n):
397-
ctrb = np.hstack((ctrb, amat**i*bmat))
396+
ctrb = np.hstack([bmat] + [amat**i*bmat for i in range(1, n)])
398397
return ctrb
399398

400399
def obsv(A, C):
@@ -421,10 +420,8 @@ def obsv(A, C):
421420
cmat = np.mat(C)
422421
n = np.shape(amat)[0]
423422

424-
# Construct the controllability matrix
425-
obsv = cmat
426-
for i in range(1, n):
427-
obsv = np.vstack((obsv, cmat*amat**i))
423+
# Construct the observability matrix
424+
obsv = np.vstack([cmat] + [cmat*amat**i for i in range(1, n)])
428425
return obsv
429426

430427
def gram(sys,type):

0 commit comments

Comments
 (0)