Is there a way to have a cubic interpolation with boundary conditions for the 2nd and 1st derivative?
I am using Interpolations.jl
Here is an example
using Interpolations, Plots
x = 1:10
y = rand(10)
y[1] = 0
y[10] = 0
yitp = CubicSplineInterpolation(x, y, extrapolation_bc = Line())
xfine = 1:0.01:10
plot(xfine, yitp.(xfine))
scatter!(x, y)
My goal is to have zero second and first derivatives in both boundary conditions.
Your condition is already satisfied:
julia> f(x) = yitp(x);
julia> grad(x) = Interpolations.gradient(yitp, x)[1];
julia> lap(x) = Interpolations.hessian(yitp, x)[1];
julia> plot(xfine, [f, grad, lap], label=["f(x)" "f'(x)" "f''(x)"])
1 Like
Of course you are right!
I forgot to mention that I want the first derivative to be zero as well. I edited the question. Thanks!
You can do this if you solve for the coefficients of the B-splines explicitly using their values and derivatives at the gridpoints (as applicable in your problem), but AFAIK Interpolations.jl does not expose B-spline basis functions in its API.
1 Like
See the different prefiltering_system
s in src/b-splines/cubic.jl
. You could add a new system.
1 Like