Skip to content

Commit 0104e4b

Browse files
committed
added fix for phaseplots to handle no arrow case correctly
1 parent 7b07af3 commit 0104e4b

2 files changed

Lines changed: 25 additions & 5 deletions

File tree

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/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)