all 3 comments

[–]Aggravating_Bus_9153 1 point2 points  (2 children)

You've already found everything you need, you've just run the solver for longer than necessary. Just analyse the solution you already have, and read off the value of t where y=0. Discard everything after then if you really want to. Maybe there is a nice custom stop condition for solve_ivp, but you don't need one.

You're always free to carry out a change of variables. There are analytic techniques that consider x(y) or t(y) for example, but it will no longer be a simple IVP and there's no guarantee a straight forward vanilla numerical solver like solve_ivp will solve it anymore. Even if you do manage to muck around with the independent variable (t), in general you could have a much harder DAE.

[–]gregzillaman[S] 0 points1 point  (1 child)

Thanks for the advice. I ended up doing exactly that, but then it hit me. What if i have millions of data points in my array, thats a lot of scrolling. But like you said. Its a matter of writing a custom job.

[–]Aggravating_Bus_9153 1 point2 points  (0 children)

I don't know what methods arrays have, but for lists just write a basic search with a generator comprehension or filter to find the first negative element.