# How to use monotonic interpolation instead of linear?

**URL:** <https://discourse.julialang.org/t/how-to-use-monotonic-interpolation-instead-of-linear/128958>\
**Category:** General Usage\
**Tags:** question, interpolations\
**Created:** [May 13, 2025, 11:49am UTC](https://discourse.julialang.org/t/how-to-use-monotonic-interpolation-instead-of-linear/128958 "2025-05-13T11:49:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dg.aragones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dg.aragones/32/11275_2.png) [@dg.aragones](https://discourse.julialang.org/u/dg.aragones)\
**Post date:** [May 13, 2025, 11:49am UTC](https://discourse.julialang.org/t/how-to-use-monotonic-interpolation-instead-of-linear/128958/1 "2025-05-13T11:49:14Z")

</div>

Hi everyone,

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

```julia
Φ(ϕ, 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](https://juliamath.github.io/Interpolations.jl/latest/control/), but I’m not sure how to implement them directly in this context.

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

```julia
ϕ = [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!

---

<div class="post-metadata">

**Author:** ![franckgaga](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/franckgaga/32/218241_2.png) [@franckgaga](https://discourse.julialang.org/u/franckgaga)\
**Post date:** [May 13, 2025, 12:33pm UTC](https://discourse.julialang.org/t/how-to-use-monotonic-interpolation-instead-of-linear/128958/2 "2025-05-13T12:33:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [May 13, 2025, 4:12pm UTC](https://discourse.julialang.org/t/how-to-use-monotonic-interpolation-instead-of-linear/128958/3 "2025-05-13T16:12:25Z")

</div>

Using the same notation as in your example, try:

```julia
Φm(ϕ, t) = interpolate(range(0, 7, length(ϕ)), ϕ, SteffenMonotonicInterpolation())(t)

```

---

<div class="post-metadata">

**Author:** ![dg.aragones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dg.aragones/32/11275_2.png) [@dg.aragones](https://discourse.julialang.org/u/dg.aragones)\
**Post date:** [May 14, 2025, 9:29am UTC](https://discourse.julialang.org/t/how-to-use-monotonic-interpolation-instead-of-linear/128958/4 "2025-05-14T09:29:34Z")

</div>

> [@franckgaga](#):
>
> I have used [GitHub - gerlero/PCHIPInterpolation.jl: Monotonic cubic interpolation in Julia](https://github.com/gerlero/PCHIPInterpolation.jl) for monotonic cubic interpolation in the past and it works well (no overshooting + shape-preserving).

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

---

<div class="post-metadata">

**Author:** ![dg.aragones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dg.aragones/32/11275_2.png) [@dg.aragones](https://discourse.julialang.org/u/dg.aragones)\
**Post date:** [May 14, 2025, 9:30am UTC](https://discourse.julialang.org/t/how-to-use-monotonic-interpolation-instead-of-linear/128958/5 "2025-05-14T09:30:15Z")

</div>

> [@rafael.guerra](#):
>
> Using the same notation as in your example, try:
> 
> `Φm(ϕ, t) = interpolate(range(0, 7, length(ϕ)), ϕ, SteffenMonotonicInterpolation())(t)`

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