9 10 Curve Fitting and Interpolation Part 2
9 10 Curve Fitting and Interpolation Part 2
Interpolation
Cubic & Quadratic Spline Interpolation
FIGURE 18.14
A visual representation of a situation where the splines are superior to higher-order
interpolating polynomials. The function to be fi t undergoes an abrupt increase at x 5 0. Parts
(a) through (c) indicate that the abrupt change induces oscillations in interpolating
polynomials. In contrast, because it is limited to third-order curves with smooth transitions, a
linear spline (d) provides a much more acceptable approximation.
where mi is the slope of the straight line connecting the points:
(18.27)
These equations can be used to evaluate the function at any point between
x0 and xn by first locating the interval within which the point lies. Then
the appropriate equation
Figure 18.14a 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
minimum. As such, the spline usually provides a superior
approximation of the behavior of functions that have local, abrupt
changes.
FIGURE 18.14
The concept of the spline originated from the drafting technique of
using a thin, flexible strip (called a spline) to draw smooth curves
through a set of points. The process is depicted in Fig. 18.15 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 location 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 section, simple linear functions will first be used to introduce
some basic concepts and problems associated with spline
interpolation. Then we derive an algorithm for fitting quadratic
splines to data. Finally, we present material on the cubic spline,
which is the most common and useful version in engineering
practice.
Example No. 1
First-Order Splines
Problem Statement. Fit the data in Table 18.1 with first-order splines. Evaluate
the function at x = 5.
Solution. These data can be used to determine the slopes between points. For
example, for the interval x = 4.5 to x = 7 the slope can be computed using Eq.
(18.27):
The slopes for the other intervals can be computed, and the resulting first-order
splines are plotted in Fig. 18.16a. The value at x 5 5 is 1.3.
Visual inspection of Fig. 18.16a indicates that the primary
disadvantage of first order splines is that they are not smooth. In
essence, at the data points where two splines meet (called a knot), the
slope changes abruptly. In formal terms, the first derivative of the
function is discontinuous at these points. This deficiency is overcome
by using higher order polynomial splines that ensure smoothness at
the knots by equating derivatives at these points, as discussed in the
next section.
QUADRATIC SPLINE
Figure 18.17 has been included to help clarify the notation. For n + 1 data
points (i =0, 1, 2, . . . , n), there are n intervals and, consequently, 3n
unknown constants (the a’s, b’s, and c’s) to evaluate. Therefore, 3n
equations or conditions are required to evaluate the unknowns. These are:
1. The function values of adjacent polynomials must be equal at the
interior knots. This
condition can be represented as
2. The first and last functions must pass through the end points.
This adds two additional
equations:
FIGURE 18.17
Notation used to
derive quadratic
splines. Notice that
there are n intervals
and n + 1 data points.
The example shown
is for n = 3
3. The first derivatives at the interior knots must be equal. The
first derivative of Eq. (18.28) is
The visual interpretation of this condition is that the first two points
will be connected by a straight line.
Example No. 2
Quadratic Splines
Problem Statement. Fit quadratic splines to the same data used in Example No.
1 (Table 18.1) Use the results to estimate the value at x = 5.
Solution. For the present problem, we have four data points and n = 3 intervals.
Therefore, 3(3) = 9 unknowns must be determined. Equations (18.29) and
(18.30) yield 2(3) - 2 = 4 conditions:
Passing the first and last functions through the initial and final values adds 2
more [Eq. (18.31)]:
and [Eq. (18.32)]
which can be substituted into the original quadratic equations to develop the
following relationships for each interval:
When we use f 2, the prediction for x = 5 is, therefore,
The total spline fit is depicted in Fig. 18.16b. Notice that there are two
shortcomings that detract from the fit: (1) the straight line connecting the
first two points and (2) the spline for the last interval seems to swing too
high. The cubic splines in the next section do not exhibit these
shortcomings and, as a consequence, are better methods for spline
interpolation.
CUBIC SPLINE
The objective in cubic splines is to derive a third-order polynomial
for each interval between knots, as in
The three equations can then be employed to compute values within each
interval. For example, the value at x = 5, which falls within the second interval,
is calculated as