Hi, I'm trying to solve an initial-value ODE using RK4, say dx/dt = f(x,t), x(0) = x0. I want to find t_end so that x(t_end) = 0. The basic RK4 implementation works fine, however I'm having some difficulties with stopping it in time. I've tried googling around but all I could find was references to matlab or similar, which doesn't say anything about how the zero crossing is detected and handled. The immediate way I can think of is to check after each integration step if x(t) has crossed, and if so restart the step using say half the step length, repeating until it no longer crosses, x(t) = 0 or the step length is below some minimum. Is this an acceptable solution? Are there some better ways? Cheers!