Hi everyone, hope this is the right channel. New to Julia, long-time R user. I am

Hi everyone, hope this is the right channel. New to Julia, long-time R user. I am looking for the equivalent of R’s approxfun in Julia and its use in ODE systems (as in here: https://tpetzoldt.github.io/deSolve-forcing/deSolve-forcing.html#example_1:_time-varying_input). Is there a simple code example/tutorial available online for when you have an ODE with a time-varying input modelled with an approx function? TIA

Note that the original poster on Slack cannot see your response here on Discourse. Consider transcribing the appropriate answer back to Slack, or pinging the poster here on Discourse so they can follow this thread.
(Original message :slack:) (More Info)

Take a look at the package Interpolations. I think it does what you need.

2 Likes

Thanks Paulo, I was also recommended to look into GitHub - PumasAI/DataInterpolations.jl: A library of data interpolation and smoothing functions and GitHub - JuliaApproximation/ApproxFun.jl: Julia package for function approximation

1 Like

Note that if you plug interpolated data into an ODE solver (using e.g. Interpolations.jl or Dierckx.jl), you should tell the solver where the knots of your interpolation are (using tstops) so that it knows to expect discontinuous derivatives. (Or you could use a smooth fit.)

See e.g. Accuracy for discontinuous right hand side · Issue #245 · SciML/DifferentialEquations.jl · GitHub

2 Likes