pythonscipyderivativecubic-spline

Imposing derivatives in Scipy cubic spline


I am using scipy cubic spline ("scipy.interpolate.CubicSpline") for 1-dimensional interpolation. I would like to specify the initial and final derivatives (the "boundary conditions", "bc_type" if I'm not mistaken) for each segment of the spline. However, reading the documentation and looking for examples, I can't understand how that would happen (I am assuming it's possible)

E.g, if I have 4 point to interpolate, I expect to have 3 segments, for each of which I should be allowed the initial and finale first order derivative. However, the only syntax accepted is something like the following:

CubicSpline(x, y, bc_type=((1, <initial_derivative>), (1, <final_derivative>)))

where a single initial and final derivatives are specified (btw, for which segment?)

I have tried to replace the bc_type value with anything that came to my mind, e.g. a list of couples of tuples, one for each point but no syntax different from the one here reported is accepted.

At this point I start to doubt it is possible, but it definitely should: a cubic polynomial expression has 4 degrees of freedom, allowing to "fix" two values and two derivatives

Any information would be really appreciated!


Solution

  • segments, for each of which I should be allowed the initial and finale first order derivative

    This is CubicHermiteSpline or BPoly.from_derivatives. CubicSpline fixes internal slopes to make the interpolant twice differentiable at internal knots.