From: <mur...@us...> - 2011-08-07 15:13:05
|
Revision: 172 http://python-control.svn.sourceforge.net/python-control/?rev=172&view=rev Author: murrayrm Date: 2011-08-07 15:12:58 +0000 (Sun, 07 Aug 2011) Log Message: ----------- * Changed function names to be more consistent with python coding standards (PEP 8): StepReponse is now step_response, etc. No changes in control.matlab interface. * Changed version number (for next release) to 0.5a due to changes in call signatures. Modified Paths: -------------- trunk/ChangeLog trunk/examples/genswitch.py trunk/examples/phaseplots.py trunk/examples/pvtol-lqr.py trunk/examples/pvtol-nested-ss.py trunk/examples/pvtol-nested.py trunk/examples/secord-matlab.py trunk/examples/test-response.py trunk/setup.py trunk/src/__init__.py trunk/src/freqplot.py trunk/src/margins.py trunk/src/matlab.py trunk/src/nichols.py trunk/src/phaseplot.py trunk/src/rlocus.py trunk/src/timeresp.py trunk/tests/margin_test.py trunk/tests/phaseplot_test.py trunk/tests/test_all.py trunk/tests/timeresp_test.py Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2011-07-26 05:44:01 UTC (rev 171) +++ trunk/ChangeLog 2011-08-07 15:12:58 UTC (rev 172) @@ -1,3 +1,37 @@ +2011-08-07 Richard Murray <murray@malabar.local> + + * examples/secord-matlab.py, examples/pvtol-nested-ss.py, + examples/test-response.py, examples/pvtol-nested.py: fixed small bug + in order of output arguments for step command + +2011-08-06 Richard Murray <murray@malabar.local> + + * src/matlab.py (ngrid): copy documentation from nichols_grid + + * src/__init__.py: changed import commands to import specific + functions rather than '*' (better modularity) + + * src/freqplot.py: default function names are now bode_plot, + nyquist_plot and gangof4_plot (still with aliases to non-"_plot" + versions) + + * src/nichols.py (nichols_plot): updated nichols to nichols_plot for + consistency with other python-control plotting functions. Set up + alias for original name + + * src/margins.py: StabilityMargins, PhaseCrossoverFrequencies -> + stability_margins, phase_crossover_frequencies + + * src/phaseplot.py: changed PhasePlot and boxgrid to phase_plot, + box_grid + + * src/timeresp.py: changed ForcedReponse, InitialReponse, + ImpulseReponse and StepResponse to forced_response, + initial_response, impulse_response and step_response. + + * src/rlocus.py: changed RootLocus to root_locus for better + compatability with PEP 8. Also updated unit tests and examples. + 2011-07-25 Richard Murray <murray@malabar.local> * tests/phaseplot_test.py: updated unit tests to use new call Modified: trunk/examples/genswitch.py =================================================================== --- trunk/examples/genswitch.py 2011-07-26 05:44:01 UTC (rev 171) +++ trunk/examples/genswitch.py 2011-08-07 15:12:58 UTC (rev 172) @@ -9,7 +9,7 @@ import matplotlib.pyplot as mpl from scipy.integrate import odeint from matplotlib.mlab import frange -from control import PhasePlot, boxgrid +from control import phase_plot, box_grid # Simple model of a genetic switch # @@ -68,7 +68,7 @@ # Phase portrait mpl.figure(2); mpl.clf(); # subplot(221); mpl.axis([0, 5, 0, 5]); # set(gca, 'DataAspectRatio', [1, 1, 1]); -PhasePlot(genswitch, X0 = boxgrid([0, 5, 6], [0, 5, 6]), T = 10, +phase_plot(genswitch, X0 = box_grid([0, 5, 6], [0, 5, 6]), T = 10, timepts = [0.2, 0.6, 1.2]) # Add the stable equilibrium points Modified: trunk/examples/phaseplots.py =================================================================== --- trunk/examples/phaseplots.py 2011-07-26 05:44:01 UTC (rev 171) +++ trunk/examples/phaseplots.py 2011-08-07 15:12:58 UTC (rev 172) @@ -6,7 +6,7 @@ import numpy as np import matplotlib.pyplot as mpl -from control.phaseplot import PhasePlot +from control.phaseplot import phase_plot from numpy import pi # Clear out any figures that are present @@ -26,7 +26,7 @@ mpl.title('Inverted pendlum') # Outer trajectories -PhasePlot(invpend_ode, +phase_plot(invpend_ode, X0 = [ [-2*pi, 1.6], [-2*pi, 0.5], [-1.8, 2.1], [-1, 2.1], [4.2, 2.1], [5, 2.1], [2*pi, -1.6], [2*pi, -0.5], [1.8, -2.1], @@ -36,7 +36,7 @@ # Separatrices mpl.hold(True); -PhasePlot(invpend_ode, X0 = [[-2.3056, 2.1], [2.3056, -2.1]], T=6, lingrid=0) +phase_plot(invpend_ode, X0 = [[-2.3056, 2.1], [2.3056, -2.1]], T=6, lingrid=0) mpl.show(); # @@ -48,7 +48,7 @@ # Generate a vector plot for the damped oscillator mpl.figure(); mpl.clf(); -PhasePlot(oscillator_ode, [-1, 1, 10], [-1, 1, 10], 0.15); +phase_plot(oscillator_ode, [-1, 1, 10], [-1, 1, 10], 0.15); mpl.hold(True); mpl.plot([0], [0], '.'); # a=gca; set(a,'FontSize',20); set(a,'DataAspectRatio',[1,1,1]); mpl.xlabel('x1'); mpl.ylabel('x2'); @@ -56,7 +56,7 @@ # Generate a phase plot for the damped oscillator mpl.figure(); mpl.clf(); mpl.axis([-1, 1, -1, 1]); # set(gca, 'DataAspectRatio', [1, 1, 1]); -PhasePlot(oscillator_ode, +phase_plot(oscillator_ode, X0 = [ [-1, 1], [-0.3, 1], [0, 1], [0.25, 1], [0.5, 1], [0.75, 1], [1, 1], [1, -1], [0.3, -1], [0, -1], [-0.25, -1], [-0.5, -1], [-0.75, -1], [-1, -1] @@ -81,7 +81,7 @@ m = 1; b = 1; k = 1; # default values mpl.figure(); mpl.clf(); mpl.axis([-1, 1, -1, 1]); # set(gca, 'DataAspectRatio', [1 1 1]); -PhasePlot(oscillator_ode, +phase_plot(oscillator_ode, X0 = [ [-1,1], [-0.3,1], [0,1], [0.25,1], [0.5,1], [0.7,1], [1,1], [1.3,1], [1,-1], [0.3,-1], [0,-1], [-0.25,-1], [-0.5,-1], [-0.7,-1], [-1,-1], @@ -95,7 +95,7 @@ # Saddle mpl.figure(); mpl.clf(); mpl.axis([-1, 1, -1, 1]); # set(gca, 'DataAspectRatio', [1 1 1]); -PhasePlot(saddle_ode, scale = 2, timepts = [0.2, 0.5, 0.8], X0 = +phase_plot(saddle_ode, scale = 2, timepts = [0.2, 0.5, 0.8], X0 = [ [-1, -1], [1, 1], [-1, -0.95], [-1, -0.9], [-1, -0.8], [-1, -0.6], [-1, -0.4], [-1, -0.2], [-0.95, -1], [-0.9, -1], [-0.8, -1], [-0.6, -1], [-0.4, -1], [-0.2, -1], @@ -111,7 +111,7 @@ m = 1; b = 0; k = 1; # zero damping mpl.figure(); mpl.clf(); mpl.axis([-1, 1, -1, 1]); # set(gca, 'DataAspectRatio', [1 1 1]); -PhasePlot(oscillator_ode, timepts = +phase_plot(oscillator_ode, timepts = [pi/6, pi/3, pi/2, 2*pi/3, 5*pi/6, pi, 7*pi/6, 4*pi/3, 9*pi/6, 5*pi/3, 11*pi/6, 2*pi], X0 = [ [0.2,0], [0.4,0], [0.6,0], [0.8,0], [1,0], [1.2,0], [1.4,0] ], T = np.linspace(0, 20, 200), parms = (m, b, k)); Modified: trunk/examples/pvtol-lqr.py =================================================================== --- trunk/examples/pvtol-lqr.py 2011-07-26 05:44:01 UTC (rev 171) +++ trunk/examples/pvtol-lqr.py 2011-08-07 15:12:58 UTC (rev 172) @@ -111,11 +111,11 @@ # Step response for the first input H1ax = ss(Ax - Bx*K1a[0,lat], Bx*K1a[0,lat]*xd[lat,:], Cx, Dx); -(Tx, Yx) = step(H1ax, T=linspace(0,10,100)); +(Yx, Tx) = step(H1ax, T=linspace(0,10,100)); # Step response for the second input H1ay = ss(Ay - By*K1a[1,alt], By*K1a[1,alt]*yd[alt,:], Cy, Dy); -(Ty, Yy) = step(H1ay, T=linspace(0,10,100)); +(Yy, Ty) = step(H1ay, T=linspace(0,10,100)); subplot(221); title("Identity weights") # plot(T, Y[:,1, 1], '-', T, Y[:,2, 2], '--'); hold(True); @@ -136,9 +136,9 @@ Qu1c = (200**2)*diag([1, 1]); (K1c, X, E) = lqr(A, B, Qx1, Qu1c); H1cx = ss(Ax - Bx*K1c[0,lat], Bx*K1c[0,lat]*xd[lat,:],Cx, Dx); -[T1, Y1] = step(H1ax, T=linspace(0,10,100)); -[T2, Y2] = step(H1bx, T=linspace(0,10,100)); -[T3, Y3] = step(H1cx, T=linspace(0,10,100)); +[Y1, T1] = step(H1ax, T=linspace(0,10,100)); +[Y2, T2] = step(H1bx, T=linspace(0,10,100)); +[Y3, T3] = step(H1cx, T=linspace(0,10,100)); subplot(222); title("Effect of input weights") plot(T1.T, Y1.T, 'b-'); hold(True); @@ -160,8 +160,8 @@ H2y = ss(Ay - By*K2[1,alt], By*K2[1,alt]*yd[alt,:], Cy, Dy); subplot(223); title("Output weighting") -[T2x, Y2x] = step(H2x, T=linspace(0,10,100)); -[T2y, Y2y] = step(H2y, T=linspace(0,10,100)); +[Y2x, T2x] = step(H2x, T=linspace(0,10,100)); +[Y2y, T2y] = step(H2y, T=linspace(0,10,100)); plot(T2x.T, Y2x.T, T2y.T, Y2y.T) ylabel('position'); xlabel('time'); ylabel('position'); @@ -183,8 +183,8 @@ H3y = ss(Ay - By*K3[1,alt], By*K3[1,alt]*yd[alt,:], Cy, Dy); subplot(224) # step(H3x, H3y, 10); -[T3x, Y3x] = step(H3x, T=linspace(0,10,100)); -[T3y, Y3y] = step(H3y, T=linspace(0,10,100)); +[Y3x, T3x] = step(H3x, T=linspace(0,10,100)); +[Y3y, T3y] = step(H3y, T=linspace(0,10,100)); plot(T3x.T, Y3x.T, T3y.T, Y3y.T) title("Physically motivated weights") xlabel('time'); Modified: trunk/examples/pvtol-nested-ss.py =================================================================== --- trunk/examples/pvtol-nested-ss.py 2011-07-26 05:44:01 UTC (rev 171) +++ trunk/examples/pvtol-nested-ss.py 2011-08-07 15:12:58 UTC (rev 172) @@ -144,10 +144,10 @@ # 'EdgeColor', color, 'FaceColor', color); figure(9); -(Tvec, Yvec) = step(T, linspace(1, 20)); +(Yvec, Tvec) = step(T, linspace(1, 20)); plot(Tvec.T, Yvec.T); hold(True); -(Tvec, Yvec) = step(Co*S, linspace(1, 20)); +(Yvec, Tvec) = step(Co*S, linspace(1, 20)); plot(Tvec.T, Yvec.T); #TODO: PZmap for statespace systems has not yet been implemented. Modified: trunk/examples/pvtol-nested.py =================================================================== --- trunk/examples/pvtol-nested.py 2011-07-26 05:44:01 UTC (rev 171) +++ trunk/examples/pvtol-nested.py 2011-08-07 15:12:58 UTC (rev 172) @@ -134,10 +134,10 @@ # 'EdgeColor', color, 'FaceColor', color); figure(9); -(Tvec, Yvec) = step(T, linspace(1, 20)); +(Yvec, Tvec) = step(T, linspace(0, 20)); plot(Tvec.T, Yvec.T); hold(True); -(Tvec, Yvec) = step(Co*S, linspace(1, 20)); +(Yvec, Tvec) = step(Co*S, linspace(0, 20)); plot(Tvec.T, Yvec.T); figure(10); clf(); Modified: trunk/examples/secord-matlab.py =================================================================== --- trunk/examples/secord-matlab.py 2011-07-26 05:44:01 UTC (rev 171) +++ trunk/examples/secord-matlab.py 2011-08-07 15:12:58 UTC (rev 172) @@ -17,7 +17,7 @@ # Step response for the system figure(1) -T, yout = step(sys) +yout, T = step(sys) plot(T.T, yout.T) # Bode plot for the system Modified: trunk/examples/test-response.py =================================================================== --- trunk/examples/test-response.py 2011-07-26 05:44:01 UTC (rev 171) +++ trunk/examples/test-response.py 2011-08-07 15:12:58 UTC (rev 172) @@ -10,9 +10,9 @@ sys2 = tf([1, 1], [1, 1, 0]) # Generate step responses -(T1a, y1a) = step(sys1) -(T1b, y1b) = step(sys1, T = arange(0, 10, 0.1)) -(T1c, y1c) = step(sys1, X0 = [1, 0]) -(T2a, y2a) = step(sys2, T = arange(0, 10, 0.1)) +(y1a, T1a) = step(sys1) +(y1b, T1b) = step(sys1, T = arange(0, 10, 0.1)) +(y1c, T1c) = step(sys1, X0 = [1, 0]) +(y2a, T2a) = step(sys2, T = arange(0, 10, 0.1)) plot(T1a, y1a, T1b, y1b, T1c, y1c, T2a, y2a) Modified: trunk/setup.py =================================================================== --- trunk/setup.py 2011-07-26 05:44:01 UTC (rev 171) +++ trunk/setup.py 2011-08-07 15:12:58 UTC (rev 172) @@ -4,7 +4,7 @@ from setuptools import setup setup(name = 'control', - version = '0.4d', + version = '0.5a', description = 'Python Control Systems Library', author = 'Richard Murray', author_email = 'mu...@cd...', Modified: trunk/src/__init__.py =================================================================== --- trunk/src/__init__.py 2011-07-26 05:44:01 UTC (rev 171) +++ trunk/src/__init__.py 2011-08-07 15:12:58 UTC (rev 172) @@ -57,17 +57,18 @@ # Import functions from within the control system library #! Should probably only import the exact functions we use... -from bdalg import * -from delay import * -from freqplot import * -from margins import * -from mateqn import * -from modelsimp import * -from nichols import * -from phaseplot import PhasePlot, boxgrid -from rlocus import * -from statefbk import * -from statesp import * -from timeresp import ForcedResponse, InitialResponse, StepResponse, \ - ImpulseResponse -from xferfcn import * +from bdalg import series, parallel, negate, feedback +from delay import pade +from freqplot import bode_plot, nyquist_plot, gangof4_plot +from freqplot import bode, nyquist, gangof4 +from margins import stability_margins, phase_crossover_frequencies +from mateqn import lyap, dlyap, care, dare +from modelsimp import hsvd, modred, balred, era, markov +from nichols import nichols_plot, nichols +from phaseplot import phase_plot, box_grid +from rlocus import root_locus +from statefbk import place, lqr, ctrb, obsv, gram +from statesp import StateSpace +from timeresp import forced_response, initial_response, step_response, \ + impulse_response +from xferfcn import TransferFunction Modified: trunk/src/freqplot.py =================================================================== --- trunk/src/freqplot.py 2011-07-26 05:44:01 UTC (rev 171) +++ trunk/src/freqplot.py 2011-08-07 15:12:58 UTC (rev 172) @@ -55,7 +55,7 @@ # # Bode plot -def BodePlot(syslist, omega=None, dB=False, Hz=False, deg=True, +def bode_plot(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 NyquistPlot(syslist, omega=None, Plot=True): +def nyquist_plot(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 GangOf4Plot(P, C, omega=None): +def gangof4_plot(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 @@ -363,6 +363,6 @@ return omega # Function aliases -bode = BodePlot -nyquist = NyquistPlot -gangof4 = GangOf4Plot +bode = bode_plot +nyquist = nyquist_plot +gangof4 = gangof4_plot Modified: trunk/src/margins.py =================================================================== --- trunk/src/margins.py 2011-07-26 05:44:01 UTC (rev 171) +++ trunk/src/margins.py 2011-08-07 15:12:58 UTC (rev 172) @@ -4,8 +4,8 @@ Routeins in this module: -margin.StabilityMargins -margin.PhaseCrossoverFrequencies +margin.stability_margins +margin.phase_crossover_frequencies """ """Copyright (c) 2011 by California Institute of Technology @@ -54,13 +54,13 @@ # gain and phase margins # contributed by Sawyer B. Fuller <mi...@ca...> #! TODO - need to add unit test functions -def StabilityMargins(sysdata, deg=True): +def stability_margins(sysdata, deg=True): """Calculate gain, phase and stability margins and associated crossover frequencies. Usage: - gm, pm, sm, wg, wp, ws = StabilityMargins(sysdata, deg=True) + gm, pm, sm, wg, wp, ws = stability_margins(sysdata, deg=True) Parameters ---------- @@ -149,13 +149,13 @@ # Contributed by Steffen Waldherr <wal...@is...> #! TODO - need to add test functions -def PhaseCrossoverFrequencies(sys): +def phase_crossover_frequencies(sys): """ Compute frequencies and gains at intersections with real axis in Nyquist plot. Call as: - omega, gain = PhaseCrossoverFrequencies() + omega, gain = phase_crossover_frequencies() Returns ------- Modified: trunk/src/matlab.py =================================================================== --- trunk/src/matlab.py 2011-07-26 05:44:01 UTC (rev 171) +++ trunk/src/matlab.py 2011-08-07 15:12:58 UTC (rev 172) @@ -62,6 +62,7 @@ # Libraries that we make use of import scipy as sp # SciPy library (used all over) import numpy as np # NumPy library +import re # regular expressions from copy import deepcopy # Import MATLAB-like functions that are defined in other packages @@ -990,15 +991,10 @@ return freqplot.bode(syslist, omega, **keywords) # Nichols chart grid +from nichols import nichols_grid def ngrid(): - """Nichols chart grid. - - Examples - -------- - >>> ngrid() - """ - from nichols import nichols_grid nichols_grid() +ngrid.__doc__ = re.sub('nichols_grid', 'ngrid', nichols_grid.__doc__) # Root locus plot def rlocus(sys, klist = None, **keywords): @@ -1018,12 +1014,12 @@ klist: list of gains used to compute roots """ - from rlocus import RootLocus + from rlocus import root_locus if (klist == None): #! TODO: update with a smart cacluation of the gains klist = logspace(-3, 3) - rlist = RootLocus(sys, klist, **keywords) + rlist = root_locus(sys, klist, **keywords) return rlist, klist def margin(*args): @@ -1060,9 +1056,9 @@ """ if len(args) == 1: sys = args[0] - margin = margins.StabilityMargins(sys) + margin = margins.stability_margins(sys) elif len(args) == 3: - margin = margins.StabilityMargins(args) + margin = margins.stability_margins(args) else: raise ValueError("Margin needs 1 or 3 arguments; received %i." % len(args)) @@ -1157,7 +1153,7 @@ **keywords: Additional keyword arguments control the solution algorithm for the differential equations. These arguments are passed on to the function - :func:`control.ForcedResponse`, which in turn passes them on to + :func:`control.forced_response`, which in turn passes them on to :func:`scipy.integrate.odeint`. See the documentation for :func:`scipy.integrate.odeint` for information about these arguments. @@ -1178,7 +1174,7 @@ -------- >>> T, yout = step(sys, T, X0) ''' - T, yout = timeresp.StepResponse(sys, T, X0, input, output, + T, yout = timeresp.step_response(sys, T, X0, input, output, transpose = True, **keywords) return yout, T @@ -1228,7 +1224,7 @@ -------- >>> T, yout = impulse(sys, T) ''' - T, yout = timeresp.ImpulseResponse(sys, T, 0, input, output, + T, yout = timeresp.impulse_response(sys, T, 0, input, output, transpose = True, **keywords) return yout, T @@ -1284,7 +1280,7 @@ -------- >>> T, yout = initial(sys, T, X0) ''' - T, yout = timeresp.InitialResponse(sys, T, X0, input, output, + T, yout = timeresp.initial_response(sys, T, X0, input, output, transpose = True, **keywords) return yout, T @@ -1338,6 +1334,6 @@ -------- >>> T, yout, xout = lsim(sys, U, T, X0) ''' - T, yout, xout = timeresp.ForcedResponse(sys, T, U, X0, + T, yout, xout = timeresp.forced_response(sys, T, U, X0, transpose = True, **keywords) return yout, T, xout Modified: trunk/src/nichols.py =================================================================== --- trunk/src/nichols.py 2011-07-26 05:44:01 UTC (rev 171) +++ trunk/src/nichols.py 2011-08-07 15:12:58 UTC (rev 172) @@ -46,7 +46,7 @@ from freqplot import default_frequency_range # Nichols plot -def nichols(syslist, omega=None, grid=True): +def nichols_plot(syslist, omega=None, grid=True): """Nichols plot for a system Plots a Nichols plot for the system over a (optional) frequency range. @@ -294,3 +294,6 @@ mags = sp.linspace(10**(mag_min/20.0), 10**(mag_max/20.0), 2000) Gcl_phases, Gcl_mags = sp.meshgrid(sp.radians(phases), mags) return closed_loop_contours(Gcl_mags, Gcl_phases) + +# Function aliases +nichols = nichols_plot Modified: trunk/src/phaseplot.py =================================================================== --- trunk/src/phaseplot.py 2011-07-26 05:44:01 UTC (rev 171) +++ trunk/src/phaseplot.py 2011-08-07 15:12:58 UTC (rev 172) @@ -39,7 +39,7 @@ from exception import ControlNotImplemented from scipy.integrate import odeint -def PhasePlot(odefun, X=None, Y=None, scale=1, X0=None, T=None, +def phase_plot(odefun, X=None, Y=None, scale=1, X0=None, T=None, lingrid=None, lintime=None, logtime=None, timepts=None, parms=(), verbose=True): """ @@ -48,12 +48,12 @@ Produces a vector field or stream line plot for a planar system. Call signatures: - PhasePlot(func, X, Y, ...) - display vector field on meshgrid - PhasePlot(func, X, Y, scale, ...) - scale arrows - PhasePlot(func. X0=(...), T=Tmax, ...) - display stream lines - PhasePlot(func, X, Y, X0=[...], T=Tmax, ...) - plot both - PhasePlot(func, X0=[...], T=Tmax, lingrid=N, ...) - plot both - PhasePlot(func, X0=[...], lintime=N, ...) - stream lines with arrows + phase_plot(func, X, Y, ...) - display vector field on meshgrid + phase_plot(func, X, Y, scale, ...) - scale arrows + phase_plot(func. X0=(...), T=Tmax, ...) - display stream lines + phase_plot(func, X, Y, X0=[...], T=Tmax, ...) - plot both + phase_plot(func, X0=[...], T=Tmax, lingrid=N, ...) - plot both + phase_plot(func, X0=[...], lintime=N, ...) - stream lines with arrows Parameters ---------- @@ -104,7 +104,7 @@ See also -------- - boxgrid(X, Y): construct box-shaped grid of initial conditions + box_grid(X, Y): construct box-shaped grid of initial conditions Examples -------- @@ -274,10 +274,10 @@ return; # Utility function for generating initial conditions around a box -def boxgrid(xlimp, ylimp): - """BOXGRID generate list of points on edge of box +def box_grid(xlimp, ylimp): + """box_grid generate list of points on edge of box - list = BOXGRID([xmin xmax xnum], [ymin ymax ynum]) generates a + list = box_grid([xmin xmax xnum], [ymin ymax ynum]) generates a list of points that correspond to a uniform grid at the end of the box defined by the corners [xmin ymin] and [xmax ymax]. """ Modified: trunk/src/rlocus.py =================================================================== --- trunk/src/rlocus.py 2011-07-26 05:44:01 UTC (rev 171) +++ trunk/src/rlocus.py 2011-08-07 15:12:58 UTC (rev 172) @@ -52,7 +52,7 @@ import xferfcn # transfer function manipulation # Main function: compute a root locus diagram -def RootLocus(sys, kvect, xlim=None, ylim=None, plotstr='-', Plot=True): +def root_locus(sys, kvect, xlim=None, ylim=None, plotstr='-', Plot=True): """Calculate the root locus by finding the roots of 1+k*TF(s) where TF is self.num(s)/self.den(s) and each k is an element of kvect. Modified: trunk/src/timeresp.py =================================================================== --- trunk/src/timeresp.py 2011-07-26 05:44:01 UTC (rev 171) +++ trunk/src/timeresp.py 2011-08-07 15:12:58 UTC (rev 172) @@ -53,8 +53,8 @@ This is a convention for function arguments and return values that represent time series: sequences of values that change over time. It is used throughout the library, for example in the functions -:func:`ForcedResponse`, :func:`StepResponse`, :func:`ImpulseResponse`, -and :func:`InitialResponse`. +:func:`forced_response`, :func:`step_response`, :func:`impulse_response`, +and :func:`initial_response`. .. note:: This convention is different from the convention used in the library @@ -235,7 +235,7 @@ return out_array # Forced response of a linear system -def ForcedResponse(sys, T=None, U=0., X0=0., transpose=False, **keywords): +def forced_response(sys, T=None, U=0., X0=0., transpose=False, **keywords): """Simulate the output of a linear system. As a convenience for parameters `U`, `X0`: @@ -285,11 +285,11 @@ See Also -------- - StepResponse, InitialResponse, ImpulseResponse + step_response, initial_response, impulse_response Examples -------- - >>> T, yout, xout = ForcedResponse(sys, T, u, X0) + >>> T, yout, xout = forced_response(sys, T, u, X0) """ if not isinstance(sys, Lti): raise TypeError('Parameter ``sys``: must be a ``Lti`` object. ' @@ -365,7 +365,7 @@ return T, yout, xout -def StepResponse(sys, T=None, X0=0., input=0, output=0, \ +def step_response(sys, T=None, X0=0., input=0, output=0, \ transpose = False, **keywords): #pylint: disable=W0622 """Step response of a linear system @@ -419,11 +419,11 @@ See Also -------- - ForcedResponse, InitialResponse, ImpulseResponse + forced_response, initial_response, impulse_response Examples -------- - >>> T, yout = StepResponse(sys, T, X0) + >>> T, yout = step_response(sys, T, X0) """ sys = _convertToStateSpace(sys) sys = _mimo2siso(sys, input, output, warn_conversion=True) @@ -431,13 +431,13 @@ T = _default_response_times(sys.A, 100) U = np.ones_like(T) - T, yout, _xout = ForcedResponse(sys, T, U, X0, + T, yout, _xout = forced_response(sys, T, U, X0, transpose=transpose, **keywords) return T, yout -def InitialResponse(sys, T=None, X0=0., input=0, output=0, transpose=False, +def initial_response(sys, T=None, X0=0., input=0, output=0, transpose=False, **keywords): #pylint: disable=W0622 """Initial condition response of a linear system @@ -491,26 +491,26 @@ See Also -------- - ForcedResponse, ImpulseResponse, StepResponse + forced_response, impulse_response, step_response Examples -------- - >>> T, yout = InitialResponse(sys, T, X0) + >>> T, yout = initial_response(sys, T, X0) """ sys = _convertToStateSpace(sys) sys = _mimo2siso(sys, input, output, warn_conversion=True) - #Create time and input vectors; checking is done in ForcedResponse(...) - #The initial vector X0 is created in ForcedResponse(...) if necessary + #Create time and input vectors; checking is done in forced_response(...) + #The initial vector X0 is created in forced_response(...) if necessary if T is None: T = _default_response_times(sys.A, 100) U = np.zeros_like(T) - T, yout, _xout = ForcedResponse(sys, T, U, X0, transpose=transpose, + T, yout, _xout = forced_response(sys, T, U, X0, transpose=transpose, **keywords) return T, yout -def ImpulseResponse(sys, T=None, X0=0., input=0, output=0, +def impulse_response(sys, T=None, X0=0., input=0, output=0, transpose=False, **keywords): #pylint: disable=W0622 """Impulse response of a linear system @@ -564,11 +564,11 @@ See Also -------- - ForcedReponse, InitialResponse, StepResponse + ForcedReponse, initial_response, step_response Examples -------- - >>> T, yout = ImpulseResponse(sys, T, X0) + >>> T, yout = impulse_response(sys, T, X0) """ sys = _convertToStateSpace(sys) sys = _mimo2siso(sys, input, output, warn_conversion=True) @@ -597,7 +597,7 @@ T = _default_response_times(sys.A, 100) U = np.zeros_like(T) - T, yout, _xout = ForcedResponse(sys, T, U, new_X0, \ + T, yout, _xout = forced_response(sys, T, U, new_X0, \ transpose=transpose, **keywords) return T, yout Modified: trunk/tests/margin_test.py =================================================================== --- trunk/tests/margin_test.py 2011-07-26 05:44:01 UTC (rev 171) +++ trunk/tests/margin_test.py 2011-08-07 15:12:58 UTC (rev 172) @@ -7,7 +7,7 @@ import numpy as np from control.xferfcn import TransferFunction from control.statesp import StateSpace -from control.margin import * +from control.margins import * class TestMargin(unittest.TestCase): """These are tests for the margin commands in margin.py.""" @@ -18,25 +18,25 @@ self.sys3 = StateSpace([[1., 4.], [3., 2.]], [[1.], [-4.]], [[1., 0.]], [[0.]]) - def testGainPhaseMargin(self): - gm, pm, sm, wg, wp, ws = StabilityMargins(self.sys1); - gm, pm, sm, wg, wp, ws = StabilityMargins(self.sys2); - gm, pm, sm, wg, wp, ws = StabilityMargins(self.sys3); + def test_stability_margins(self): + gm, pm, sm, wg, wp, ws = stability_margins(self.sys1); + gm, pm, sm, wg, wp, ws = stability_margins(self.sys2); + gm, pm, sm, wg, wp, ws = stability_margins(self.sys3); - def testPhaseCrossoverFrequencies(self): - omega, gain = PhaseCrossoverFrequencies(self.sys2) + def test_phase_crossover_frequencies(self): + omega, gain = phase_crossover_frequencies(self.sys2) np.testing.assert_array_almost_equal(omega, [1.73205, 0.]) np.testing.assert_array_almost_equal(gain, [-0.5, 0.25]) tf = TransferFunction([1],[1,1]) - omega, gain = PhaseCrossoverFrequencies(tf) + omega, gain = phase_crossover_frequencies(tf) np.testing.assert_array_almost_equal(omega, [0.]) np.testing.assert_array_almost_equal(gain, [1.]) # testing MIMO, only (0,0) element is considered tf = TransferFunction([[[1],[2]],[[3],[4]]], [[[1, 2, 3, 4],[1,1]],[[1,1],[1,1]]]) - omega, gain = PhaseCrossoverFrequencies(tf) + omega, gain = phase_crossover_frequencies(tf) np.testing.assert_array_almost_equal(omega, [1.73205081, 0.]) np.testing.assert_array_almost_equal(gain, [-0.5, 0.25]) Modified: trunk/tests/phaseplot_test.py =================================================================== --- trunk/tests/phaseplot_test.py 2011-07-26 05:44:01 UTC (rev 171) +++ trunk/tests/phaseplot_test.py 2011-08-07 15:12:58 UTC (rev 172) @@ -21,18 +21,18 @@ pass; def testInvPendNoSims(self): - PhasePlot(self.invpend_ode, (-6,6,10), (-6,6,10)); + phase_plot(self.invpend_ode, (-6,6,10), (-6,6,10)); def testInvPendSims(self): - PhasePlot(self.invpend_ode, (-6,6,10), (-6,6,10), + phase_plot(self.invpend_ode, (-6,6,10), (-6,6,10), X0 = ([1,1], [-1,1])); def testInvPendTimePoints(self): - PhasePlot(self.invpend_ode, (-6,6,10), (-6,6,10), + phase_plot(self.invpend_ode, (-6,6,10), (-6,6,10), X0 = ([1,1], [-1,1]), T=np.linspace(0,5,100)); def testInvPendLogtime(self): - PhasePlot(self.invpend_ode, X0 = + phase_plot(self.invpend_ode, X0 = [ [-2*pi, 1.6], [-2*pi, 0.5], [-1.8, 2.1], [-1, 2.1], [4.2, 2.1], [5, 2.1], [2*pi, -1.6], [2*pi, -0.5], [1.8, -2.1], @@ -42,12 +42,12 @@ verbose=False) def testInvPendAuto(self): - PhasePlot(self.invpend_ode, lingrid = 0, X0= + phase_plot(self.invpend_ode, lingrid = 0, X0= [[-2.3056, 2.1], [2.3056, -2.1]], T=6, verbose=False) def testOscillatorParams(self): m = 1; b = 1; k = 1; # default values - PhasePlot(self.oscillator_ode, timepts = [0.3, 1, 2, 3], X0 = + phase_plot(self.oscillator_ode, timepts = [0.3, 1, 2, 3], X0 = [[-1,1], [-0.3,1], [0,1], [0.25,1], [0.5,1], [0.7,1], [1,1], [1.3,1], [1,-1], [0.3,-1], [0,-1], [-0.25,-1], [-0.5,-1], [-0.7,-1], [-1,-1], [-1.3,-1]], Modified: trunk/tests/test_all.py =================================================================== --- trunk/tests/test_all.py 2011-07-26 05:44:01 UTC (rev 171) +++ trunk/tests/test_all.py 2011-08-07 15:12:58 UTC (rev 172) @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# test_al.py - test suit for python-control +# test_all.py - test suit for python-control # RMM, 30 Mar 2011 import unittest # unit test module Modified: trunk/tests/timeresp_test.py =================================================================== --- trunk/tests/timeresp_test.py 2011-07-26 05:44:01 UTC (rev 171) +++ trunk/tests/timeresp_test.py 2011-08-07 15:12:58 UTC (rev 172) @@ -43,7 +43,7 @@ "0. 9. ") self.mimo_ss1 = StateSpace(A, B, C, D) - def testStepResponse(self): + def test_step_response(self): #Test SISO system sys = self.siso_ss1 t = np.linspace(0, 1, 10) @@ -51,64 +51,64 @@ 42.3227, 44.9694, 47.1599, 48.9776]) # SISO call - tout, yout = StepResponse(sys, T=t) + tout, yout = step_response(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 = StepResponse(sys, T=t, X0=0) + tout, yout = step_response(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 = StepResponse(sys, T=t, X0=X0) + tout, yout = step_response(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 = StepResponse(sys, T=t, input=0, output=0) - _t, y_11 = StepResponse(sys, T=t, input=1, output=1) + _t, y_00 = step_response(sys, T=t, input=0, output=0) + _t, y_11 = step_response(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) - def testImpulseResponse(self): + def test_impulse_response(self): #Test SISO system sys = self.siso_ss1 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 = ImpulseResponse(sys, T=t) + tout, yout = impulse_response(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 = ImpulseResponse(sys, T=t, input=0, output=0) - _t, y_11 = ImpulseResponse(sys, T=t, input=1, output=1) + _t, y_00 = impulse_response(sys, T=t, input=0, output=0) + _t, y_11 = impulse_response(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) - def testInitialResponse(self): + def test_initial_response(self): #Test SISO system sys = self.siso_ss1 t = np.linspace(0, 1, 10) x0 = np.array([[0.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 = InitialResponse(sys, T=t, X0=x0) + tout, yout = initial_response(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 = InitialResponse(sys, T=t, X0=x0, input=0, output=0) - _t, y_11 = InitialResponse(sys, T=t, X0=x0, input=1, output=1) + _t, y_00 = initial_response(sys, T=t, X0=x0, input=0, output=0) + _t, y_11 = initial_response(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) - def testForcedResponse(self): + def test_forced_response(self): t = np.linspace(0, 1, 10) #compute step response - test with state space, and transfer function @@ -116,10 +116,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 = ForcedResponse(self.siso_ss1, t, u) + tout, yout, _xout = forced_response(self.siso_ss1, t, u) np.testing.assert_array_almost_equal(yout, youttrue, decimal=4) np.testing.assert_array_almost_equal(tout, t) - _t, yout, _xout = ForcedResponse(self.siso_tf2, t, u) + _t, yout, _xout = forced_response(self.siso_tf2, t, u) np.testing.assert_array_almost_equal(yout, youttrue, decimal=4) #test with initial value and special algorithm for ``U=0`` @@ -127,7 +127,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 = ForcedResponse(self.siso_ss1, t, u, x0) + _t, yout, _xout = forced_response(self.siso_ss1, t, u, x0) np.testing.assert_array_almost_equal(yout, youttrue, decimal=4) #Test MIMO system, which contains ``siso_ss1`` twice @@ -139,7 +139,7 @@ 1.1508, 0.5833, 0.1645, -0.1391], [9., 17.6457, 24.7072, 30.4855, 35.2234, 39.1165, 42.3227, 44.9694, 47.1599, 48.9776]]) - _t, yout, _xout = ForcedResponse(self.mimo_ss1, t, u, x0) + _t, yout, _xout = forced_response(self.mimo_ss1, t, u, x0) np.testing.assert_array_almost_equal(yout, youttrue, decimal=4) def suite(): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |