[Math] Piecewise interpolation with derivatives that is also twice differentiable

continuityderivativesinterpolationspline

This question regards the issue of interpolation of one dimension real functions.

If one has a finite set of function values and its corresponding derivatives, one could find unique continuous piecewise cubic function that interpolates those points and has the desired derivatives. This function is at least once-differentiable and in the general case is not twice-differentiable as the second derivative is discontinuous.

On the other hand a cspline-interpolation (with some boundary conditions) of those same points gives a three twice-differentiable function (but does not respect the values of the derivatives at the points).

In other words, the cspline is the only cubic spline that is twice differentiable, which makes me think that if I want a twice-differentiable interpolation with derivatives I will need a higher order interpolation. For example quartic or quintic.

The question is, does interpolation with derivatives that is also twice-differentialy exists already? In practice, should it be quartic or quintic? Is there any reference or numerical implementation for it?

(I experimented with quartic interpolation –for values only– in the past, but as it is well-know, even-number order interpolations produce unstable oscillations making it unsuitable for numerical approximation, which discourages me from trying quartic order interpolation)

Here it is an illustration of function interpolation of values (on the right) and derivative values (on the left)

cubicvscspline

(in this example the value of the derivative is choosen to be 1 in the sample data for illustration only)

Best Answer

If you have $n$ function values and $n$ derivative values, then you have $2n$ pieces of data that you need to interpolate. A $C_2$ cubic spline with breaks at your data points has only (roughly) $n$ degrees of freedom, so clearly it's not going to work.

There are many ways to get what you want. I suggest you start by reading about Hermite interpolation.

A search for "quintic Hermite spline" produced many results, including some that provide code.

If you want to stick with cubics, you will have to introduce additional breaks to get the additional degrees of freedom that you need. Maybe using two cubic pieces in between each pair of data points would work. As long as you have the right number of degrees of freedom, you will probably get a linear system of equations that you can solve. I have never tried this, but it sounds promising.

Another approach: use cubic spline interpolation (or some other technique) to calculate second derivative values at each data point. Then, on each segment, you have function values, and first and second derivative values at each end -- a total of 6 pieces of data. Interpolate these 6 pieces of data with a Hermite quintic polynomial. The end result is a $C_2$ piecewise quintic spline.