Why is the default behaviour of DifferentialEquations to extrapolate the solution beyond the time range?

I just spent an entire afternoon debugging why my equation appears to go unstable. Stupidly, I was animating the solution for T=[0, 10], whereas the solution was solved on the interval T=[0, 3].

For clarity, my code (from memory) looked something like

‘’’
T = 3.0
sol = solve(ode_problem, u0, T)

ts = LinRange(0.0, 10.0, 100)
plot(sol.(ts))
‘’’

While fully admitting my culpability, is this not a bit of a footgun? Can we protect silly people like me by throwing an error when ‘t’ in ‘sol(t)’ is outside the range of the solution?

Otherwise, thank you for what is an amazing package/ecosystem!

Related issue Allow to disable solution extrapolation · Issue #869 · SciML/DifferentialEquations.jl · GitHub

1 Like

It’s used in things like prediction-correctors like in the DDE solvers themselves. We could definitely have a switch on it. We used to actually disallow extrapolation by default but then that error was removed because people said it got in the way of too many things :sweat_smile:

1 Like

Thanks for the reply. From my point of view, a default behaviour (; extrapolate_solution=false) would have saved a headache, but I understand there is a large ecosystem depending upon DifferentialEquations with varying needs and use cases.