How to use monotonic interpolation instead of linear?

Hi everyone,

I’ve been using a simple interpolation function like this:

Φ(ϕ, t) = interpolate((0 : 7/length(ϕ) : 7,), vcat(0, ϕ), Gridded(Linear()))(t)

This uses linear interpolation with Interpolations.jl, and it works well for what I need so far.

However, I’d like to switch to a monotonic cubic interpolation, specifically using either the Fritsch-Butland or Steffen methods, as they avoid overshooting and better preserve the shape of the data. I found references to these in Interpolations.jl documentation, but I’m not sure how to implement them directly in this context.

To make things concrete, here’s a small test case:

ϕ = [1.0, 3.0, 2.5, 4.0]
t_test = 3.5

I’d like to evaluate Φ(ϕ, t_test) using both linear interpolation (as above), and monotonic cubic interpolation.

Could someone show how to adapt the function to use these monotonic interpolators?

Thanks a lot for the help!

I have used GitHub - gerlero/PCHIPInterpolation.jl: Monotonic cubic interpolation in Julia for monotonic cubic interpolation in the past and it works well (no overshooting + shape-preserving).

2 Likes

Using the same notation as in your example, try:

Φm(ϕ, t) = interpolate(range(0, 7, length(ϕ)), ϕ, SteffenMonotonicInterpolation())(t)
2 Likes

Thank you! I didn’t know about that package. I’ll give it a try!

1 Like

That’s perfect, super clear and exactly what I was looking for. Thanks a lot!

1 Like