# How to keep u\>0 when solving ODEs

**URL:** <https://discourse.julialang.org/t/how-to-keep-u-0-when-solving-odes/101824>\
**Category:** General Usage\
**Created:** [July 20, 2023, 8:44am UTC](https://discourse.julialang.org/t/how-to-keep-u-0-when-solving-odes/101824 "2023-07-20T08:44:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![liao2877104858](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/liao2877104858/32/45869_2.png) [@liao2877104858](https://discourse.julialang.org/u/liao2877104858)\
**Post date:** [July 20, 2023, 8:44am UTC](https://discourse.julialang.org/t/how-to-keep-u-0-when-solving-odes/101824/1 "2023-07-20T08:44:54Z")

</div>

I’m using Rodas3() to solve a stiff ODEs in Julia. du/dt = F(u). The Analytical expression of u should be positive. However, when I use julia to solve the ODE, u may be less equal 0. I suspect that the time step was too large.

I wonder if there is parameters. When solving ODE, if the u of a certain step size is less than 0, the step size will be recalculated by rolling it back.

Thany you!

---

<div class="post-metadata">

**Author:** ![contradict](https://avatars.discourse-cdn.com/v4/letter/c/ac91a4/32.png) [@contradict](https://discourse.julialang.org/u/contradict)\
**Post date:** [July 20, 2023, 3:00pm UTC](https://discourse.julialang.org/t/how-to-keep-u-0-when-solving-odes/101824/2 "2023-07-20T15:00:15Z")

</div>

[`isoutofdomain`](https://docs.sciml.ai/DiffEqDocs/stable/basics/common_solver_opts/#CommonSolve.solve-Tuple%7BSciMLBase.AbstractDEProblem,%20Vararg%7BAny%7D%7D) (Under the Miscellaneous heading) can do that, however it is often helpful to transform your problem using something like `u⁺ = ln(u)` and then whatever the value of u⁺, `exp(u⁺)` will be positive.

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [July 20, 2023, 3:02pm UTC](https://discourse.julialang.org/t/how-to-keep-u-0-when-solving-odes/101824/3 "2023-07-20T15:02:10Z")

</div>

I’d recommend reading through [Frequently Asked Questions · DifferentialEquations.jl](https://docs.sciml.ai/DiffEqDocs/stable/basics/faq/#My-ODE-goes-negative-but-should-stay-positive,-what-tools-can-help)?
