From: <kk...@us...> - 2011-02-08 22:18:25
|
Revision: 104 http://python-control.svn.sourceforge.net/python-control/?rev=104&view=rev Author: kkchen Date: 2011-02-08 22:18:19 +0000 (Tue, 08 Feb 2011) Log Message: ----------- Changed the message in TestConvert.py so that it reads there is a complex numbers error but all of the tests pass. This error is due to rounding in the common denominator routine. It can be seen by printing num, den right before passing to td04ad in _convertToStateSpace. td04ad can only have real proper transfer functions (although the roots of course can still be imaginary.) Have also added TestSlycot.py which can be used to isolate debugging slycot routines from python-control. Lauren Padilla <lpa...@pr...> Modified Paths: -------------- branches/control-0.4a/src/TestConvert.py branches/control-0.4a/src/statesp.py Added Paths: ----------- branches/control-0.4a/src/TestSlycot.py Modified: branches/control-0.4a/src/TestConvert.py =================================================================== --- branches/control-0.4a/src/TestConvert.py 2011-02-08 22:18:14 UTC (rev 103) +++ branches/control-0.4a/src/TestConvert.py 2011-02-08 22:18:19 UTC (rev 104) @@ -4,11 +4,10 @@ Test state space and transfer function conversion. -Currently, this unit test script is not complete. Ideally, it would convert +Currently, this unit test script is not complete. It converts several random state spaces back and forth between state space and transfer -function representations, and assert that the conversion outputs are correct. -As they currently stand, the td04ad and tb04ad functions appear to be buggy from -time to time. Therefore, this script can be used to diagnose the errors. +function representations, and asserts that the conversion outputs are correct. +As it stands, tests pass but there is some rounding error in one of the conversions leading to imaginary numbers. See the warning message. This script may be used to diagnose errors. """ @@ -29,7 +28,7 @@ # Maximum number of inputs and outputs to test + 1 self.maxIO = 3 # Set to True to print systems to the output. - self.debug = False + self.debug = True def printSys(self, sys, ind): """Print system to the standard output.""" @@ -51,7 +50,7 @@ sys2 = matlab.tf(sys1) self.printSys(sys2, 2) - + sys3 = matlab.ss(sys2) self.printSys(sys3, 3) Added: branches/control-0.4a/src/TestSlycot.py =================================================================== --- branches/control-0.4a/src/TestSlycot.py (rev 0) +++ branches/control-0.4a/src/TestSlycot.py 2011-02-08 22:18:19 UTC (rev 104) @@ -0,0 +1,30 @@ +import numpy as np +from slycot import tb04ad, td04ad +import matlab + +numTests = 1 +maxStates = 3 +maxIO = 3 + +for states in range(1, maxStates): + for inputs in range(1, maxIO): + for outputs in range(1, maxIO): + sys1 = matlab.rss(states, inputs, outputs) + print "sys1" + print sys1 + + sys2 = tb04ad(states,inputs,outputs,sys1.A,sys1.B,sys1.C,sys1.D,outputs,outputs,inputs) + print "sys2" + print sys2 + + ldwork = 100*max(1,states+max(states,max(3*inputs,3*outputs))) + dwork = np.zeros(ldwork) + sys3 = td04ad(inputs,outputs,sys2[4],sys2[5],sys2[6]) + #sys3 = td04ad(inputs,outputs,sys2[4],sys2[5],sys2[6],ldwork) + print "sys3" + print sys3 + + sys4 = tb04ad(states,inputs,outputs,sys3[1][0:states,0:states],sys3[2][0:states,0:inputs],sys3[3][0:outputs,0:states],sys3[4],outputs,outputs,inputs) + print "sys4" + print sys4 + Modified: branches/control-0.4a/src/statesp.py =================================================================== --- branches/control-0.4a/src/statesp.py 2011-02-08 22:18:14 UTC (rev 103) +++ branches/control-0.4a/src/statesp.py 2011-02-08 22:18:19 UTC (rev 104) @@ -449,9 +449,11 @@ index = [len(den) - 1 for i in range(sys.outputs)] # Repeat the common denominator along the rows. den = array([den for i in range(sys.outputs)]) - + #print index + #print den + #print num ssout = td04ad(sys.inputs, sys.outputs, index, den, num) - + states = ssout[0] return StateSpace(ssout[1][:states, :states], ssout[2][:states, :sys.inputs], This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |