-
Notifications
You must be signed in to change notification settings - Fork 439
Fixing bug in timeresp.forced_response #336
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
Conversation
…ueError when applied to discrete sys with T=None.
control/timeresp.py
Outdated
if len(U) != len(T): | ||
ValueError('Pamameter ``T`` must have same length as' | ||
'input vector ``U``') | ||
if (len(U.shape) == 1 and U.shape[0] != T.shape[0]) or (len(U.shape) > 1 and U.shape[1] != T.shape[0]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this fits in 78 columns. If not, break into two lines (at or
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've broken this line in the updated PR.
control/timeresp.py
Outdated
else: | ||
# Make sure the input vector and time vector have same length | ||
# TODO: allow interpolation of the input vector |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leave this comment in, since at some point we would like to allow "subsampling"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have re-added this comment in the updated PR.
control/timeresp.py
Outdated
# Set and/or check time vector in discrete time case | ||
if isdtime(sys, strict=True): | ||
if T is None: | ||
if U is None: | ||
raise ValueError('Parameters ``T`` and ``U`` can\'t both be' | ||
'zero for discrete-time simulation') | ||
# Set T to equally spaced samples with same length as U | ||
T = np.array(range(len(U))) * (1 if sys.dt is True else sys.dt) | ||
if len(U.shape) == 1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using U.ndim
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have replaced all instances of range(len(U)) with U.ndim in the updated PR.
control/timeresp.py
Outdated
if len(U) != len(T): | ||
ValueError('Pamameter ``T`` must have same length as' | ||
'input vector ``U``') | ||
if (len(U.shape) == 1 and U.shape[0] != T.shape[0]) or (len(U.shape) > 1 and U.shape[1] != T.shape[0]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider U.ndim instead of len(U.shape)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have replaced all instances of range(len(U)) with U.ndim in the updated PR.
When forced_response was called with a discrete MIMO sys and T=None, the following error occurred:
Traceback (most recent call last): File "/home/andrew/Apps/python-control/control/tests/timeresp_test.py", line 281, in test_forced_response _t, yout, _xout = forced_response(sysd, U=u, X0=x0) File "/home/andrew/Apps/python-control/control/timeresp.py", line 374, in forced_response tout, yout, xout = sp.signal.dlsim(dsys, np.transpose(U), T, X0) File "/home/andrew/.virtualenvs/python-control-dev/local/lib/python2.7/site-packages/scipy/signal/ltisys.py", line 3327, in dlsim u_dt_interp = interp1d(t, u.transpose(), copy=False, bounds_error=True) File "/home/andrew/.virtualenvs/python-control-dev/local/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 433, in __init__ _Interpolator1D.__init__(self, x, y, axis=axis) File "/home/andrew/.virtualenvs/python-control-dev/local/lib/python2.7/site-packages/scipy/interpolate/polyint.py", line 60, in __init__ self._set_yi(yi, xi=xi, axis=axis) File "/home/andrew/.virtualenvs/python-control-dev/local/lib/python2.7/site-packages/scipy/interpolate/polyint.py", line 125, in _set_yi raise ValueError("x and y arrays must be equal in length along " ValueError: x and y arrays must be equal in length along interpolation axis.
Fix: