As a toy example, consider the differential equation, dx / dt = p x
ODE = function(t, X, p){ list( p*X ) }
One can solve this using lsoda
from package deSolve
with no problem.
times = seq(0, 20, by=.1)
out = lsoda( y = 1, times, ODE, p = 2 )
However, I'd like lsoda
to stop computing after a threshold value has been reached, say xMax = 1e5
. I coudn't seem to find this option in the documentation. There is an option for events
which looks promising for possibly implementing something like this.
In the deSolve documentation for lsoda you can also find the
rootfunc
parameter which can be used to trigger an event at root locations.See example 3 in https://www.rdocumentation.org/packages/deSolve/versions/1.10-9/topics/events for an example that seems very close to your test case.