# Problem Solving an "Inverse" ODE w DifferentialEquations.jl

**URL:** <https://discourse.julialang.org/t/problem-solving-an-inverse-ode-w-differentialequations-jl/36521>\
**Category:** Specific Domains\
**Tags:** question, diffeq, ode\
**Created:** [March 25, 2020, 9:30pm UTC](https://discourse.julialang.org/t/problem-solving-an-inverse-ode-w-differentialequations-jl/36521 "2020-03-25T21:30:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![shoshievass](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shoshievass/32/3260_2.png) [@shoshievass](https://discourse.julialang.org/u/shoshievass)\
**Post date:** [March 25, 2020, 9:30pm UTC](https://discourse.julialang.org/t/problem-solving-an-inverse-ode-w-differentialequations-jl/36521/1 "2020-03-25T21:30:03Z")

</div>

I have an ODE that I can solve, but I need to also be able to solve its “inverse”. That is, my normal ode is defined as `du_dx = f(x, u, p)` , and I can solve that, but I also need to be able to solve `dx_du = g(x, u, p)` (because I’m trying to solve a boundary value problem w/ a shooting algorithm).

I’m hitting a weird boundary error when I try to do the inverse problem though, and I’m stuck on why. Any advice on what to try/check or what might help resolve this would be really helpful (and greatly appreciated).

[PublicFiles/Inv\_diffeq\_problem\_example.ipynb at master · shoshievass/PublicFiles · GitHub](https://github.com/shoshievass/PublicFiles/blob/master/Julia/Inv_diffeq_problem_example.ipynb)

---

<div class="post-metadata">

**Author:** ![shoshievass](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shoshievass/32/3260_2.png) [@shoshievass](https://discourse.julialang.org/u/shoshievass)\
**Post date:** [March 26, 2020, 2:20am UTC](https://discourse.julialang.org/t/problem-solving-an-inverse-ode-w-differentialequations-jl/36521/2 "2020-03-26T02:20:23Z")

</div>

One thing that seems to be contributing – the ODE solution should be monotone, but for some values, it seems to break and go “backward” – rather than sampling increasing alpha values, it samples a value that is below the initial value at some point and then blows up.

I’m not sure why this occurs or how to prevent it…

I can change da\_ds = 0.00001 whenever ds\_da = 0, but this doesn’t really help – the solver never gets past the blow up point.

---

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [March 26, 2020, 9:27am UTC](https://discourse.julialang.org/t/problem-solving-an-inverse-ode-w-differentialequations-jl/36521/3 "2020-03-26T09:27:45Z")

</div>

You compute the flow of `f` as u(x). I assume everything is scalar. To compute the inverse function of u, the vector field `f` must not vanish. In case it does, g = 1/f will change sign through a singularity and you need to chose a solver that does not step after the singularity. Theoretically, the solution blows up at this singularity but the numerical time steps need to be adapted to not cross it.You can enforce the sign of g being constant on a trajectory using a simple implicit solver (I bet).

---

<div class="post-metadata">

**Author:** ![shoshievass](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shoshievass/32/3260_2.png) [@shoshievass](https://discourse.julialang.org/u/shoshievass)\
**Post date:** [March 26, 2020, 12:33pm UTC](https://discourse.julialang.org/t/problem-solving-an-inverse-ode-w-differentialequations-jl/36521/4 "2020-03-26T12:33:24Z")

</div>

Can you say a bit more about what a simple implicit solver would be? (Thank you!)

---

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [March 26, 2020, 12:40pm UTC](https://discourse.julialang.org/t/problem-solving-an-inverse-ode-w-differentialequations-jl/36521/5 "2020-03-26T12:40:34Z")

</div>

Not much I am afraid. `CVODE_BDF()` is quite good in general but I doubt it is positive (meaning it keeps the sign of the input vector). Also, around the singularity, the problem is stiff, so `AutoTsit5(Rosenbrock23())` could be a first try.
