diff --git a/control/phaseplot.py b/control/phaseplot.py index 2108d99e6..4703dd868 100644 --- a/control/phaseplot.py +++ b/control/phaseplot.py @@ -120,7 +120,10 @@ def phase_plot(odefun, X=None, Y=None, scale=1, X0=None, T=None, # Figure out ranges for phase plot (argument processing) # #! TODO: need to add error checking to arguments + #! TODO: think through proper action if multiple options are given + # autoFlag = False; logtimeFlag = False; timeptsFlag = False; Narrows = 0; + if lingrid is not None: autoFlag = True; Narrows = lingrid; @@ -138,14 +141,18 @@ def phase_plot(odefun, X=None, Y=None, scale=1, X0=None, T=None, timeptsFlag = True; Narrows = len(timepts); - else: - # Figure out the set of points for the quiver plot - #! TODO: Add sanity checks + # Figure out the set of points for the quiver plot + #! TODO: Add sanity checks + elif (X is not None and Y is not None): (x1, x2) = np.meshgrid( frange(X[0], X[1], float(X[1]-X[0])/X[2]), frange(Y[0], Y[1], float(Y[1]-Y[0])/Y[2])); + else: + # If we weren't given any grid points, don't plot arrows + Narrows = 0; - if ((not autoFlag) and (not logtimeFlag) and (not timeptsFlag)): + if ((not autoFlag) and (not logtimeFlag) and (not timeptsFlag) + and (Narrows > 0)): # Now calculate the vector field at those points (nr,nc) = x1.shape; dx = np.empty((nr, nc, 2)) diff --git a/control/rlocus.py b/control/rlocus.py index 57e938d12..e272a833d 100644 --- a/control/rlocus.py +++ b/control/rlocus.py @@ -50,7 +50,7 @@ from scipy import array, poly1d, row_stack, zeros_like, real, imag import scipy.signal # signal processing toolbox import pylab # plotting routines -from . import xferfcn +from .xferfcn import _convertToTransferFunction from .exception import ControlMIMONotImplemented from functools import partial @@ -144,7 +144,7 @@ def _systopoly1d(sys): else: # Convert to a transfer function, if needed - sys = xferfcn._convertToTransferFunction(sys) + sys = _convertToTransferFunction(sys) # Make sure we have a SISO system if (sys.inputs > 1 or sys.outputs > 1): diff --git a/control/tests/phaseplot_test.py b/control/tests/phaseplot_test.py index e596dd54f..b8194e260 100644 --- a/control/tests/phaseplot_test.py +++ b/control/tests/phaseplot_test.py @@ -13,7 +13,7 @@ import numpy as np import scipy as sp import matplotlib.pyplot as mpl -from control.phaseplot import * +from control import phase_plot from numpy import pi class TestPhasePlot(unittest.TestCase): @@ -53,6 +53,19 @@ def testOscillatorParams(self): [-0.5,-1], [-0.7,-1], [-1,-1], [-1.3,-1]], T = np.linspace(0, 10, 100), parms = (m, b, k)); + def testNoArrows(self): + # Test case from aramakrl that was generating a type error + # System does not have arrows + def d1(x1x2,t): + x1,x2 = x1x2 + return np.array([x2, x2 - 2*x1]) + + x1x2_0 = np.array([[-1.,1.], [-1.,-1.], [1.,1.], [1.,-1.], + [-1.,0.],[1.,0.],[0.,-1.],[0.,1.],[0.,0.]]) + + mpl.figure(1) + phase_plot(d1,X0=x1x2_0,T=100) + # Sample dynamical systems - inverted pendulum def invpend_ode(self, x, t, m=1., l=1., b=0, g=9.8): import numpy as np