Skip to content
Merged
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
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