Using CubicSplineInterpolation on a vector (not on a Lazy Array)

I have a small problem that I can’t seem to solve regarding the use of CubicSplineInterpolation on a vector (rather than lazy array).

using Interpolations, Plots
function spline_interpolation2()
    #mygrid = range(-1.0, stop=1.0, length=5)  # lazy array representation
    mygrid = collect(range(-1.0, stop=1.0, length=5))  # vector representation
    mypoints = abs.(mygrid)

    #itp = interpolate((mygrid,),mypoints, Gridded(Constant()))
    #itp = interpolate((mygrid,),mypoints, Gridded(Linear()))
    #itp = LinearInterpolation(mygrid, mypoints, extrapolation_bc=Flat())
    #itp = LinearInterpolation(mygrid, mypoints)
    #itp = Spline1D(mygrid, mypoints, k=3, bc="nearest", s=0.0)
    itp = CubicSplineInterpolation(mygrid, mypoints; bc=Line(OnGrid()), extrapolation_bc=Throw())

    # interpolate at any point
    myfinergrid = range(-1.0, stop=1.0, length=100)

    plot(myfinergrid, [abs.(myfinergrid) itp.(myfinergrid)], label=["abs" "interplotion" ])

When using Spline1D I get what I want. CubicSplineInterpolation returns a method error, though.

FYI: LinearInterpolation works, but it is not what I want to use. I am interested in Cubic Interpolation.

Thanks for the help.

Cubic Splines is not yet implemented on custom grids, see

1 Like

I see. Thanks. I will stick to Spline1D for the moment then. supports this.

Thanks at @stevengj. I indeed resorted to Dierckx.jl