Fixing bug in timeresp.forced_response #336
Merged
Merged
Conversation
…ueError when applied to discrete sys with T=None.
murrayrm
reviewed
Aug 9, 2019
| 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]): |
Member
There was a problem hiding this comment.
Not sure if this fits in 78 columns. If not, break into two lines (at or)?
Contributor
Author
There was a problem hiding this comment.
I've broken this line in the updated PR.
| T = np.array(range(n_steps)) * (1 if sys.dt is True else sys.dt) | ||
| else: | ||
| # Make sure the input vector and time vector have same length | ||
| # TODO: allow interpolation of the input vector |
Member
There was a problem hiding this comment.
Leave this comment in, since at some point we would like to allow "subsampling"
Contributor
Author
There was a problem hiding this comment.
I have re-added this comment in the updated PR.
bnavigator
reviewed
Aug 9, 2019
| '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: |
Contributor
Author
There was a problem hiding this comment.
I have replaced all instances of range(len(U)) with U.ndim in the updated PR.
| 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]): |
Contributor
There was a problem hiding this comment.
Consider U.ndim instead of len(U.shape)
Contributor
Author
There was a problem hiding this comment.
I have replaced all instances of range(len(U)) with U.ndim in the updated PR.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: