From: <kk...@us...> - 2011-02-08 22:16:06
|
Revision: 77 http://python-control.svn.sourceforge.net/python-control/?rev=77&view=rev Author: kkchen Date: 2011-02-08 22:16:00 +0000 (Tue, 08 Feb 2011) Log Message: ----------- Added TestMatlab to test impulse, step and initial. Tests fail. There is no scipy.signal.lti initial() function, so we will have to use lsim. Steven Brunton <sbr...@pr...> Modified Paths: -------------- branches/control-0.4a/src/matlab.py Added Paths: ----------- branches/control-0.4a/src/TestMatlab.py Added: branches/control-0.4a/src/TestMatlab.py =================================================================== --- branches/control-0.4a/src/TestMatlab.py (rev 0) +++ branches/control-0.4a/src/TestMatlab.py 2011-02-08 22:16:00 UTC (rev 77) @@ -0,0 +1,44 @@ +#!/usr/bin/env python + +from matlab import * +import numpy as np +import unittest + +class TestMatlab(unittest.TestCase): + def testStep(self): + A = np.matrix("1. -2.; 3. -4.") + B = np.matrix("5.; 7.") + C = np.matrix("6. 8.") + D = np.matrix("9.") + sys = ss(A,B,C,D) + t = np.linspace(0, 1, 10) + t, yout = step(sys, t) + youttrue = np.matrix("9. 17.6457 24.7072 30.4855 35.2234 39.1165 42.3227 44.9694 47.1599 48.9776") + np.testing.assert_array_almost_equal(yout, youttrue,decimal=4) + + def testImpulse(self): + A = np.matrix("1. -2.; 3. -4.") + B = np.matrix("5.; 7.") + C = np.matrix("6. 8.") + D = np.matrix("9.") + sys = ss(A,B,C,D) + t = np.linspace(0, 1, 10) + t, yout = impulse(sys, t) + youttrue = np.matrix("86. 70.1808 57.3753 46.9975 38.5766 31.7344 26.1668 21.6292 17.9245 14.8945") + np.testing.assert_array_almost_equal(yout, youttrue,decimal=4) + + def testInitial(self): + A = np.matrix("1. -2.; 3. -4.") + B = np.matrix("5.; 7.") + C = np.matrix("6. 8.") + D = np.matrix("9.") + sys = ss(A,B,C,D) + t = np.linspace(0, 1, 10) + x0 = np.matrix(".5; 1.") + t, yout = initial(sys, t, x0) + youttrue = np.matrix("11. 8.1494 5.9361 4.2258 2.9118 1.9092 1.1508 0.5833 0.1645 -0.1391") + np.testing.assert_array_almost_equal(yout, youttrue,decimal=4) + + +if __name__ == '__main__': + unittest.main() Property changes on: branches/control-0.4a/src/TestMatlab.py ___________________________________________________________________ Added: svn:executable + * Modified: branches/control-0.4a/src/matlab.py =================================================================== --- branches/control-0.4a/src/matlab.py 2011-02-08 22:15:55 UTC (rev 76) +++ branches/control-0.4a/src/matlab.py 2011-02-08 22:16:00 UTC (rev 77) @@ -599,7 +599,7 @@ ltiobjs = sys.returnScipySignalLti() ltiobj = ltiobjs[0][0] - return sp.signal.lsim2(*args, **keywords) + return sp.signal.lsim2(ltiobj, **keywords) #! Redefine step to use lsim2 #! Not yet implemented @@ -622,15 +622,8 @@ sys = args[0] ltiobjs = sys.returnScipySignalLti() ltiobj = ltiobjs[0][0] - newargs = [] - newargs.append(ltiobj) - for i in range(1, len(args)): - newargs.append(args[i]) - newargs = tuple(newargs) - print len(args) - print len(newargs) - return sp.signal.step(*newargs, **keywords) + return sp.signal.step(ltiobj, **keywords) # Redefine initial to use lsim2 #! Not yet implemented (uses step for now) @@ -654,7 +647,7 @@ ltiobjs = sys.returnScipySignalLti() ltiobj = ltiobjs[0][0] - return sp.signal.initial(*args, **keywords) + return sp.signal.initial(ltiobj, **keywords) # Redefine impulse to use initial() #! Not yet implemented (uses impulse for now) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |