|
From: <kk...@us...> - 2011-02-08 22:13:50
|
Revision: 49
http://python-control.svn.sourceforge.net/python-control/?rev=49&view=rev
Author: kkchen
Date: 2011-02-08 22:13:44 +0000 (Tue, 08 Feb 2011)
Log Message:
-----------
Added interface for balred and modred in modelsimp.py. Also changed * to dot in gram function.
Steven Brunton <sbr...@pr...>
Modified Paths:
--------------
branches/control-0.4a/src/modelsimp.py
branches/control-0.4a/src/statefbk.py
Modified: branches/control-0.4a/src/modelsimp.py
===================================================================
--- branches/control-0.4a/src/modelsimp.py 2011-02-08 22:13:40 UTC (rev 48)
+++ branches/control-0.4a/src/modelsimp.py 2011-02-08 22:13:44 UTC (rev 49)
@@ -77,6 +77,112 @@
# Return the Hankel singular values
return hsv
+def modred(sys,ELIM,method):
+ """Model reduction of sys by eliminating the states in ELIM using a given method
+
+ Usage
+ =====
+ rsys = modred(sys,ELIM,method)
+
+ Inputs
+ ======
+ sys : original system to reduce
+ ELIM : vector of states to eliminate
+ method : method of removing states in ELIM (truncate or matchdc)
+
+ Outputs
+ =======
+ rsys : a reduced order model
+
+ """
+
+ #Check for ss system object, need a utility for this?
+
+ #TODO: Check for continous or discrete, only continuous supported right now
+ # if isCont():
+ # dico = 'C'
+ # elif isDisc():
+ # dico = 'D'
+ # else:
+ dico = 'C'
+
+ #TODO: Check system is stable, perhaps a utility in ctrlutil.py
+ # or a method of the StateSpace class?
+ D,V = np.linalg.eig(sys.A)
+ for e in D:
+ if e.real >= 0:
+ raise ValueError, "Oops, the system is unstable!"
+
+ if method=='matchdc':
+ print "matchdc"
+ elif method=='truncate':
+ print "truncate"
+ 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 balred(sys,orders,elimination,method):
+ """Balanced reduced order model of sys of a given order. States are eliminated based on Hankel singular value.
+
+ Usage
+ =====
+ rsys = balred(sys,order,elimination,method)
+
+ Inputs
+ ======
+ sys : original system to reduce
+ orders : desired order of reduced order model (if a vector, returns a vector of systems)
+ elimination : if elimination is specified, use 'method'
+ method : method of removing states (truncate or matchdc)
+
+ Outputs
+ =======
+ rsys : a reduced order model
+
+ """
+
+ #Check for ss system object, need a utility for this?
+
+ #TODO: Check for continous or discrete, only continuous supported right now
+ # if isCont():
+ # dico = 'C'
+ # elif isDisc():
+ # dico = 'D'
+ # else:
+ dico = 'C'
+
+ #TODO: Check system is stable, perhaps a utility in ctrlutil.py
+ # or a method of the StateSpace class?
+ D,V = np.linalg.eig(sys.A)
+ for e in D:
+ if e.real >= 0:
+ raise ValueError, "Oops, the system is unstable!"
+
+ if method=='matchdc':
+ print "matchdc"
+ elif method=='truncate':
+ print "truncate"
+ 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
Modified: branches/control-0.4a/src/statefbk.py
===================================================================
--- branches/control-0.4a/src/statefbk.py 2011-02-08 22:13:40 UTC (rev 48)
+++ branches/control-0.4a/src/statefbk.py 2011-02-08 22:13:44 UTC (rev 49)
@@ -267,11 +267,11 @@
if type=='c':
print "controllable"
trana = 'T'
- C = -sys.B*sys.B.transpose()
+ C = -np.dot(sys.B,sys.B.transpose())
elif type=='o':
print "observable"
trana = 'N'
- C = -sys.C.transpose()*sys.C
+ C = -np.dot(sys.C.transpose(),sys.C)
else:
raise ValueError, "Oops, neither observable, nor controllable!"
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|