INTRODUCTION TO SPLINES Applied Numerical Methods with MATLAB fo

adjacent cubic equations are visually smooth. On the surface, it would seem that the third- order approximation of the splines would be inferior to the seventh-order expression. You might wonder why a spline would ever be preferable. Figure 18.1 illustrates a situation where a spline performs better than a higher-order polynomial. This is the case where a function is generally smooth but undergoes an abrupt change somewhere along the region of interest. The step increase depicted in Fig. 18.1 is an extreme example of such a change and serves to illustrate the point. Figure 18.1a through c illustrates how higher-order polynomials tend to swing through wild oscillations in the vicinity of an abrupt change. In contrast, the spline also connects the points, but because it is limited to lower-order changes, the oscillations are kept to a a f x x b f x x c f x x d f x x FIGURE 18.1 A visual representation of a situation where splines are superior to higher-order interpolating polynomials. The function to be fit undergoes an abrupt increase at x = . Parts a through c indicate that the abrupt change induces oscillations in interpolating polynomials. In contrast, because it is limited to straight-line connections, a linear spline d provides a much more acceptable approximation. minimum. As such, the spline usually provides a superior approximation of the behavior of functions that have local, abrupt changes. The concept of the spline originated from the drafting technique of using a thin, flexi- ble strip called a spline to draw smooth curves through a set of points. The process is de- picted in Fig. 18.2 for a series of five pins data points. In this technique, the drafter places paper over a wooden board and hammers nails or pins into the paper and board at the lo- cation of the data points. A smooth cubic curve results from interweaving the strip between the pins. Hence, the name “cubic spline” has been adopted for polynomials of this type. In this chapter, simple linear functions will first be used to introduce some basic con- cepts and issues associated with spline interpolation. Then we derive an algorithm for fitting quadratic splines to data. This is followed by material on the cubic spline, which is the most common and useful version in engineering and science. Finally, we describe MATLAB’s capabilities for piecewise interpolation including its ability to generate splines.

18.2 LINEAR SPLINES

The notation used for splines is displayed in Fig. 18.3. For n data points i = 1, 2, . . . , n, there are n − 1 intervals. Each interval i has its own spline function, s i x . For linear splines, each function is merely the straight line connecting the two points at each end of the interval, which is formulated as s i x = a i + b i x − x i 18.1 where a i is the intercept, which is defined as a i = f i 18.2 and b i is the slope of the straight line connecting the points: b i = f i +1 − f i x i +1 − x i 18.3 18.2 LINEAR SPLINES 431 FIGURE 18.2 The drafting technique of using a spline to draw smooth curves through a series of points. Notice how, at the end points, the spline straightens out. This is called a “natural” spline. where f i is shorthand for f x i . Substituting Eqs. 18.1 and 18.2 into Eq. 18.3 gives s i x = f i + f i +1 − f i x i +1 − x i x − x i 18.4 These equations can be used to evaluate the function at any point between x 1 and x n by first locating the interval within which the point lies. Then the appropriate equation is used to determine the function value within the interval. Inspection of Eq. 18.4 indicates that the linear spline amounts to using Newton’s first-order polynomial [Eq. 17.5] to interpolate within each interval. EXAMPLE 18.1 First-Order Splines Problem Statement. Fit the data in Table 18.1 with first-order splines. Evaluate the function at x = 5. s n ⫺1 x x Interval 1 f x s 1 x x 1 x 2 x i x i ⫹1 x n ⫺1 x n f 1 f i f i ⫹1 f 2 Interval i Interval n ⫺ 1 s i x f n ⫺1 f n FIGURE 18.3 Notation used to derive splines. Notice that there are n − 1 intervals and n data points. TABLE 18.1 Data to be fit with spline functions. i x i f i 1 3.0 2.5 2 4.5 1.0 3 7.0 2.5 4 9.0 0.5 Solution. The data can be substituted into Eq. 18.4 to generate the linear spline functions. For example, for the second interval from x = 4.5 to x = 7, the function is s 2 x = 1.0 + 2.5 − 1.0 7.0 − 4.5 x − 4.5