If we have derivative data available, it is easy to extend the approach of the preceding subsection to obtain an interpolant with a continuous derivative. For example, we could interpolate f(xn), f´(x,), f(xn+1), f´(xn+1) by the cubic Hermite interpolating
polynomial on [xn,xn+1]. Doing this on each subinterval produces a spline H(x) with a continuous first derivative. Each interval is treated independently, so the bounds (3.17)-(3.20) hold and show that a good approximation is obtained. In the chapter on differential equations, we produce, for successive n, approximations to a function y(x) and its derivative at the points xn, xn + h/2, and xn + h. By forming the quintic (degree
5) Hermite interpolant to these data, a spline with a continuous derivative is formed that approximates y(x) and y´(x) for all x. It is especially important in this context that the interval [xn,xn + h] is handled independently because generally it is only the data
on this interval that are available when interpolation is done.
Let us now consider the representation of data when only f(xi) values are known
and there are not many of them. It has been found that a cubic spline H(x) yields a plot pleasing to the eye if it has a continuous derivative and if it preserves monotonicity. By the latter is meant that if fn < fn+1, then H(x) increases on (xn,xn+1) and if fn > fn+1,
then H(x) decreases. The point is to avoid oscillations that do not appear in the data. A moment’s thought shows that linear splines preserve monotonicity. The problem with them is that their graphs have “corners.” By going to cubits and a continuous first derivative, we avoid the corners. Such a “shape-preserving” interpolant can be constructed along the lines of the cubic Hermite interpolant. The cubits on [ xn - 1, xn]
and [xn,xn+l] both interpolate to fn at xn. If the first derivative is to be continuous, the
first derivatives of the two cubits must have the same value at xn, but now the value of this derivative is an unknown parameter that we choose to achieve monotonicity.
As in (3.11) the cubic is written in the form
for xn < x < xn+1, 1 < n < N - 1. Note that the parameter bn is just the slope of
H(x) at the point xn. Proceeding as in the derivation of (3.12)–(3.14) with the notation
hn = xn+l - xn and = (fn+ 1 - fn) /hn yields
3.5 SPLINE INTERPOLATION 105
(3.30)
These equations result from solving the three interpolation conditions H(xn) = fn,
H(xn+l) = fn+1, and H´(xn+l) = bn+l for the three unknowns an, cn, and dn.
The quantity A, is the slope of the line through (xn, fn) and (xn+1, fn+1). If = 0,
it seems reasonable to force H(x) to be constant on [ xn, xn + 1], that is, to make the slopes
bn = bn+1 = 0. If 0, let us define αn = bn/ and βn = bn+1 To preserve monotonicity it is necessary that the sign of the slope of H(x) at xn and xn+l be the
same as that of Mathematically this is αn > 0, βn > 0.
A sufficient condition on α and β to preserve monotonicity was found by Ferguson and Miller [7]. This was independently discovered by Fritsch and Carlson and pub- lished in the more accessible reference [10]. The argument involves studying H’(x) as a function of αn and βn. This is not too complicated since H’(x) is a quadratic on
(xn,xn + l). A simple condition that guarantees monotonicity is preserved is that αn
and βn lie in the interval [0,3]. There are many formulas for αn and βn that satisfy this restriction. One given in [9] that works pretty well is to use
with
(3.3 1)
(3.32)
for n = 2, 3, . . . , N - 1. If then the slopes change sign at xn. In such
a case we probably should not impose any requirements on the slope of H(x) at xn.
Some people suggest setting bn = 0 when this happens. Others say to go ahead and
use (3.31) as long as there is no division by zero. The heuristic actually chosen can have a significant impact on the behavior of the shape-preserving cubic spline near
those regions where At the ends the simplest rule is to use b1 = and
bN = A better choice is to use the end slope of the quadratic interpolating
the three closest data points (assuming it satisfies the constraint on a and β); other possibilities are given in [9]. With (3.31) and the simple choice for b1 and bN it is easy
to show that the sufficient conditions on αn and βn are satisfied. At the ends α1 = 1
and βN-1 = l, which are certainly in [0,3]. For n = 2, 3, . . . , N - 1,
so αn = and
as desired.
The algorithm for H(x) is very simple. Compute b1 by whatever formula you
choose; for n = 2, 3, . . . , N - 1 take bn = 0 if otherwise compute bn from
(3.31), (3.32). Compute bN. The values cn and dn can be computed from (3.30) for
n = l, . . . , N - 1 either at the same time the bn are computed or in a separate pass over the data. Later in this chapter we provide a routine SVALUE/Spline_value for the evaluation of H(x).
Examination of the algorithm shows that on the subinterval [xn, xn + 1], the spline depends on the data (xn-1, fn-1) , (xn, fn) (xn+l, fn+l) and (xn+2, fn+2). It should be no surprise that it depends on data from adjacent subintervals because the first
Figure 3.8 Data from Exercise 3.30 interpolated by the polynomial P8.
derivatives of the polynomials in adjacent subintervals have to match at the nodes. Although not as local as the cubic splines of the preceding subsection, the construction of the shape-preserving spline on a subinterval requires only data from the subinterval itself and the two adjacent subintervals. As might be expected this H(x) works very well on data that are always monotone but is less successful on oscillatory data. See Huynh [14] for some alternatives.
This spline is not very accurate as h = max(xn+l - xn) tends to zero, but that is
not its purpose. It should be used when the data are “sparse” and qualitative properties of the data are to be reproduced. It is a simple and effective automatic French curve.
Example 3.8. Exercise 3.30 describes a situation in which a shape-preserving spline is particularly appropriate for the approximation of a function f(C). There are only eight data points and it is necessary to approximate the derivative f´(C). The concen- tration C and diffusion coefficient D(C) that make up the function f(C) = CD(C) to be approximated are nonnegative. As can be seen in Figure 3.8, a polynomial inter- polant to f(C) is unsatisfactory because it fails to reproduce this fundamental property. Also, it does not reproduce the monotonicity of the data, casting doubt on its use for approximating f´(C). The shape-preserving spline requires the monotonicity of the interpolant to match that of the data; Figure 3.9 shows that the result is a much more
plausible fit. n