# Generating zero-isoclines for a coupled ODE

**URL:** <https://discourse.julialang.org/t/generating-zero-isoclines-for-a-coupled-ode/35070>\
**Category:** General Usage\
**Tags:** diffeq\
**Created:** [February 24, 2020, 12:56pm UTC](https://discourse.julialang.org/t/generating-zero-isoclines-for-a-coupled-ode/35070 "2020-02-24T12:56:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Libbum](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/libbum/32/3935_2.png) [@Libbum](https://discourse.julialang.org/u/Libbum)\
**Post date:** [February 24, 2020, 12:56pm UTC](https://discourse.julialang.org/t/generating-zero-isoclines-for-a-coupled-ode/35070/1 "2020-02-24T12:56:30Z")

</div>

Hi All,

This seems like it should be a simple problem to solve, but I’ve scoured the documentation of DifferentialEquations.jl and can’t seem to identify anything specifically relating to my issue.

For a simple coupled ODE of the form

\frac{dA}{dt} = f(A,B,t)\\ \frac{dB}{dt} = g(A,B,t)

I’ve set up my Julia implementation like so:

```julia
u0 = [20.0, 2.6]; #Initial populations
p = [ib, r, nutr, H₁, H₂, H₃, H₄];
tspan = (0.0,364.0);
prob = ODEProblem(coupled_ode!,u0,tspan,p);
sol = solve(prob);

```

I want to generate a state space diagram over A \in [0,20], B \in [0,120], showing zero isoclines for both parameters (i.e. traces over the state space when \frac{dA}{dt} = 0 or \frac{dB}{dt} = 0).

There are a few steady state solutions to this problem, that I can obtain using `prob = SteadyStateProblem(coupled_ode!,u0,p)` in place of the `ODEProblem`, but I can’t seem to find a concise/efficient solution for generating the zero-isoclines at all.

Currently I’ve looked into using two `for` loops altering `u0 = [A0[i], B0[j]]` to build the state space.  
I can use `sol(0.0, Val{1})` for each of the solutions to find the derivative values when t=0, but of course I’m looking for the the time when `Val{1} == 0`.  
Perhaps I can generate a large search range over time and find the index of the minimum of the derivative?

```julia
search = 0.0:0.001:5000.0;
findmin(abs.(hcat(sol(search,Val{1}).u...)),dims=2)

```

but this seems like overkill, and doesn’t necessarily assure that A’ = 0 has been found either.

It’s highly likely I’ve either missed a simple method or misunderstood something conceptually. Any hints or suggestions on this would be appreciated.

---

<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 24, 2020, 2:18pm UTC](https://discourse.julialang.org/t/generating-zero-isoclines-for-a-coupled-ode/35070/2 "2020-02-24T14:18:20Z")

</div>

@rveltz I assume there’s a nice way to do this with [[PseudoArcLengthContinuation.jl](https://rveltz.github.io/PseudoArcLengthContinuation.jl/dev/#PseudoArcLengthContinuation.jl-1)]([https://rveltz.github.io/PseudoArcLengthContinuation.jl/dev/](https://rveltz.github.io/PseudoArcLengthContinuation.jl/dev/)) ?

---

<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:** [February 24, 2020, 9:37pm UTC](https://discourse.julialang.org/t/generating-zero-isoclines-for-a-coupled-ode/35070/3 "2020-02-24T21:37:31Z")

</div>

you can try

```julia
using PseudoArcLengthContinuation
const PALC = PseudoArcLengthContinuation

h = (A,B) -> [A^2-B]
contparams = ContinuationPar(pMin = -1., pMax = 1.,
                ds = 0.001) # set ds = -0.001 for the other part of the manifold
nullcline, _,_ = continuation( (x,p)->h(x[1],p),
                [0.], #value of A for B = 0
                0., # initial value of B
                contparams; printSolution = (x, p) -> x[1])

plot(nullcline.branch[2,:], nullcline.branch[1,:])

```

Another idea: [https://github.com/bachrathyd/MDBM.jl](https://github.com/bachrathyd/MDBM.jl)

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [February 25, 2020, 4:04am UTC](https://discourse.julialang.org/t/generating-zero-isoclines-for-a-coupled-ode/35070/4 "2020-02-25T04:04:50Z")

</div>

If f and g are independent of t (which they must be, otherwise I don’t think the concept of zero-isocline makes sense?) then you are just asking to draw **contours** or **level sets** of the functions f and g:

```julia
using Plots
f(x, y) = x^2 + 2y^2
g(x, y) = x - 2y^3

myrange = -2:0.01:2

contour(myrange, myrange, f, levels=[0])
contour!(myrange, myrange, g, levels=[0])

```

---

<div class="post-metadata">

**Author:** ![Libbum](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/libbum/32/3935_2.png) [@Libbum](https://discourse.julialang.org/u/Libbum)\
**Post date:** [February 25, 2020, 9:30am UTC](https://discourse.julialang.org/t/generating-zero-isoclines-for-a-coupled-ode/35070/5 "2020-02-25T09:30:16Z")

</div>

Thanks everyone.

@dpsanders, you are correct. It’s my conceptual issue with this problem that was the killer. Thanks!

@ChrisRackauckas & @rveltz: will be interesting to take a look at the packages you suggested for other problems I have in the future - thank you. This one however didn’t even need diffeq in the end (other than for identification of the solutions to the `SteadyStateProblem()`.
