# Can you prevent Julia from erroring out when solving ODE problem, if Domain Error arises?

**URL:** <https://discourse.julialang.org/t/can-you-prevent-julia-from-erroring-out-when-solving-ode-problem-if-domain-error-arises/42842>\
**Category:** General Usage\
**Tags:** ode\
**Created:** [July 10, 2020, 12:24pm UTC](https://discourse.julialang.org/t/can-you-prevent-julia-from-erroring-out-when-solving-ode-problem-if-domain-error-arises/42842 "2020-07-10T12:24:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cbasile21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cbasile21/32/13072_2.png) [@cbasile21](https://discourse.julialang.org/u/cbasile21)\
**Post date:** [July 10, 2020, 12:24pm UTC](https://discourse.julialang.org/t/can-you-prevent-julia-from-erroring-out-when-solving-ode-problem-if-domain-error-arises/42842/1 "2020-07-10T12:24:10Z")

</div>

say you have a parameter in a ODE system of equations.

x = (u[1]) ^ 0.8

du[1] = x - k\_elim  
(Downstream effects are unaffected ( lets pretend) – So is Good output I dont want to waste.

du[2]= (…)

As an example. Let us assume the initial condition of u is generated randomly , sometimes is negative , sometimes positive for u1 (that will generate the issue). When negative Julia will error out with Domain Error, because say negative value ^ 0.8 will produce real and imaginary component. However, matlab I seen it not to fail, what I think it did is simply populate the -IC throughout all time final output returned after system is solved, and somehow ignore d[1].

I think isoutofdomain to prevent non-negative is meant for preventing solution for going negative given IC is chosen, or at least one that will not solve a Domain Error, so this option will not help me. I am looking for best practices here. Thanks

Is there a way to ignore the error by options, and simulate the rest ? If you would want me to inquiry more about what matlab might be doing before I re-ask the question , I can ask them their matlab side.

I look forward to your response.

Thank you

Christian

---

<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:** [July 10, 2020, 1:35pm UTC](https://discourse.julialang.org/t/can-you-prevent-julia-from-erroring-out-when-solving-ode-problem-if-domain-error-arises/42842/2 "2020-07-10T13:35:27Z")

</div>

Set `isoutofdomain` but do `abs(u[1])^0.8`. That way it won’t error but it will also reject any step where it goes negative.

---

<div class="post-metadata">

**Author:** ![cbasile21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cbasile21/32/13072_2.png) [@cbasile21](https://discourse.julialang.org/u/cbasile21)\
**Post date:** [July 10, 2020, 1:41pm UTC](https://discourse.julialang.org/t/can-you-prevent-julia-from-erroring-out-when-solving-ode-problem-if-domain-error-arises/42842/3 "2020-07-10T13:41:33Z")

</div>

Hi Chris,

That makes a lot of sense, thanks a lot for your quick response and help!

Best

Thanks

Christian
