Hey,
There are two ways to do this. One is to use isoutofdomain
. It’s documented with the other solver options:
http://docs.juliadiffeq.org/latest/basics/common_solver_opts.html#Miscellaneous-1
isoutofdomain = (u,p,t)->any(x->x<0,u)
makes any step with a negative value get rejected and use a smaller dt
. This is a method that is always safe, but may get a few more rejections.
The other method is to use PositiveDomain()
as a callback on the problem. This uses continuous extensions in the event handling to perform the pullback to the positive time.
http://docs.juliadiffeq.org/latest/features/callback_library.html#PositiveDomain-1
This is more like MATLAB’s version. This is less safe than isoutofdomain
since it requires that the function is differentiable around zero in order for the interpolation to make sense, but it can be (a tiny bit) faster.