I’m trying to solve a system of ODE which is exactly as the Lotka Volterra systems:
dx/dt = axy - bx
dy/dt = -cxy + dy

In which a, b, c, d, x(0) and y(0) are all positive. According to this set up, x(t) and y(t) could get really small but never become negative. I increased the abs error and rel error to both 10^(-12) and the number of iterations to 10000 which are both way beyond the default values but still get negative results. Does anybody have any suggestions for this problem? Thanks :)

Ode integrators only control within absolute error around 0. A hack solution is to add 10x more than the abs error to the solution. That will keep it positive.

Well…if the solution approaches 0 then that means the log gets very small…which can make the original ode system unexpectedly hard to solve. The log transform trick is elegant, but has other traps one can get caught in. If the clog thing works, its preferable…in practice I guess that the hack is better more often

Thanks everybody for your inputs. I agree that the log-transformation one is very elegant but now some of the parameters will have an exponential effect on the derivatives which might cause some potential issues. In the end, i just set the solutions to zeros manually once it gets below 1e-12, the inferences look ok but I need to carefully investigate the fit.