Interactive Educational Modules in
Scientific Computing

Piecewise Cubic Interpolation

This module illustrates piecewise cubic interpolation, both Hermite cubic and cubic spline. Given a set of data points (ti, yi)i = 1,…,n, with t1 < t2 < · · · < tn, a piecewise cubic interpolant is composed of a different cubic polynomial in each subinterval [ti, ti+1]. There are sufficiently many degrees of freedom in choosing the cubic polynomials that the resulting piecewise cubic not only can be made continuous, but it can also have a continuous first derivative (i.e., Hermite cubic) and continuous second derivative (i.e., cubic spline). Indeed, even the latter requirement still leaves two degrees of freedom remaining, and different choices for these result in different types of cubic splines.

The user chooses a set of data points either by selecting one of two preset examples or by specifying an arbitrary set of points. For the latter, select Choose Points and then click on the graph to specify the location of each point, followed by Apply. At least four points are required to define a piecewise cubic interpolant. To prevent points from being too close to each other, no new point can be selected within the shaded buffer zone around each existing point. After the points have been specified, a piecewise cubic interpolant is drawn through the data points. The user can choose the type of piecewise cubic interpolant, and in some cases can control additional parameters related to the type of interpolant. Except for the monotonic Hermite cubic interpolant, the available choices are all cubic splines. After an interpolant has been drawn, another point can be added by selecting Add Point and then clicking on the graph at the desired location, whereupon the resulting new interpolant is drawn.

A periodic cubic spline is most appropriate for periodic data, but for nonperiodic data the first and second derivatives can still be equated at the endpoints, and this strategy is implemented here. Similarly, a monotonic Hermite cubic interpolant is most appropriate for monotonic data, but for nonmonotonic data, the interpolant can be forced to be monotonic on each subinterval in which the data are montonic, as implemented here.

Reference: Michael T. Heath, Scientific Computing, An Introductory Survey, 2nd edition, McGraw-Hill, New York, 2002. See Section 7.4; Example 1 is shown in Figures 7.9 and 7.10 on page 329, and Example 2 is given in Computer Problem 7.5 on page 337.

Developers: Evan VanderZee and Michael Heath