# Issues when ODE solver and interpolations.jl are used together or something else perhaps?

**URL:** <https://discourse.julialang.org/t/issues-when-ode-solver-and-interpolations-jl-are-used-together-or-something-else-perhaps/44348>\
**Category:** General Usage\
**Tags:** ode\
**Created:** [August 5, 2020, 3:44pm UTC](https://discourse.julialang.org/t/issues-when-ode-solver-and-interpolations-jl-are-used-together-or-something-else-perhaps/44348 "2020-08-05T15:44:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cbasile21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cbasile21/32/13072_2.png) [@cbasile21](https://discourse.julialang.org/u/cbasile21)\
**Post date:** [August 5, 2020, 3:44pm UTC](https://discourse.julialang.org/t/issues-when-ode-solver-and-interpolations-jl-are-used-together-or-something-else-perhaps/44348/1 "2020-08-05T15:44:51Z")

</div>

There was an unexpected behavior I noticed when using ode solver and itp that I would appreciate your help.

I am sharing a problem where u[1] can be a assign to a value like 3000 , where the final solution was the value expected, however, when u[1] is assigned to the value the interpolant object predicts, the final solution is not what is expected. For a moment I thought that the interpolant is being ignored, but when printing the values , it does seem to be evaluating it , but the final solution does not reflect those values that u[1] was, is there something I am missing, I am using julia 1.4 v also. Any recommendation / or explanation of what is happening will be appreciated.

scenario one : u[1]= constant, scenario two: u[1]= itp(t) ( the latter is the unexpected behavior I mentioned above)

Again thank you very much.

Christian

```julia
using DifferentialEquations
using Sundials
using Interpolations

t= collect(0.0:1.0:6.0)
y= [525.42,577.87,560,536,526,427,390];

#This Interpolates
knots = (t,)
itp = interpolate(knots, y, Gridded(Linear()))

function ode_functionminie(du,u, p,t)

du[1] = 0

value= itp(t)

#u[1]=value;
u[1]=3000;

if t >1.0 && t <=3
    println("value vs u", (value, u[1]))
end

end
p=[]
uo_e=[30]
tol= 1e-6
t_start= 0.0;
sim_time_e= 6.0;
prob = ODEProblem(ode_functionminie,uo_e,(t_start,sim_time_e), p)
sol = solve(prob, abstol=tol, reltol=tol,CVODE_BDF(), dtmax=0.1, tstops=[1.0,4.0]);
times= 0.0:1.0:6.0;
time_output, output= collect(times), sol(times).u
final_output= Array(sol(times)')

println("Done")

```

---

<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:** [August 5, 2020, 3:51pm UTC](https://discourse.julialang.org/t/issues-when-ode-solver-and-interpolations-jl-are-used-together-or-something-else-perhaps/44348/2 "2020-08-05T15:51:23Z")

</div>

> [@cbasile21](#):
>
> `u[1]=3000;`

This doesn’t make sense. Why not just leave that out of the differential equation? It’s not a derived variable.

---

<div class="post-metadata">

**Author:** ![cbasile21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cbasile21/32/13072_2.png) [@cbasile21](https://discourse.julialang.org/u/cbasile21)\
**Post date:** [August 5, 2020, 4:02pm UTC](https://discourse.julialang.org/t/issues-when-ode-solver-and-interpolations-jl-are-used-together-or-something-else-perhaps/44348/3 "2020-08-05T16:02:40Z")

</div>

I see your point about taking out of it Chris. I know the example I shared is an extreme case, but the final sol does have the 3000 populated, but it does not have the values of the itp interpolant , when I do instead u[1] = itp(t) , ( instead of 3000). so I simply raised to see why this happens. When I print the values of itp inside the ode it does print the corrected values, so I am not sure why in the case of the interpolant why the final sol ignored those values.

Thanks

---

<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:** [August 5, 2020, 4:21pm UTC](https://discourse.julialang.org/t/issues-when-ode-solver-and-interpolations-jl-are-used-together-or-something-else-perhaps/44348/4 "2020-08-05T16:21:46Z")

</div>

> [@cbasile21](#):
>
> when I do instead u[1] = itp(t) , ( instead of 3000). so I simply raised to see why this happens

the error estimates are probably going haywire or something. This behavior just isn’t expected. Even if it is `itp(t)`, you still don’t need to put it into the ODE.

---

<div class="post-metadata">

**Author:** ![cbasile21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cbasile21/32/13072_2.png) [@cbasile21](https://discourse.julialang.org/u/cbasile21)\
**Post date:** [August 5, 2020, 4:27pm UTC](https://discourse.julialang.org/t/issues-when-ode-solver-and-interpolations-jl-are-used-together-or-something-else-perhaps/44348/5 "2020-08-05T16:27:37Z")

</div>

Thank you Chris for the help and explaining that! Helpful to me , I will probably do this.

Christian
