# Different results for same model with DifferentialEquations.jl

**URL:** <https://discourse.julialang.org/t/different-results-for-same-model-with-differentialequations-jl/34155>\
**Category:** Modelling & Simulations\
**Tags:** diffeq\
**Created:** [February 4, 2020, 10:25am UTC](https://discourse.julialang.org/t/different-results-for-same-model-with-differentialequations-jl/34155 "2020-02-04T10:25:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![moesphere](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/moesphere/32/3348_2.png) [@moesphere](https://discourse.julialang.org/u/moesphere)\
**Post date:** [February 4, 2020, 10:25am UTC](https://discourse.julialang.org/t/different-results-for-same-model-with-differentialequations-jl/34155/1 "2020-02-04T10:25:43Z")

</div>

I am defining two `ODEProblem`s, where they are both the same but the implementation is different. There is a parameter I specify for one problem directly inside the function and for the other problem as an argument to the function.

```julia
function decay1(dx,x,t,p)
    dx[1] = -p[1]*x[1]*0.04*0.00127
end
function decay2(dx,x,t,p)
    dx[1] = -1574*x[1]*0.04*0.00127
end
prob1 = ODEProblem(decay1, [0.25], (0.,8.), [1574])
prob2 = ODEProblem(decay1, [0.25], (0.,8.))

```

When solving, different results are obtained:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/8/6/867e54e34cfd1a07e82255b425f5c959f58c4129.png)

It also does not help to specify e.g. `tstops`. Can anyone help?

---

<div class="post-metadata">

**Author:** ![moesphere](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/moesphere/32/3348_2.png) [@moesphere](https://discourse.julialang.org/u/moesphere)\
**Post date:** [February 4, 2020, 10:41am UTC](https://discourse.julialang.org/t/different-results-for-same-model-with-differentialequations-jl/34155/2 "2020-02-04T10:41:56Z")

</div>

I restarted julia and the `DifferentialEquations.jl` pkg and now both versions are not solved properly.

As a comparison, I solved it with MATLAB:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/7/b/7b430ffc45e1b8f823b35522911a555278172877.png)

---

<div class="post-metadata">

**Author:** ![larsm](https://avatars.discourse-cdn.com/v4/letter/l/9de0a6/32.png) [@larsm](https://discourse.julialang.org/u/larsm)\
**Post date:** [February 4, 2020, 11:03am UTC](https://discourse.julialang.org/t/different-results-for-same-model-with-differentialequations-jl/34155/3 "2020-02-04T11:03:40Z")

</div>

decay1(dx,x,t,p) should be  
decay1(dx,x,p,t)

---

<div class="post-metadata">

**Author:** ![Karajan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/karajan/32/8545_2.png) [@Karajan](https://discourse.julialang.org/u/Karajan)\
**Post date:** [February 4, 2020, 11:24am UTC](https://discourse.julialang.org/t/different-results-for-same-model-with-differentialequations-jl/34155/4 "2020-02-04T11:24:00Z")

</div>

It also looks like you would want to use `decay2` in `prob2` if you want to do a comparison?

---

<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 4, 2020, 2:54pm UTC](https://discourse.julialang.org/t/different-results-for-same-model-with-differentialequations-jl/34155/5 "2020-02-04T14:54:52Z")

</div>

2.0[1] works, which is why the code didn’t error when indexing the scalar for time. For reference, this is the corrected code with @larsm and @karajan’s corrections:

```julia
function decay1(dx,x,p,t)
    dx[1] = -p[1]*x[1]*0.04*0.00127
end
function decay2(dx,x,p,t)
    dx[1] = -1574*x[1]*0.04*0.00127
end
prob1 = ODEProblem(decay1, [0.25], (0.,8.), [1574])
prob2 = ODEProblem(decay2, [0.25], (0.,8.))

```
