|
From: <kk...@us...> - 2011-02-08 20:57:58
|
Revision: 35
http://python-control.svn.sourceforge.net/python-control/?rev=35&view=rev
Author: kkchen
Date: 2011-02-08 20:57:52 +0000 (Tue, 08 Feb 2011)
Log Message:
-----------
Added TestStatefbk.py, which currently tests obsv and ctrb. Also, obsv and ctrb had their algorithms backwards, so I fixed this.
Modified Paths:
--------------
branches/control-0.4a/src/statefbk.py
Added Paths:
-----------
branches/control-0.4a/src/TestStatefbk.py
Added: branches/control-0.4a/src/TestStatefbk.py
===================================================================
--- branches/control-0.4a/src/TestStatefbk.py (rev 0)
+++ branches/control-0.4a/src/TestStatefbk.py 2011-02-08 20:57:52 UTC (rev 35)
@@ -0,0 +1,37 @@
+#!/usr/bin/env python
+
+from statefbk import ctrb, obsv, place, lqr
+import numpy as N
+import unittest
+
+class TestStatefbk(unittest.TestCase):
+ def testCtrbSISO(self):
+ A = N.matrix("1. 2.; 3. 4.")
+ B = N.matrix("5.; 7.")
+ Wctrue = N.matrix("5. 19.; 7. 43.")
+ Wc = ctrb(A,B)
+ N.testing.assert_array_almost_equal(Wc, Wctrue)
+
+ def testCtrbMIMO(self):
+ A = N.matrix("1. 2.; 3. 4.")
+ B = N.matrix("5. 6.; 7. 8.")
+ Wctrue = N.matrix("5. 6. 19. 22.; 7. 8. 43. 50.")
+ Wc = ctrb(A,B)
+ N.testing.assert_array_almost_equal(Wc, Wctrue)
+
+ def testObsvSISO(self):
+ A = N.matrix("1. 2.; 3. 4.")
+ C = N.matrix("5. 7.")
+ Wotrue = N.matrix("5. 7.; 26. 38.")
+ Wo = obsv(A,C)
+ N.testing.assert_array_almost_equal(Wo, Wotrue)
+
+ def testObsvMIMO(self):
+ A = N.matrix("1. 2.; 3. 4.")
+ C = N.matrix("5. 6.; 7. 8.")
+ Wotrue = N.matrix("5. 6.; 7. 8.; 23. 34.; 31. 46.")
+ Wo = obsv(A,C)
+ N.testing.assert_array_almost_equal(Wo, Wotrue)
+
+if __name__ == '__main__':
+ unittest.main()
Modified: branches/control-0.4a/src/statefbk.py
===================================================================
--- branches/control-0.4a/src/statefbk.py 2011-02-08 18:04:02 UTC (rev 34)
+++ branches/control-0.4a/src/statefbk.py 2011-02-08 20:57:52 UTC (rev 35)
@@ -205,11 +205,10 @@
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.vstack((ctrb, amat**i*bmat))
+ ctrb = np.hstack((ctrb, amat**i*bmat))
return ctrb
def obsv(A, C):
@@ -236,5 +235,5 @@
# Construct the controllability matrix
obsv = cmat
for i in range(1, n):
- obsv = np.hstack((obsv, cmat*amat**i))
+ obsv = np.vstack((obsv, cmat*amat**i))
return obsv
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|