# How to set a systems of ODEs to zero with Boundary Value Problem?

**URL:** <https://discourse.julialang.org/t/how-to-set-a-systems-of-odes-to-zero-with-boundary-value-problem/53771>\
**Category:** Optimization (Mathematical)\
**Tags:** question, package, diffeq, numerics\
**Created:** [January 22, 2021, 9:19am UTC](https://discourse.julialang.org/t/how-to-set-a-systems-of-odes-to-zero-with-boundary-value-problem/53771 "2021-01-22T09:19:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luigi\_Marongiu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luigi_marongiu/32/7909_2.png) [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)\
**Post date:** [January 22, 2021, 9:19am UTC](https://discourse.julialang.org/t/how-to-set-a-systems-of-odes-to-zero-with-boundary-value-problem/53771/1 "2021-01-22T09:19:20Z")

</div>

I have a system of ordinary differential equations (ODEs) that model the interaction between a bacterium and phage:

```julia
dN/dt = μN(1-(N+I)/κ) -φNP -ωN
dI/dt = φNP -ηI -ωI
dP/dt = βηI -φNP -ωP

```

I am looking for the values of P that bring N to zero in a stable term. As is, the addition of P to the system reduces N, but then N and P go into oscillation and then they reach an equilibrium where N \>\> 0.

 ![treatment_1](https://global.discourse-cdn.com/julialang/original/3X/f/f/ff0daf55161a086c4d09cdf4047387a55c4a17c2.png)  
I understand this might be a problem for [Boundary Value Problem](https://diffeq.sciml.ai/stable/types/bvp_types/) but how do I set the system?  
I understand BVP requires a function to work upon, which probably is the dN/dt I indicated, hence:

```julia
function fun!(du, u, p, t) 
    μ, κ, φ, ω = p
    #=
    du[1] = susceptible
    =#
    du[1] = ((μ * u[1]) * (1 - ((u[1]+u[2])/κ))) - (φ * u[1] * u[3]) - (ω * u[1])
end

```

(do I need to include dI/dt?) This is derived from the system of ODEs I set for the model:

```julia
function modelFun!(du, u, p, t) # base infection model with logistic term
    μ, κ, φ, ω, η, β = p
    #=
    du[1] = susceptible
    du[2] = infected
    du[3] = phages
    =#
    du[1] = ((μ * u[1]) * (1 - ((u[1]+u[2])/κ))) - (φ * u[1] * u[3]) - (ω * u[1])
    du[2] = (φ * u[1] * u[3]) - (η * u[2]) - (ω * u[2])
    du[3] = (β * η * u[2]) - (φ * u[1] * u[3]) - (ω * u[3])
end

```

I then need an implicit function bc, but what would that be?  
How is the setting of this kind of problem?  
The parameters I used are:

```julia
κ = 2.2 ⋅ 10^7
μ = 0.47
φ = 10^-9
β = 50
η = 1.0
ω = 0.05
N0 = 1.0*10^7
P0 = 2*10^8

```

Thank you

---

<div class="post-metadata">

**Author:** ![Luigi\_Marongiu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luigi_marongiu/32/7909_2.png) [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)\
**Post date:** [January 24, 2021, 6:58am UTC](https://discourse.julialang.org/t/how-to-set-a-systems-of-odes-to-zero-with-boundary-value-problem/53771/2 "2021-01-24T06:58:06Z")

</div>

I tried with:

```julia
julia> function bc!(residual, u, p, t)
           residual[1] = (u[1][1] - N0)/N0 # keep the starting value constant
           residual[2] = (u[1][2] - I0)/I0 # keep the starting value constant
           residual[3] = u[end][1]/N0 # u[end][1] should be zero at the final timestep
       end
bc! (generic function with 1 method)

julia> N0 = 1.0*10^7
1.0e7

julia> I0 = 1E5
100000.0

julia> P0 = 2*10^8
200000000

julia> pGuess = 1.0
1.0

julia> tspan = (0.0,1500.0)
(0.0, 1500.0)

julia> bvp0 = BVProblem(modelFun!, bc!, [N0,I0,P0], tspan)
BVProblem with uType Array{Float64,1} and tType Float64. In-place: true
timespan: (0.0, 1500.0)
u0: [1.0e7, 100000.0, 2.0e8]

julia> sol0 = solve(bvp0, Shooting(Vern7()), dtmin=0.01, dt=0.5)
ERROR: MethodError: no method matching iterate(::DiffEqBase.NullParameters)
Closest candidates are:
  iterate(::Base.EnvDict) at env.jl:119
  iterate(::Base.EnvDict, ::Any) at env.jl:119
  iterate(::JuliaInterpreter.ExprSplitter) at /home/gigiux/.julia/packages/JuliaInterpreter/LBEYA/src/construct.jl:535
  ...

```
