From: <mur...@us...> - 2011-07-13 16:03:38
|
Revision: 167 http://python-control.svn.sourceforge.net/python-control/?rev=167&view=rev Author: murrayrm Date: 2011-07-13 16:03:32 +0000 (Wed, 13 Jul 2011) Log Message: ----------- * Updated output arguments for matlab.py time response functions to match MATLAB conventions (they were switched) * Added long version names for frequency plots: BodePlot, NyquistPlot, etc * Fixed some import errors in rlocus.py Details in ChangeLog. Modified Paths: -------------- trunk/ChangeLog trunk/src/freqplot.py trunk/src/matlab.py trunk/src/rlocus.py trunk/tests/matlab_test.py Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2011-07-02 01:55:50 UTC (rev 166) +++ trunk/ChangeLog 2011-07-13 16:03:32 UTC (rev 167) @@ -1,3 +1,18 @@ +2011-07-11 Richard Murray <murray@malabar.local> + + * src/rlocus.py: added real() and imag() to list of functions + imported from numpy + + * src/freqplot.py: renamed plotting functions to BodePlot, + NyquistPlot, GangOf4Plot and MarginPlot. Set up aliases to the more + common names (bode, nyquest, gangof4, margin). Mainly playing + around with idea for the eventual interface to use. + + * tests/matlab_test.py: updated timeresp outputs to match MATLAB + + * src/matlab.py (impulse, initial, lsim, step): switched outputs + from step, impulse, initial, lsim to match MATLAB standard + 2011-07-01 Richard Murray <murray@malabar.local> * src/rlocus.py: modified scipy import to only import those Modified: trunk/src/freqplot.py =================================================================== --- trunk/src/freqplot.py 2011-07-02 01:55:50 UTC (rev 166) +++ trunk/src/freqplot.py 2011-07-13 16:03:32 UTC (rev 167) @@ -55,7 +55,7 @@ # # Bode plot -def bode(syslist, omega=None, dB=False, Hz=False, deg=True, +def BodePlot(syslist, omega=None, dB=False, Hz=False, deg=True, color=None, Plot=True): """Bode plot for a system @@ -178,7 +178,7 @@ return mags, phases, omegas # Nyquist plot -def nyquist(syslist, omega=None, Plot=True): +def NyquistPlot(syslist, omega=None, Plot=True): """Nyquist plot for a system Plots a Nyquist plot for the system over a (optional) frequency range. @@ -245,7 +245,7 @@ # Gang of Four #! TODO: think about how (and whether) to handle lists of systems -def gangof4(P, C, omega=None): +def GangOf4Plot(P, C, omega=None): """Plot the "Gang of 4" transfer functions for a system Generates a 2x2 plot showing the "Gang of 4" sensitivity functions @@ -302,7 +302,7 @@ # gain and phase margins # contributed by Sawyer B. Fuller <mi...@ca...> -def margin(sysdata, deg=True): +def MarginPlot(sysdata, deg=True): """Calculate gain and phase margins and associated crossover frequencies Usage: @@ -457,3 +457,8 @@ return omega +# Function aliases +bode = BodePlot +nyquist = NyquistPlot +gangof4 = GangOf4Plot +margin = MarginPlot Modified: trunk/src/matlab.py =================================================================== --- trunk/src/matlab.py 2011-07-02 01:55:50 UTC (rev 166) +++ trunk/src/matlab.py 2011-07-13 16:03:32 UTC (rev 167) @@ -1165,12 +1165,12 @@ Returns ------- + yout: array + Response of the system + T: array Time values of the output - yout: array - Response of the system - See Also -------- lsim, initial, impulse @@ -1181,7 +1181,7 @@ ''' T, yout = timeresp.StepResponse(sys, T, X0, input, output, transpose = True, **keywords) - return T, yout + return yout, T def impulse(sys, T=None, input=0, output=0, **keywords): ''' @@ -1216,10 +1216,10 @@ Returns ------- + yout: array + Response of the system T: array Time values of the output - yout: array - Response of the system See Also -------- @@ -1231,7 +1231,7 @@ ''' T, yout = timeresp.ImpulseResponse(sys, T, 0, input, output, transpose = True, **keywords) - return T, yout + return yout, T def initial(sys, T=None, X0=0., input=0, output=0, **keywords): ''' @@ -1272,10 +1272,10 @@ Returns ------- + yout: array + Response of the system T: array Time values of the output - yout: array - Response of the system See Also -------- @@ -1287,7 +1287,7 @@ ''' T, yout = timeresp.InitialResponse(sys, T, X0, input, output, transpose = True, **keywords) - return T, yout + return yout, T def lsim(sys, U=0., T=None, X0=0., **keywords): ''' @@ -1324,10 +1324,10 @@ Returns ------- + yout: array + Response of the system. T: array Time values of the output. - yout: array - Response of the system. xout: array Time evolution of the state vector. @@ -1341,4 +1341,4 @@ ''' T, yout, xout = timeresp.ForcedResponse(sys, T, U, X0, transpose = True, **keywords) - return T, yout, xout + return yout, T, xout Modified: trunk/src/rlocus.py =================================================================== --- trunk/src/rlocus.py 2011-07-02 01:55:50 UTC (rev 166) +++ trunk/src/rlocus.py 2011-07-13 16:03:32 UTC (rev 167) @@ -46,7 +46,7 @@ # $Id$ # Packages used by this module -from scipy import array, poly1d, row_stack, zeros_like +from scipy import array, poly1d, row_stack, zeros_like, real, imag import scipy.signal # signal processing toolbox import pylab # plotting routines import xferfcn # transfer function manipulation Modified: trunk/tests/matlab_test.py =================================================================== --- trunk/tests/matlab_test.py 2011-07-02 01:55:50 UTC (rev 166) +++ trunk/tests/matlab_test.py 2011-07-13 16:03:32 UTC (rev 167) @@ -95,24 +95,24 @@ t = np.linspace(0, 1, 10) youttrue = np.array([9., 17.6457, 24.7072, 30.4855, 35.2234, 39.1165, 42.3227, 44.9694, 47.1599, 48.9776]) - tout, yout = step(sys, T=t) + yout, tout = step(sys, T=t) np.testing.assert_array_almost_equal(yout, youttrue, decimal=4) np.testing.assert_array_almost_equal(tout, t) # Play with arguments - tout, yout = step(sys, T=t, X0=0) + yout, tout = step(sys, T=t, X0=0) np.testing.assert_array_almost_equal(yout, youttrue, decimal=4) np.testing.assert_array_almost_equal(tout, t) X0 = np.array([0, 0]); - tout, yout = step(sys, T=t, X0=X0) + yout, tout = step(sys, T=t, X0=X0) np.testing.assert_array_almost_equal(yout, youttrue, decimal=4) np.testing.assert_array_almost_equal(tout, t) #Test MIMO system, which contains ``siso_ss1`` twice sys = self.mimo_ss1 - _t, y_00 = step(sys, T=t, input=0, output=0) - _t, y_11 = step(sys, T=t, input=1, output=1) + y_00, _t = step(sys, T=t, input=0, output=0) + y_11, _t = step(sys, T=t, input=1, output=1) np.testing.assert_array_almost_equal(y_00, youttrue, decimal=4) np.testing.assert_array_almost_equal(y_11, youttrue, decimal=4) @@ -122,14 +122,14 @@ t = np.linspace(0, 1, 10) youttrue = np.array([86., 70.1808, 57.3753, 46.9975, 38.5766, 31.7344, 26.1668, 21.6292, 17.9245, 14.8945]) - tout, yout = impulse(sys, T=t) + yout, tout = impulse(sys, T=t) np.testing.assert_array_almost_equal(yout, youttrue, decimal=4) np.testing.assert_array_almost_equal(tout, t) #Test MIMO system, which contains ``siso_ss1`` twice sys = self.mimo_ss1 - _t, y_00 = impulse(sys, T=t, input=0, output=0) - _t, y_11 = impulse(sys, T=t, input=1, output=1) + y_00, _t = impulse(sys, T=t, input=0, output=0) + y_11, _t = impulse(sys, T=t, input=1, output=1) np.testing.assert_array_almost_equal(y_00, youttrue, decimal=4) np.testing.assert_array_almost_equal(y_11, youttrue, decimal=4) @@ -140,15 +140,15 @@ x0 = np.matrix(".5; 1.") youttrue = np.array([11., 8.1494, 5.9361, 4.2258, 2.9118, 1.9092, 1.1508, 0.5833, 0.1645, -0.1391]) - tout, yout = initial(sys, T=t, X0=x0) + yout, tout = initial(sys, T=t, X0=x0) np.testing.assert_array_almost_equal(yout, youttrue, decimal=4) np.testing.assert_array_almost_equal(tout, t) #Test MIMO system, which contains ``siso_ss1`` twice sys = self.mimo_ss1 x0 = np.matrix(".5; 1.; .5; 1.") - _t, y_00 = initial(sys, T=t, X0=x0, input=0, output=0) - _t, y_11 = initial(sys, T=t, X0=x0, input=1, output=1) + y_00, _t = initial(sys, T=t, X0=x0, input=0, output=0) + y_11, _t = initial(sys, T=t, X0=x0, input=1, output=1) np.testing.assert_array_almost_equal(y_00, youttrue, decimal=4) np.testing.assert_array_almost_equal(y_11, youttrue, decimal=4) @@ -160,10 +160,10 @@ u = np.array([1., 1, 1, 1, 1, 1, 1, 1, 1, 1]) youttrue = np.array([9., 17.6457, 24.7072, 30.4855, 35.2234, 39.1165, 42.3227, 44.9694, 47.1599, 48.9776]) - tout, yout, _xout = lsim(self.siso_ss1, u, t) + yout, tout, _xout = lsim(self.siso_ss1, u, t) np.testing.assert_array_almost_equal(yout, youttrue, decimal=4) np.testing.assert_array_almost_equal(tout, t) - _t, yout, _xout = lsim(self.siso_tf3, u, t) + yout, _t, _xout = lsim(self.siso_tf3, u, t) np.testing.assert_array_almost_equal(yout, youttrue, decimal=4) #test with initial value and special algorithm for ``U=0`` @@ -171,7 +171,7 @@ x0 = np.matrix(".5; 1.") youttrue = np.array([11., 8.1494, 5.9361, 4.2258, 2.9118, 1.9092, 1.1508, 0.5833, 0.1645, -0.1391]) - _t, yout, _xout = lsim(self.siso_ss1, u, t, x0) + yout, _t, _xout = lsim(self.siso_ss1, u, t, x0) np.testing.assert_array_almost_equal(yout, youttrue, decimal=4) #Test MIMO system, which contains ``siso_ss1`` twice @@ -184,7 +184,7 @@ [1.9092, 39.1165], [1.1508, 42.3227], [0.5833, 44.9694], [0.1645, 47.1599], [-0.1391, 48.9776]]) - _t, yout, _xout = lsim(self.mimo_ss1, u, t, x0) + yout, _t, _xout = lsim(self.mimo_ss1, u, t, x0) np.testing.assert_array_almost_equal(yout, youttrue, decimal=4) def testDcgain(self): @@ -206,7 +206,7 @@ #Compute the gain with a long simulation t = linspace(0, 1000, 1000) - _t, y = step(sys_ss, t) + y, _t = step(sys_ss, t) gain_sim = y[-1] print 'gain_sim:', gain_sim This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |