# Callback function in DifferentialEquations

**URL:** <https://discourse.julialang.org/t/callback-function-in-differentialequations/55314>\
**Category:** General Usage\
**Tags:** question, diffeq\
**Created:** [February 15, 2021, 12:36pm UTC](https://discourse.julialang.org/t/callback-function-in-differentialequations/55314 "2021-02-15T12:36:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![arif](https://avatars.discourse-cdn.com/v4/letter/a/74df32/32.png) [@arif](https://discourse.julialang.org/u/arif)\
**Post date:** [February 15, 2021, 12:36pm UTC](https://discourse.julialang.org/t/callback-function-in-differentialequations/55314/1 "2021-02-15T12:36:30Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [February 15, 2021, 1:32pm UTC](https://discourse.julialang.org/t/callback-function-in-differentialequations/55314/2 "2021-02-15T13:32:49Z")

</div>

Use `abs` doesn’t error and let the callback “rewind”. It’s the same in all languages/cases.
