Skip to content

Commit 5a75ca0

Browse files
committed
update iosys ufun to extrapolate
1 parent 306a216 commit 5a75ca0

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

control/iosys.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,15 +1852,10 @@ def input_output_response(
18521852
# but has a lot less overhead => simulation runs much faster
18531853
def ufun(t):
18541854
# Find the value of the index using linear interpolation
1855-
idx = np.searchsorted(T, t, side='left')
1856-
if idx == 0:
1857-
# For consistency in return type, multiple by a float
1858-
return U[..., 0] * 1.
1859-
elif idx == len(T): # request for extrapolation, stop at right side
1860-
return U[..., idx-1] * 1.
1861-
else:
1862-
dt = (t - T[idx-1]) / (T[idx] - T[idx-1])
1863-
return U[..., idx-1] * (1. - dt) + U[..., idx] * dt
1855+
# Use clip to allow for extrapolation if t is out of range
1856+
idx = np.clip(np.searchsorted(T, t, side='left'), 1, len(T)-1)
1857+
dt = (t - T[idx-1]) / (T[idx] - T[idx-1])
1858+
return U[..., idx-1] * (1. - dt) + U[..., idx] * dt
18641859

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

0 commit comments

Comments
 (0)