Skip to content

Phaseplot typeerror #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions control/phaseplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions control/rlocus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down
15 changes: 14 additions & 1 deletion control/tests/phaseplot_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down