# Monotone cubic spline interpolation on an irregular grid

**URL:** https://discourse.julialang.org/t/monotone-cubic-spline-interpolation-on-an-irregular-grid/97977
**Category:** Specific Domains
**Tags:** splines
**Created:** [April 26, 2023, 11:10pm UTC](https://discourse.julialang.org/t/monotone-cubic-spline-interpolation-on-an-irregular-grid/97977 "2023-04-26T23:10:31Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![zdenek\_hurak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zdenek_hurak/32/53118_2.png) [@zdenek\_hurak](https://discourse.julialang.org/u/zdenek_hurak)
#### Post date: [April 26, 2023, 11:10pm UTC](https://discourse.julialang.org/t/monotone-cubic-spline-interpolation-on-an-irregular-grid/97977/1 "2023-04-26T23:10:31Z")

</div>

Is there a package in Julia for interpolation using a **monotone** cubic spline interpolation on an **irregular** grid? I seem to be failing to find one.

[Interpolations.jl](http://juliamath.github.io/Interpolations.jl/latest/) does provide monotone option, but only on a regular grid. On irregular grids it only supports linear constant and linear interpolations.

[BSplineKit.jl](https://jipolanco.github.io/BSplineKit.jl/dev/) does provide even higher-order interpolations on irregular grids, but does not offer monotone option.

[Dierckx.jl](https://github.com/kbarbary/Dierckx.jl) does not seem to fit either.

Anything else?

For illustration, here comes some data and cubic spline interpolation, but not monotone, using BSplineKit.jl

```plaintext
M = [0.0, 0.4, 0.8, 0.9, 1.0, 1.2, 1.4, 1.6, 1.8]
η = [0.54, 0.54, 0.54, 0.75, 0.79, 0.78, 0.89, 0.93, 0.93]

using BSplineKit
itp_η = interpolate(M2, η, BSplineOrder(4))
M_range = LinRange(0.0,1.8,100)

scatter(M,η,xlabel="M [-]",ylabel="η")
plot!(M_range,itp_η.(M_range))

```

![spline_julia](https://global.discourse-cdn.com/julialang/original/3X/2/9/290a02bc53a6bf4ff108206cb1293f542d94df3e.png)

And here comes a solution of the same problem in Matlab – this is what I need in Julia:

```matlab
M = [0.0, 0.4, 0.8, 0.9, 1.0, 1.2, 1.4, 1.6, 1.8]
eta = [0.54, 0.54, 0.54, 0.75, 0.79, 0.78, 0.89, 0.93, 0.93]

M_range = linspace(0,1.8,100)
eta_pchip = pchip(M,eta,M_range);

plot(M,eta,'o',M_range,eta_pchip)
xlabel('M')
ylabel('eta')

```

 ![pchip_matlab](https://global.discourse-cdn.com/julialang/original/3X/9/7/97b5e3efa0e652e9c2c5e01ae1fd58af202d33aa.png)

---

<div class="post-metadata">

### Author: ![PeterSimon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petersimon/32/25193_2.png) [@PeterSimon](https://discourse.julialang.org/u/PeterSimon)
#### Post date: [April 27, 2023, 12:16am UTC](https://discourse.julialang.org/t/monotone-cubic-spline-interpolation-on-an-irregular-grid/97977/2 "2023-04-27T00:16:10Z")

</div>

> **[GitHub - gerlero/PCHIPInterpolation.jl: Monotonic cubic interpolation in Julia](https://github.com/gerlero/PCHIPInterpolation.jl)**
>
> Monotonic cubic interpolation in Julia. Contribute to gerlero/PCHIPInterpolation.jl development by creating an account on GitHub.

---

<div class="post-metadata">

### Author: ![zdenek\_hurak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zdenek_hurak/32/53118_2.png) [@zdenek\_hurak](https://discourse.julialang.org/u/zdenek_hurak)
#### Post date: [April 27, 2023, 10:45am UTC](https://discourse.julialang.org/t/monotone-cubic-spline-interpolation-on-an-irregular-grid/97977/3 "2023-04-27T10:45:49Z")

</div>

Thanks. Indeed, this will solve the particular univariate interpolation problem.

I was wondering if a multivariate (bivariate will be fine) version is available elsewhere.
