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

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.


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)


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

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)')


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

1 Like

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.


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.

1 Like

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