# Non-negative ODE solution

**URL:** https://discourse.julialang.org/t/non-negative-ode-solution/23449
**Category:** General Usage
**Created:** [April 23, 2019, 5:23pm UTC](https://discourse.julialang.org/t/non-negative-ode-solution/23449 "2019-04-23T17:23:35Z")
**Posts on this page:** 1
**Showing post:** 2

<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: [April 23, 2019, 5:34pm UTC](https://discourse.julialang.org/t/non-negative-ode-solution/23449/2 "2019-04-23T17:34:03Z")

</div>

Hey,  
There are two ways to do this. One is to use `isoutofdomain`. It’s documented with the other solver options:

[http://docs.juliadiffeq.org/latest/basics/common\_solver\_opts.html#Miscellaneous-1](http://docs.juliadiffeq.org/latest/basics/common_solver_opts.html#Miscellaneous-1)

`isoutofdomain = (u,p,t)->any(x->x<0,u)` makes any step with a negative value get rejected and use a smaller `dt`. This is a method that is always safe, but may get a few more rejections.

The other method is to use `PositiveDomain()` as a callback on the problem. This uses continuous extensions in the event handling to perform the pullback to the positive time.

[http://docs.juliadiffeq.org/latest/features/callback\_library.html#PositiveDomain-1](http://docs.juliadiffeq.org/latest/features/callback_library.html#PositiveDomain-1)

This is more like MATLAB’s version. This is less safe than `isoutofdomain` since it requires that the function is differentiable around zero in order for the interpolation to make sense, but it can be (a tiny bit) faster.

---

_[View the full topic](https://discourse.julialang.org/t/non-negative-ode-solution/23449)._
