# Interpolations: boundary conditions for the second and first derivative

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 = 0
y = 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.

``````julia> f(x) = yitp(x);

julia> lap(x) = Interpolations.hessian(yitp, x);

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