# Piecewise interpolation with derivatives that is also twice differentiable

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)

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

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.

• My problem with quintic is that it suddenly will have too many degrees of freedom. Actually, your recommendation of adding break breakpoints to cubic splines sounds reasonable, although the exact location of the extra breakpoints will be somewhat arbitrary, (e.g. midpoint). I don't understand the last part of your answer (...and second derivatives...), I only have the value and the first derivative.
– alfC
Sep 7, 2013 at 6:22
• > I only have the value and the first derivative -- Understood. So, to use the approach I suggested, you have to fabricate some second derivatives somehow. One easy way is to say that $y''_i = (y'_{i+1} - y'_{i-1})/(x_{i+1} - x_{i-1})$. Or, alternatively. compute a $C_2$ cubic spline, and use its second derivatives. Sep 7, 2013 at 6:36

1) does interpolation with derivatives that is also twice-differentialy exists already? In practice, should it be quartic or quintic? --- sure, for instance it is possible to build a generalized Hermite interpolating spline of any predefined degrees of smoothness (J.Duchon papers, etc)

2) Is there any reference or numerical implementation for it? --- such numerical implementation existed in the past.