From: <kk...@us...> - 2011-02-08 22:13:42
|
Revision: 47 http://python-control.svn.sourceforge.net/python-control/?rev=47&view=rev Author: kkchen Date: 2011-02-08 22:13:36 +0000 (Tue, 08 Feb 2011) Log Message: ----------- Added initial unittests for modred and balred to TestModelsimp.py and debugged hsvd. Lauren Padilla <lpa...@pr...> Modified Paths: -------------- branches/control-0.4a/src/TestModelsimp.py branches/control-0.4a/src/modelsimp.py Modified: branches/control-0.4a/src/TestModelsimp.py =================================================================== --- branches/control-0.4a/src/TestModelsimp.py 2011-02-08 22:13:30 UTC (rev 46) +++ branches/control-0.4a/src/TestModelsimp.py 2011-02-08 22:13:36 UTC (rev 47) @@ -24,5 +24,93 @@ Htrue = np.matrix("1.; 0.; 0.") np.testing.assert_array_almost_equal( H, Htrue ) + def testModredMatchDC(self): + #balanced realization computed in matlab for the transfer function: + # num = [1 11 45 32], den = [1 15 60 200 60] + A = np.matrix('-1.958, -1.194, 1.824, -1.464; \ + -1.194, -0.8344, 2.563, -1.351; \ + -1.824, -2.563, -1.124, 2.704; \ + -1.464, -1.351, -2.704, -11.08') + B = np.matrix('-0.9057; -0.4068; -0.3263; -0.3474') + C = np.matrix('-0.9057, -0.4068, 0.3263, -0.3474') + D = np.matrix('0.') + sys = ss(A,B,C,D) + rsys = modred(sys,np.matrix('3, 4'),'matchdc') + Artrue = np.matrix('-4.431, -4.552; -4.552, -5.361') + Brtrue = np.matrix('-1.362; -1.031') + Crtrue = np.matrix('-1.362, -1.031') + Drtrue = np.matrix('-0.08384') + np.testing.assert_array_almost_equal(sys.A, Artrue) + np.testing.assert_array_almost_equal(sys.B, Brtrue) + np.testing.assert_array_almost_equal(sys.C, Crtrue) + np.testing.assert_array_almost_equal(sys.D, Drtrue) + + def testModredTruncate(self): + #balanced realization computed in matlab for the transfer function: + # num = [1 11 45 32], den = [1 15 60 200 60] + A = np.matrix('-1.958, -1.194, 1.824, -1.464; \ + -1.194, -0.8344, 2.563, -1.351; \ + -1.824, -2.563, -1.124, 2.704; \ + -1.464, -1.351, -2.704, -11.08') + B = np.matrix('-0.9057; -0.4068; -0.3263; -0.3474') + C = np.matrix('-0.9057, -0.4068, 0.3263, -0.3474') + D = np.matrix('0.') + sys = ss(A,B,C,D) + rsys = modred(sys,np.matrix('3, 4'),'truncate') + Artrue = np.matrix('-1.958, -1.194; -1.194, -0.8344') + Brtrue = np.matrix('-0.9057, -0.4068') + Crtrue = np.matrix('-0.9057, -0.4068') + Drtrue = np.matrix('0.') + np.testing.assert_array_almost_equal(sys.A, Artrue) + np.testing.assert_array_almost_equal(sys.B, Brtrue) + np.testing.assert_array_almost_equal(sys.C, Crtrue) + np.testing.assert_array_almost_equal(sys.D, Drtrue) + + def testBalredMatchDC(self): + #controlable canonical realization computed in matlab for the transfer function: + # num = [1 11 45 32], den = [1 15 60 200 60] + A = np.matrix('-15., -7.5, -6.25, -1.875; \ + 8., 0., 0., 0.; \ + 0., 4., 0., 0.; \ + 0., 0., 1., 0.') + B = np.matrix('2.; 0.; 0.; 0.') + C = np.matrix('0.5, 0.6875, 0.7031, 0.5') + D = np.matrix('0.') + sys = ss(A,B,C,D) + orders = 1 + rsys = balred(sys,orders,'elimination','matchdc') + Artrue = np.matrix('-0.566') + Brtrue = np.matrix('-0.414') + Crtrue = np.matrix('-0.5728') + Drtrue = np.matrix('0.1145') + np.testing.assert_array_almost_equal(sys.A, Artrue) + np.testing.assert_array_almost_equal(sys.B, Brtrue) + np.testing.assert_array_almost_equal(sys.C, Crtrue) + np.testing.assert_array_almost_equal(sys.D, Drtrue) + + def testBalredTruncate(self): + #controlable canonical realization computed in matlab for the transfer function: + # num = [1 11 45 32], den = [1 15 60 200 60] + A = np.matrix('-15., -7.5, -6.25, -1.875; \ + 8., 0., 0., 0.; \ + 0., 4., 0., 0.; \ + 0., 0., 1., 0.') + B = np.matrix('2.; 0.; 0.; 0.') + C = np.matrix('0.5, 0.6875, 0.7031, 0.5') + D = np.matrix('0.') + sys = ss(A,B,C,D) + orders = 2 + rsys = balred(sys,orders,'elimination','truncate') + Artrue = np.matrix('-1.95, 0.6203; 2.314, -0.8432') + Brtrue = np.matrix('0.7221; -0.6306') + Crtrue = np.matrix('1.132, -0.2667') + Drtrue = np.matrix('0.') + np.testing.assert_array_almost_equal(sys.A, Artrue) + np.testing.assert_array_almost_equal(sys.B, Brtrue) + np.testing.assert_array_almost_equal(sys.C, Crtrue) + np.testing.assert_array_almost_equal(sys.D, Drtrue) + + + if __name__ == '__main__': unittest.main() Modified: branches/control-0.4a/src/modelsimp.py =================================================================== --- branches/control-0.4a/src/modelsimp.py 2011-02-08 22:13:30 UTC (rev 46) +++ branches/control-0.4a/src/modelsimp.py 2011-02-08 22:13:36 UTC (rev 47) @@ -43,6 +43,7 @@ import numpy as np import ctrlutil from control.exception import * +from statefbk import * # Hankel Singular Value Decomposition # The following returns the Hankel singular values, which are singular values of the matrix formed by multiplying the controllability and observability grammians @@ -69,7 +70,7 @@ Wo = gram(sys,'o') WoWc = np.dot(Wo, Wc) - w, v = LA.eig(WoWc) + w, v = np.linalg.eig(WoWc) hsv = np.sqrt(w) hsv = np.matrix(hsv) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |