• No results found

CONTINUOUS SECOND DERIVATIVE

DISCONTINUOUS AND CONTINUOUS SPLINES

CONTINUOUS SECOND DERIVATIVE

The last spline considered has a historical origin. To draw smooth curves through data points, drafters once used thin flexible strips of plastic or wood called splines. The

3.5 SPLINE INTERPOLATION 107

Figure 3.9 Data from Exercise 3.30 interpolated by the shape-preserving spline.

data were plotted on graph paper and a spline was held on the paper with weights so that it went over the data points. The weights were constructed so that the spline was free to slip. The flexible spline straightened out as much as it could subject to the constraint that it pass over the data points. The drafter then traced along the spline to get the interpolating curve. The smooth cubic spline presented here is the solution of a linearized model of the physical spline. The physical analogy already points out something very different about this spline—its value at any point depends on all the data.

To construct the smooth cubic spline, we write once again

(3.33) on each [xn,xn+1], 1 < n < N - 1. There are 4(N - 1) free parameters to be determined.

The interpolation conditions require that for 1 < n < N - 1

(3.34) giving 2N - 2 conditions. There remain 2N - 2 degrees of freedom that can be used to make S(x) smooth on all of [x1,xN]. Note that (3.34) automatically ensures that S is continuous on [xl,xN]. For S´ to be continuous at interior knots,

(3.35) This provides N - 2 conditions, so N degrees of freedom remain. For S´´ to be contin- uous at interior knots,

(3.36) for another N - 2 conditions. Exactly 2 degrees of freedom are left. This is not enough to achieve a continuous S”’ (this is undesirable anyway since the resulting S would be a cubic polynomial rather than a piecewise cubic polynomial). There are many possibilities for the two additional constraints.

Figure 3.10 Graphs of S(x) and S´´(X) from Example 3.9.

Type 1. S´(x1) = f´(x1),S´(xN) = f´(xN).

Type 2. S´´(x1) = S´´(xN) = 0.

Type 3. S´´(x1) = f´´´(xl),S´´(xN) = f´´´(xN).

Type 4. S´´(x1) = S´(xN),S´´(x1) = S´´(xN).

For obvious reasons these conditions are known as end conditions. The second condi- tion is the one leading to a spline that approximates the physical spline. The physical spline straightens out as much as possible past the last data point on each end, so it be- comes a straight line with zero second derivative. In the form stated, the first and third conditions are useful only if extra information is available about f. However, the exact slopes or curvatures needed here are often replaced by polynomial approximations in practice. The last end condition is appropriate when f is periodic with period xN-x1

because then f(x) and all its derivatives have the same values at x1 and xN.

Example 3.9. Let

It is easily verified that S is in C2[0,2], and satisfies the interpolation conditions S(0) = 2, S(1) = 1, S(2) = 4 and the end conditions S´(0) = 1, S´(2) = 13. Graphs of S and S´´ are shown in Figure 3.10. Note that the graph of S appears very smooth, while that

for S´´ has an obvious corner at the knot x = 1. n

Returning to the earlier characterization of S(x), we had 4N - 4 conditions on the 4 N - 4 unknowns given by (3.33). A matrix method is in order, but some preliminary manipulations will simplify the task considerably. On each interval [xn,xn+1]

3.5 SPLINE INTERPOLATION 109

(3.38) The interpolation conditions immediately yield, from (3.33),

an = fn, 1 < n < N - 1, (3.39)

and also fn+1 = an + bnhn + cnh2n + dnh3n which can be rewritten as bn = (fn+l - fn)/hn - cnhn-dnh

2

n, 1 < n < N -1. (3.40)

This eliminates half of the unknowns. The continuity condition (3.36) on S´´ says that 2cn = 2cn-l + 6dn-1hn-1 or [with cN = S´´(xN)/2]

(3.41) Only formulas for c1, . . . , cN remain. They are provided by the two end conditions

and the global continuity of S´. From (3.35) and (3.37) it follows that bn = bn-1 +

2cn-1hn-l + 3dn-1h2n-1 for 2 < n < N - 1. Substitution in (3.40) and (3.41) gives

for 2 < n < N - 1 and a rearrangement yields

(3.42) Only the first type of end conditions (prescribed slopes) is taken up here. From (3.33), (3.40), and (3.41), so 2hlc1 + h1c2 = 3 {(f2 - f1)/h1 - f´(x1)}. Similarly, f´(xN) = S´(xN) leads to (3.43) (344) Equations (3.41)–(3.44) provide a set of N equations in the N unknowns c1, c2, . . ., cN.

Such a matrix is called tridiagonal (all the nonzero entries lie in three diagonal bands), symmetric (the entry in row i of column j equals the one in row j of column i ), and diagonally dominant (in each column the magnitude of the entry on the main diagonal exceeds the sum of the magnitudes of the other entries in the column). We saw in Section 2.5.2 that for such matrices the system has a unique solution for each right- hand side and the solution can be found accurately using Gaussian elimination without any row interchanges.

Theorem 3.4. Given the knots x1 < x2 < ··· < xN and fn = f(xn), 1 < n < N, there exists one and only one function S(x) that satisfies each of the following:

1. S(x) is a cubic polynomial in each [xn,xn+1], 1 < n < N - 1. 2. S(x) is in C2[x1,xN].

3. S(xn) = fn, 1 < n < N.

4. S´(x1) = f´(x1),S´(xN) = f´(xN).

For this choice of end conditions, S(x) is called the complete cubic spline. The coefficient matrix has the same structure for end conditions of types (2) and (3) and similar results are true for them. With the choice of type (2), S(x) is called the natural cubic spline. The matrix has a somewhat different form for the periodic end conditions, type (4), but similar results are true and the spline can be computed conveniently.

Because the smooth cubic spline depends on all the data, a system of linear equa- tions must be solved to construct it. Often large data sets are to be fit, and if the solution of the linear equations were anything like as expensive as for a general sys- tem, the approach would be impractical. Fortunately, the system is very special and it is practical to interpolate data involving thousands of nodes. First the tridiagonal system (3.42)–(3.44) must be solved. Since it is not necessary to do row interchanges in this case, the elimination formulas are very simple. For reinforcement, let us work through the details.

To eliminate the first entry in row 2, multiply row 1 by and subtract. The re- maining equations have the same pattern, so at the kth stage multiply row k by the current and subtract from row k + 1. The algorithm for elimination and modifi- cation of the right-hand side is

for k = 2, 3, . . . , N begin

3.5 SPLINE INTERPOLATION 111

Back substitution is also easy:

The whole computation costs only 3N – 3 multiplications and 2N – 1 divisions. Once the c vector is known, vector d can be computed from (3.41), and vector b from (3.40). The storage required is a small multiple of N rather than the N* needed for a general system of equations.

We finish this section by discussing some of the mathematical properties of the complete cubic interpolator spline S(x). The physical spline used by drafters can be modeled using the theory of thin beams. In general, the curvature K(X) of a function

f(x) is

and in this theory the expression is linearized to K(x) |f"(x)|. When (S'(x))2 << 1,

the quantity can be regarded as a measure of the curvature of the spline

S(x). We prove now that in this measure, any smooth interpolating function satisfying the type (1) end conditions must have a curvature at least as large as that of S(x). This is sometimes referred to as the minimum curvature property of the complete cubic spline. The same result is true for the natural cubic spline when the requirement that the interpolant satisfy the type (1) end conditions is dropped.