I am trying to solve the Lane-Emden equations using DifferentialEquations. This is a system of two first order ODEs which are something like `dtheta/dxi = psi, dpsi/dxi = -2 psi/xi - theta^n`

. I want to stop the integration when theta hits zero. However, as you can see if n is a fraction negative theta would cause problem. In principle, since the integration should stop as it hits zero, there should not be any problem. But the error that the solver gives is exactly due to the negative theta. How to circumvent this problem?

Use `abs`

doesnâ€™t error and let the callback â€śrewindâ€ť. Itâ€™s the same in all languages/cases.

1 Like