|
From: <kk...@us...> - 2011-02-08 22:15:02
|
Revision: 64
http://python-control.svn.sourceforge.net/python-control/?rev=64&view=rev
Author: kkchen
Date: 2011-02-08 22:14:56 +0000 (Tue, 08 Feb 2011)
Log Message:
-----------
Modified balred routine in modelsimp.py module to use real slycot routine ab09ad. User must have new slycot files installed for balred to work. testBalredTruncate unittest now passes.
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:14:51 UTC (rev 63)
+++ branches/control-0.4a/src/TestModelsimp.py 2011-02-08 22:14:56 UTC (rev 64)
@@ -101,14 +101,14 @@
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')
+ 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)
+ np.testing.assert_array_almost_equal(rsys.A, Artrue,decimal=2)
+ np.testing.assert_array_almost_equal(rsys.B, Brtrue,decimal=4)
+ np.testing.assert_array_almost_equal(rsys.C, Crtrue,decimal=4)
+ np.testing.assert_array_almost_equal(rsys.D, Drtrue,decimal=4)
Modified: branches/control-0.4a/src/modelsimp.py
===================================================================
--- branches/control-0.4a/src/modelsimp.py 2011-02-08 22:14:51 UTC (rev 63)
+++ branches/control-0.4a/src/modelsimp.py 2011-02-08 22:14:56 UTC (rev 64)
@@ -44,6 +44,7 @@
import ctrlutil
from control.exception import *
from statefbk import *
+from statesp import StateSpace
# 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
@@ -167,22 +168,34 @@
raise ValueError, "Oops, the system is unstable!"
if method=='matchdc':
- print "matchdc"
+ raise ValueError, "MatchDC not yet supported!"
elif method=='truncate':
- print "truncate"
+ try:
+ from slycot import ab09ad
+ except ImportError:
+ raise ControlSlycot("can't find slycot subroutine ab09ad")
+ job = 'B' # balanced (B) or not (N)
+ equil = 'N' # scale (S) or not (N)
+ ordsel = 'F' # fixed truncation level (F) or find the truncation level given tol (A)
+ n = np.size(sys.A,0)
+ m = np.size(sys.B,1)
+ p = np.size(sys.C,0)
+ nr = orders
+ tol = 0.
+ out = ab09ad(dico,job,equil,ordsel, n, m, p, nr, sys.A, sys.B, sys.C,tol)
+ Ar = out[0][0:nr,0:nr]
+ Br = out[1][0:nr,0:m]
+ Cr = out[2][0:p,0:nr]
+ hsv = out[3]
+ iwarn = out[4]
+ info = out[5]
+
+ rsys = StateSpace(Ar, Br, Cr, sys.D)
else:
raise ValueError, "Oops, method is not supported!"
- #Compute rhs using the Slycot routine XXXXXX
- #make sure Slycot is installed
- #try:
- # from slycot import XXXXXX
- #except ImportError:
- # raise ControlSlycot("can't find slycot module 'XXXXXX'")
- rsys = 0.
return rsys
-
def era(YY,m,n,nin,nout,r):
"""Calculate an ERA model of order r based on the impulse-response data YY
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|