One of the advantages of cubic Hermite splines is that their interval interpolation formula is an explicit function of gradients at knot-points:

where the Hermite bases are:

(For now, I will be using the unit-interval form of the interpolation, where t runs from 0 to 1 on each interval. I will also discuss the non-uniform interval equations below)

This formulation allows one to explicitly specify the interpolation gradient at each knot point, and to choose from various gradient assignment policies, for example those listed here, even supporting policies for enforcing monotonic interpolations.

One important caveat with cubic Hermite splines is that although the gradient is guaranteed to be continuous, it is not guaranteed to be smooth (that is, differentiable) across the knots (it is of course smooth inside each interval). Therefore, another useful category of gradient policy is to obtain gradients such that is also smooth across knots.

(I feel sure that what follows was long since derived elsewhere, but my attempts to dig the formulation up on the internet failed, and so I decided the derivation might make a useful blog post)

To ensure smooth gradient across knot points, we want the 2nd derivative to be equal at the boundaries of adjacent intervals:

or substituting the 2nd derivative of the basis definitions above:

Observe that t = 1 on the left hand side of this equation, and t = 0 on the right side, and so we have:

which we can rearrange as:

Given n knot points, the above equation holds for j = 1 to n-2 (using zero-based indexing, as nature intended). Once we define equations for j = 0 and j = n-1, we will have a system of equations to solve. There are two likely choices. The first is to simply specify the endpoint gradients and directly, which yields the following tri-diagonal matrix equation:

The second common endpoint policy is to set the 2nd derivative equal to zero – the “natural spline.” Setting the 2nd derivative to zero at the left-end knot (and t = 0) gives us:

Similarly, at the right-end knot (t = 1), we have:

And so for a natural spline endpoint policy the matrix equation looks like this:

The derivation above is for uniform (and unit) intervals, where t runs from 0 to 1 on each knot interval. I’ll now discuss the variation where knot intervals are non-uniform. The non-uniform form of the interpolation equation is:

Taking and applying the chain rule, we see that 2nd derivative equation now looks like:

Applying a derivation similar to the above, we find that our (interior) equations look like this:

and natural spline endpoint equations are:

And so the matrix equation for specified endpoint gradients is:

And the equation for natural spline endpoints is: