Hermite Polynomial Interpolation

← Numerical Methods

Source inspiration: (Mathew 2000-2019).

Description

Hermite polynomial interpolation builds a polynomial that matches both the values and the first derivatives of a function at the nodes. On one interval \([x_0, x_1]\) the data are the values \(y_0, y_1\) and the slopes \(y_0', y_1'\), and the interpolant is a cubic, which Mathews calls a “clamped cubic” because its slopes at the endpoints are fixed. With \(h = x_1 - x_0\) and \(t = (x - x_0)/h\), it is

\[ H(x)=y_0H_{00}(t)+hy_0'H_{10}(t)+y_1H_{01}(t)+hy_1'H_{11}(t), \]

where the cubic Hermite basis functions are

\[ H_{00}(t)=2t^3-3t^2+1, \quad H_{10}(t)=t^3-2t^2+t, \quad H_{01}(t)=-2t^3+3t^2, \quad H_{11}(t)=t^3-t^2 . \]

Each basis function has value or slope 1 for one of the four endpoint conditions and 0 for the other three, so each weighted term supplies one condition; the factor \(h\) converts a slope in \(x\) into a slope in \(t\). Case 2 adds the four terms one at a time.

The method needs \(x_0 \neq x_1\) and the derivatives at the nodes as well as the values. Given those four numbers, Mathews’ theorem states that exactly one cubic satisfies the four conditions. Applied on each subinterval of a mesh, the pieces join with matching value and slope, so the piecewise interpolant is \(C^1\) but in general not \(C^2\): in Case 1 with \(n = 2\), \(H''\) jumps from \(-2/\pi\) to \(2/\pi\) at \(x = \pi\).

The general error result, which Mathews’ module does not state: if \(f \in C^4[x_0, x_1]\), then for each \(x\) in the interval there is a \(\xi\) in \((x_0, x_1)\) with

\[ f(x)-H(x)=\frac{f^{(4)}(\xi)}{4!}\,(x-x_0)^2(x-x_1)^2 , \]

so \(|f(x) - H(x)| \le M_4 h^4/384\), where \(M_4\) bounds \(|f^{(4)}|\) on the interval. The piecewise interpolant’s error is therefore \(O(h^4)\), and every cubic is reproduced exactly. In Case 1, \(f = \sin x\) and \(M_4 = 1\), and the maximum error of every frame lies below \(h^4/384\): 0.425 against 4.06 for \(n = 1\), and 0.000906 against 0.000991 for \(n = 8\).

The \(O(h^4)\) rate is asymptotic, and coarse meshes can mislead: in Case 1 the three doublings of \(n\) divide the maximum error by 2.0, 19.9 and 11.9, not 16. Prescribed slopes can also push the cubic outside the range of the data: in Case 2, \(H\) rises to 2.098 near \(x = 1.205\) and dips to 0.654 near \(x = 2.629\), above the larger endpoint value and below the smaller. When derivatives are not known, they must be estimated, and their errors enter \(H\).

Hermite interpolation in general, matching derivatives of any order at any number of nodes, generalizes both the Taylor polynomial (one node) and the Lagrange polynomial (values only); Cubic Splines need only the values at the knots and two end conditions, and are \(C^2\), and Bézier Curves describe cubic Hermite pieces through control points.

Animations

These animations illustrate the cubic Hermite polynomial, which interpolates both function values and first derivatives at the endpoint nodes. Unlike ordinary (Lagrange) interpolation, which uses only function values, Hermite interpolation also matches the slope at each node.

Julia source scripts that generated these animations are linked under each case.

Mathews’ Hermite polynomial module has no animation. Case 1, piecewise interpolation of \(\sin x\) on \([0, 2\pi]\), is this site’s own example; Case 2 uses the endpoint data of the module’s Example 1. The module’s Examples 2 and 3, a clamped and a natural cubic spline through given knots, are not animated here.

Case 1 — Piecewise cubic Hermite for \(\sin(x)\), refining the mesh

Behavior: Piecewise cubic Hermite interpolation uses \(n\) subintervals, each carrying a cubic polynomial that matches \(f\) and \(f'\) at its two endpoints. The maximum errors in the four frames are 0.425, 0.215, 0.0108 and 0.000906, so the doublings shown divide the error by about 2.0, 19.9 and 11.9. For smooth \(f\) the error is \(O(h^4)\), but these coarse meshes are not yet in the asymptotic range; the ratio approaches \(2^4 = 16\) only on finer meshes (15.0 for \(n = 8 \to 16\), 15.7 for \(16 \to 32\), 15.9 for \(32 \to 64\)).

Julia source

Piecewise cubic Hermite interpolation of sin(x) on 0 to 2pi, showing n=1,2,4,8 intervals; the maximum error falls from 0.425 at n=1 to 0.000906 at n=8

Case 2 — Hermite basis functions building the cubic with \(p(1)=2\), \(p'(1)=1\), \(p(3)=1\), \(p'(3)=2\)

Behavior: The four cubic Hermite basis functions \(H_{00}\), \(H_{10}\), \(H_{01}\), \(H_{11}\) each carry one degree of freedom (a value or derivative at an endpoint). Their weighted combination \(H(x) = y_0 H_{00} + h y_0' H_{10} + y_1 H_{01} + h y_1' H_{11}\) takes the prescribed values and slopes at both endpoints. Here \(h = 2\), so the slope weights are \(h y_0' = 2\) and \(h y_1' = 4\), and the result is \(H(x) = x^3 - \tfrac{23}{4}x^2 + \tfrac{19}{2}x - \tfrac{11}{4}\), the cubic of Mathews’ solution. The frames add the weighted terms one at a time and draw the running sum, with the prescribed tangent lines as short dotted segments; the first two partial sums fall to 0 with zero slope at \(x = 3\), because \(H_{00}\) and \(H_{10}\) have zero value and zero slope there.

Julia source

Running sum of the four weighted Hermite basis terms for the endpoint data p(1)=2, p’(1)=1, p(3)=1, p’(3)=2, adding one term per frame until it forms the complete cubic Hermite polynomial, which meets the dotted tangent segments at both endpoints

References

Mathew, John H. 2000-2019. Numerical Analysis - Numerical Methods Modules. https://web.archive.org/web/20190808102217/http://mathfaculty.fullerton.edu/mathews/n2003/NumericalUndergradMod.html.