Skip to content

Commit

Permalink
Merge pull request #682 from miroslavfikar/mifi_ufun
Browse files Browse the repository at this point in the history
Fix bug in ufun: extrapolation throwing errors
  • Loading branch information
murrayrm committed Dec 26, 2021
2 parents 89291e6 + 9bd61b0 commit 8356044
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions control/iosys.py
Original file line number Diff line number Diff line change
Expand Up @@ -1852,13 +1852,10 @@ def input_output_response(
# but has a lot less overhead => simulation runs much faster
def ufun(t):
# Find the value of the index using linear interpolation
idx = np.searchsorted(T, t, side='left')
if idx == 0:
# For consistency in return type, multiple by a float
return U[..., 0] * 1.
else:
dt = (t - T[idx-1]) / (T[idx] - T[idx-1])
return U[..., idx-1] * (1. - dt) + U[..., idx] * dt
# Use clip to allow for extrapolation if t is out of range
idx = np.clip(np.searchsorted(T, t, side='left'), 1, len(T)-1)
dt = (t - T[idx-1]) / (T[idx] - T[idx-1])
return U[..., idx-1] * (1. - dt) + U[..., idx] * dt

# Create a lambda function for the right hand side
def ivp_rhs(t, x):
Expand Down

0 comments on commit 8356044

Please sign in to comment.