# Same ODEProblem has differente results when variable is Float64 and Vector{Float64}

**URL:** <https://discourse.julialang.org/t/same-odeproblem-has-differente-results-when-variable-is-float64-and-vector-float64/59477>\
**Category:** Modelling & Simulations\
**Created:** [April 17, 2021, 2:19pm UTC](https://discourse.julialang.org/t/same-odeproblem-has-differente-results-when-variable-is-float64-and-vector-float64/59477 "2021-04-17T14:19:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafael\_FC](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael_fc/32/24130_2.png) [@Rafael\_FC](https://discourse.julialang.org/u/Rafael_FC)\
**Post date:** [April 17, 2021, 2:19pm UTC](https://discourse.julialang.org/t/same-odeproblem-has-differente-results-when-variable-is-float64-and-vector-float64/59477/1 "2021-04-17T14:19:14Z")

</div>

Hello!

I’m having trouble with the following code. As of now it’s working fine, but if I change y0 (Float64) to y0[1] (Vector{Float64}) and dy to dy[1], it returns a wrong result.

Since it’s a simple problem I must be missing something important. Thanks in advance!

```julia
using DifferentialEquations

function teste_step!(dy, y, t)
    b = 50
    dy = (650.0 - 628.0) * (exp((300.0 - t)/b) / (b * (exp((300.0 - t)/b)+1.0)^2.0 ))
    return dy
end

# y0 = zeros(1)
y0 = 628

t_span = (0, 600.0)

prob = ODEProblem(teste_step!, y0, t_span)
sol = solve(prob)

```

---

<div class="post-metadata">

**Author:** ![RobertGregg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/robertgregg/32/22105_2.png) [@RobertGregg](https://discourse.julialang.org/u/RobertGregg)\
**Post date:** [April 17, 2021, 3:10pm UTC](https://discourse.julialang.org/t/same-odeproblem-has-differente-results-when-variable-is-float64-and-vector-float64/59477/2 "2021-04-17T15:10:04Z")

</div>

I think it has something to do with the argument placement in `teste_step!` ?

This seems to give the desired result:

```julia
function teste_step!(dy, y, p, t)
    y0, b, c, d = p
    dy[1] = (c - y0) * (exp((d - t)/b) / (b * (exp((d - t)/b)+1.0)^2.0 ))
    return dy
end

y0 = [628.0]

p = [y0[1], 50.0, 650.0, 300.0]

t_span = (0, 600.0)

prob = ODEProblem(teste_step!, y0, t_span, p)
sol = solve(prob)

```

I put all the important looking constants into a parameters vector (just gave them arbitrary names) and that seems to solve the problem. Maybe someone else can comment on the subtleties of including/excluding a parameters argument. It’s weird that it effects the `Vector{Float64}` case and not the `Float64` case.

---

<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:** [April 17, 2021, 8:08pm UTC](https://discourse.julialang.org/t/same-odeproblem-has-differente-results-when-variable-is-float64-and-vector-float64/59477/3 "2021-04-17T20:08:12Z")

</div>

Yes, either the in-place form or out of place:

```julia
function teste_step(y, p, t)
    b = 50
    (650.0 - 628.0) * (exp((300.0 - t)/b) / (b * (exp((300.0 - t)/b)+1.0)^2.0 ))
end
y0 = 628
t_span = (0, 600.0)
prob = ODEProblem(teste_step!, y0, t_span)
sol = solve(prob)

```

It has to be one of the two. See [Ordinary Differential Equations · DifferentialEquations.jl](https://diffeq.sciml.ai/stable/tutorials/ode_example/)
