Cubicspline Interpolation where domain is non-uniform array

With Interpolations.jl, for cubic spline interpolation on irregular grid:

using Interpolations

f(x) = 5e-3*x^2

# input data to interpolate on non-uniform grid
times = [1.,20,100,150,200,238,300,400,540,600,707,800,1000,1200,1400]
vals = f.(times)

# Interpolations with parametric cubic splines
t = LinRange(0,1,length(times))
itp = Interpolations.scale(interpolate(hcat(times,vals), (BSpline(Cubic(Natural(OnGrid()))), NoInterp())), t, 1:2)
ti = 0:.01:1
timesitp, valsitp = [itp(t,1) for t in ti], [itp(t,2) for t in ti]

# Plot results
scatter(times,vals, legend=:topleft, label="f(t) = 5e-3*t^2")
plot!(timesitp, valsitp, xlabel="times", ylabel="vals", label="Interpolations' parametric spline")

Interpolations_parametric_splines_irregular_grid

4 Likes