Skip to content

Commit 5f30018

Browse files
committed
Merge pull request #97 "Phaseplot typeerror"
#97 Changes are from branch `phaseplot-typeerror` of https://github.com/murrayrm/python-control.git
2 parents d4e0155 + 8144627 commit 5f30018

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

control/phaseplot.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ def phase_plot(odefun, X=None, Y=None, scale=1, X0=None, T=None,
120120
# Figure out ranges for phase plot (argument processing)
121121
#
122122
#! TODO: need to add error checking to arguments
123+
#! TODO: think through proper action if multiple options are given
124+
#
123125
autoFlag = False; logtimeFlag = False; timeptsFlag = False; Narrows = 0;
126+
124127
if lingrid is not None:
125128
autoFlag = True;
126129
Narrows = lingrid;
@@ -138,14 +141,18 @@ def phase_plot(odefun, X=None, Y=None, scale=1, X0=None, T=None,
138141
timeptsFlag = True;
139142
Narrows = len(timepts);
140143

141-
else:
142-
# Figure out the set of points for the quiver plot
143-
#! TODO: Add sanity checks
144+
# Figure out the set of points for the quiver plot
145+
#! TODO: Add sanity checks
146+
elif (X is not None and Y is not None):
144147
(x1, x2) = np.meshgrid(
145148
frange(X[0], X[1], float(X[1]-X[0])/X[2]),
146149
frange(Y[0], Y[1], float(Y[1]-Y[0])/Y[2]));
150+
else:
151+
# If we weren't given any grid points, don't plot arrows
152+
Narrows = 0;
147153

148-
if ((not autoFlag) and (not logtimeFlag) and (not timeptsFlag)):
154+
if ((not autoFlag) and (not logtimeFlag) and (not timeptsFlag)
155+
and (Narrows > 0)):
149156
# Now calculate the vector field at those points
150157
(nr,nc) = x1.shape;
151158
dx = np.empty((nr, nc, 2))

control/rlocus.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
from scipy import array, poly1d, row_stack, zeros_like, real, imag
5151
import scipy.signal # signal processing toolbox
5252
import pylab # plotting routines
53-
from . import xferfcn
53+
from .xferfcn import _convertToTransferFunction
5454
from .exception import ControlMIMONotImplemented
5555
from functools import partial
5656

@@ -144,7 +144,7 @@ def _systopoly1d(sys):
144144

145145
else:
146146
# Convert to a transfer function, if needed
147-
sys = xferfcn._convertToTransferFunction(sys)
147+
sys = _convertToTransferFunction(sys)
148148

149149
# Make sure we have a SISO system
150150
if (sys.inputs > 1 or sys.outputs > 1):

control/tests/phaseplot_test.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import numpy as np
1414
import scipy as sp
1515
import matplotlib.pyplot as mpl
16-
from control.phaseplot import *
16+
from control import phase_plot
1717
from numpy import pi
1818

1919
class TestPhasePlot(unittest.TestCase):
@@ -53,6 +53,19 @@ def testOscillatorParams(self):
5353
[-0.5,-1], [-0.7,-1], [-1,-1], [-1.3,-1]],
5454
T = np.linspace(0, 10, 100), parms = (m, b, k));
5555

56+
def testNoArrows(self):
57+
# Test case from aramakrl that was generating a type error
58+
# System does not have arrows
59+
def d1(x1x2,t):
60+
x1,x2 = x1x2
61+
return np.array([x2, x2 - 2*x1])
62+
63+
x1x2_0 = np.array([[-1.,1.], [-1.,-1.], [1.,1.], [1.,-1.],
64+
[-1.,0.],[1.,0.],[0.,-1.],[0.,1.],[0.,0.]])
65+
66+
mpl.figure(1)
67+
phase_plot(d1,X0=x1x2_0,T=100)
68+
5669
# Sample dynamical systems - inverted pendulum
5770
def invpend_ode(self, x, t, m=1., l=1., b=0, g=9.8):
5871
import numpy as np

0 commit comments

Comments
 (0)