|
From: <kk...@us...> - 2011-02-08 22:11:28
|
Revision: 37
http://python-control.svn.sourceforge.net/python-control/?rev=37&view=rev
Author: kkchen
Date: 2011-02-08 22:11:21 +0000 (Tue, 08 Feb 2011)
Log Message:
-----------
Added shell interface for gram along with tests.
Steven Brunton <sbr...@pr...>
Modified Paths:
--------------
branches/control-0.4a/src/TestStatefbk.py
branches/control-0.4a/src/statefbk.py
Modified: branches/control-0.4a/src/TestStatefbk.py
===================================================================
--- branches/control-0.4a/src/TestStatefbk.py 2011-02-08 22:03:57 UTC (rev 36)
+++ branches/control-0.4a/src/TestStatefbk.py 2011-02-08 22:11:21 UTC (rev 37)
@@ -1,6 +1,7 @@
#!/usr/bin/env python
-from statefbk import ctrb, obsv, place, lqr
+from statefbk import ctrb, obsv, place, lqr, gram
+from matlab import *
import numpy as N
import unittest
@@ -42,5 +43,27 @@
Wo = N.transpose(obsv(A,C));
N.testing.assert_array_almost_equal(Wc,Wo)
+ def testGramWc(self):
+ A = N.matrix("1. -2.; 3. -4.")
+ B = N.matrix("5. 6.; 7. 8.")
+ C = N.matrix("4. 5.; 6. 7.")
+ D = N.matrix("13. 14.; 15. 16.")
+ # sys = ss(A, B, C, D)
+ sys = 1.
+ Wctrue = N.matrix("18.5 24.5; 24.5 32.5")
+ Wc = gram(sys,'c')
+ N.testing.assert_array_almost_equal(Wc, Wctrue)
+
+ def testGramWo(self):
+ A = N.matrix("1. -2.; 3. -4.")
+ B = N.matrix("5. 6.; 7. 8.")
+ C = N.matrix("4. 5.; 6. 7.")
+ D = N.matrix("13. 14.; 15. 16.")
+ sys = ss(A, B, C, D)
+ sys = 1.
+ Wotrue = N.matrix("257.5 -94.5; -94.5 56.5")
+ Wo = gram(sys,'o')
+ 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 22:03:57 UTC (rev 36)
+++ branches/control-0.4a/src/statefbk.py 2011-02-08 22:11:21 UTC (rev 37)
@@ -190,7 +190,7 @@
Usage
=====
- Wc = ctrb(A, B)
+ C = ctrb(A, B)
Inputs
------
@@ -198,7 +198,7 @@
Outputs
-------
- Wc: Controllability matrix
+ C: Controllability matrix
"""
# Convert input parameters to matrices (if they aren't already)
@@ -216,7 +216,7 @@
Usage
=====
- Wc = obsv(A, C)
+ O = obsv(A, C)
Inputs
------
@@ -224,7 +224,7 @@
Outputs
-------
- Wc: Observability matrix
+ O: Observability matrix
"""
# Convert input parameters to matrices (if they aren't already)
@@ -237,3 +237,22 @@
for i in range(1, n):
obsv = np.vstack((obsv, cmat*amat**i))
return obsv
+
+def gram(sys,type):
+ """Gramian
+
+ Usage
+ =====
+ Wc = gram(sys,'c')
+ Wo = gram(sys,'o')
+ """
+
+ if type=='c':
+ print "controllable"
+ elif type=='o':
+ print "observable"
+ else:
+ raise ValueError, "Oops, neither observable, nor controllable!"
+
+ gram = 0.
+ return gram
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|