approximation of the first derivative [recall Eq. 4.20]. In general, the smaller the interval between the data points, the better the approximation. This is due to the fact that, as the
interval decreases, a continuous function will be better approximated by a straight line. This characteristic is demonstrated in the following example.
EXAMPLE 17.2 Linear Interpolation
Problem Statement. Estimate the natural logarithm of 2 using linear interpolation. First,
perform the computation by interpolating between ln 1 = 0 and ln 6 = 1.791759. Then,
repeat the procedure, but use a smaller interval from ln 1 to ln 4 1.386294. Note that the true value of ln 2 is 0.6931472.
Solution. We use Eq. 17.5 from x
1
= 1 to x
2
= 6 to give f
1
2 = 0 +
1.791759 − 0
6 − 1
2 − 1 = 0.3583519
which represents an error of ε
t
= 48.3. Using the smaller interval from x
1
= 1 to x
2
= 4 yields
f
1
2 = 0 +
1.386294 − 0
4 − 1
2 − 1 = 0.4620981
f x
2
f
1
x f
x
f x
1
x
1
x
2
x x
FIGURE 17.2
Graphical depiction of linear interpolation. The shaded areas indicate the similar triangles used to derive the Newton linear-interpolation formula [Eq.
17
.
5
].
Thus, using the shorter interval reduces the percent relative error to ε
t
= 33.3. Both interpolations are shown in Fig. 17.3, along with the true function.
17.2.2 Quadratic Interpolation
The error in Example 17.2 resulted from approximating a curve with a straight line. Con- sequently, a strategy for improving the estimate is to introduce some curvature into the line
connecting the points. If three data points are available, this can be accomplished with a second-order polynomial also called a quadratic polynomial or a parabola. A particularly
convenient form for this purpose is
f
2
x = b
1
+ b
2
x − x
1
+ b
3
x − x
1
x − x
2
17.6
A simple procedure can be used to determine the values of the coefficients. For b
1
, Eq. 17.6 with x
= x
1
can be used to compute b
1
= f x
1
17.7
Equation 17.7 can be substituted into Eq. 17.6, which can be evaluated at x = x
2
for b
2
= f x
2
− f x
1
x
2
− x
1
17.8
Finally, Eqs. 17.7 and 17.8 can be substituted into Eq. 17.6, which can be evaluated at x
= x
3
and solved after some algebraic manipulations for b
3
= f x
3
− f x
2
x
3
− x
2
− f x
2
− f x
1
x
2
− x
1
x
3
− x
1
17.9 17.2 NEWTON INTERPOLATING POLYNOMIAL
411
f x
f x ⫽ ln x
f
1
x True
value Linear estimates
x 5
2
1
FIGURE 17.3
Two linear interpolations to estimate ln
2
. Note how the smaller interval provides a better estimate.
Notice that, as was the case with linear interpolation, b
2
still represents the slope of the line connecting points x
1
and x
2
. Thus, the first two terms of Eq. 17.6 are equivalent to linear interpolation between x
1
and x
2
, as specified previously in Eq. 17.5. The last term, b
3
x − x
1
x − x
2
, introduces the second-order curvature into the formula. Before illustrating how to use Eq. 17.6, we should examine the form of the coeffi-
cient b
3
. It is very similar to the finite-difference approximation of the second derivative introduced previously in Eq. 4.27. Thus, Eq. 17.6 is beginning to manifest a structure
that is very similar to the Taylor series expansion. That is, terms are added sequentially to capture increasingly higher-order curvature.
EXAMPLE 17.3 Quadratic Interpolation
Problem Statement. Employ a second-order Newton polynomial to estimate ln 2 with
the same three points used in Example 17.2: x
1
= 1 f x
1
= 0 x
2
= 4 f x
2
= 1.386294 x
3
= 6 f x
3
= 1.791759 Solution.
Applying Eq. 17.7 yields b
1
= 0 Equation 17.8 gives
b
2
= 1.386294
− 0 4
− 1 = 0.4620981
f x
f x ⫽ ln x
f
2
x True
value
Linear estimate Quadratic estimate
x 5
2
1
FIGURE 17.4
The use of quadratic interpolation to estimate ln
2
. The linear interpolation from x =
1
to
4
is also included for comparison.
and Eq. 17.9 yields b
3
= 1.791759
− 1.386294 6
− 4 − 0.4620981
6 − 1
= −0.0518731 Substituting these values into Eq. 17.6 yields the quadratic formula
f
2
x = 0 + 0.4620981x − 1 − 0.0518731x − 1x − 4
which can be evaluated at x = 2 for f
2
2 = 0.5658444, which represents a relative
error of ε
t
= 18.4. Thus, the curvature introduced by the quadratic formula Fig. 17.4 improves the interpolation compared with the result obtained using straight lines in
Example 17.2 and Fig. 17.3.
17.2.3 General Form of Newton’s Interpolating Polynomials
The preceding analysis can be generalized to fit an n − 1th-order polynomial to n data
points. The n − 1th-order polynomial is
f
n −1
x = b
1
+ b
2
x − x
1
+ · · · + b
n
x − x
1
x − x
2
· · · x − x
n −1
17.10
As was done previously with linear and quadratic interpolation, data points can be used to evaluate the coefficients b
1
, b
2
, . . . , b
n
. For an n − 1th-order polynomial, n data points
are required: [x
1
, f x
1
], [x
2
, f x
2
], . . . , [x
n
, f x
n
]. We use these data points and the following equations to evaluate the coefficients:
b
1
= f x
1
17.11
b
2
= f [x
2
, x
1
]
17.12
b
3
= f [x
3
, x
2
, x
1
]
17.13
. .
. b
n
= f [x
n
, x
n −1
, . . . , x
2
, x
1
]
17.14
where the bracketed function evaluations are finite divided differences. For example, the first finite divided difference is represented generally as
f [x
i
, x
j
] =
f x
i
− f x
j
x
i
− x
j
17.15
The second finite divided difference, which represents the difference of two first divided differences, is expressed generally as
f [x
i
, x
j
, x
k
] =
f [x
i
, x
j
] − f [x
j
, x
k
] x
i
− x
k
17.16
Similarly, the nth finite divided difference is f
[x
n
, x
n −1
, . . . , x
2
, x
1
] =
f [x
n
, x
n −1
, . . . , x
2
] − f [x
n −1
, x
n −2
, . . . , x
1
] x
n
− x
1
17.17 17.2 NEWTON INTERPOLATING POLYNOMIAL
413
These differences can be used to evaluate the coefficients in Eqs. 17.11 through 17.14, which can then be substituted into Eq. 17.10 to yield the general form of Newton’s inter-
polating polynomial:
f
n −1
x = f x
1
+ x − x
1
f [x
2
, x
1
] + x − x
1
x − x
2
f [x
3
, x
2
, x
1
] + · · · + x − x
1
x − x
2
· · · x − x
n −1
f [x
n
, x
n −1
, . . . , x
2
, x
1
]
17.18
We should note that it is not necessary that the data points used in Eq. 17.18 be equally spaced or that the abscissa values necessarily be in ascending order, as illustrated
in the following example. However, the points should be ordered so that they are centered around and as close as possible to the unknown. Also, notice how Eqs. 17.15 through
17.17 are recursive—that is, higher-order differences are computed by taking differences of lower-order differences Fig. 17.5. This property will be exploited when we develop an
efficient M-file to implement the method.
EXAMPLE 17.4 Newton Interpolating Polynomial
Problem Statement. In Example 17.3, data points at x
1
= 1, x
2
= 4, and x
3
= 6 were used to estimate ln 2 with a parabola. Now, adding a fourth point [x
4
= 5; f x
4
= 1.609438], estimate ln 2 with a third-order Newton’s interpolating polynomial.
Solution. The third-order polynomial, Eq. 17.10 with n
= 4, is f
3
x = b
1
+ b
2
x − x
1
+ b
3
x − x
1
x − x
2
+ b
4
x − x
1
x − x
2
x − x
3
The first divided differences for the problem are [Eq. 17.15] f
[x
2
, x
1
] =
1.386294 − 0
4 − 1
= 0.4620981 f
[x
3
, x
2
] =
1.791759 − 1.386294
6 − 4
= 0.2027326 f
[x
4
, x
3
] =
1.609438 − 1.791759
5 − 6
= 0.1823216
x
1
x
2
x
3
x
4
x
i
f x
1
f x
2
f x
3
f x
4
fx
i
f [x
2
, x
1
] f
[x
3
, x
2
] f
[x
4
, x
3
]
First
f [x
3
, x
2
, x
1
] f
[x
4
, x
3
, x
2
]
Second
f [x
4
, x
3
, x
2
, x
1
]
Third
FIGURE 17.5
Graphical depiction of the recursive nature of finite divided differences. This representation is referred to as a divided difference table.
The second divided differences are [Eq. 17.16] f
[x
3
, x
2
, x
1
] =
0.2027326 − 0.4620981
6 − 1
= −0.05187311 f
[x
4
, x
3
, x
2
] =
0.1823216 − 0.2027326
5 − 4
= −0.02041100 The third divided difference is [Eq. 17.17 with n
= 4] f
[x
4
, x
3
, x
2
, x
1
] =
−0.02041100 − −0.05187311 5
− 1 = 0.007865529
Thus, the divided difference table is
x
i
f x
i
First Second
Third
1 0.4620981
−0.05187311 0.007865529
4 1.386294
0.2027326 −0.02041100
6 1.791759
0.1823216 5
1.609438
The results for f x
1
, f
[x
2
, x
1
], f [x
3
, x
2
, x
1
], and f [x
4
, x
3
, x
2
, x
1
] represent the coefficients b
1
, b
2
, b
3
, and b
4
, respectively, of Eq. 17.10. Thus, the interpolating cubic is f
3
x = 0 + 0.4620981x − 1 − 0.05187311x − 1x − 4
+ 0.007865529x − 1x − 4x − 6 which can be used to evaluate f
3
2 = 0.6287686, which represents a relative error of
ε
t
= 9.3. The complete cubic polynomial is shown in Fig. 17.6.
17.2 NEWTON INTERPOLATING POLYNOMIAL 415
f x
f x ⫽ ln x
f
3
x
True value
Cubic estimate
x 5
2
1
FIGURE 17.6
The use of cubic interpolation to estimate ln
2
.
17.2.4 MATLAB M-file:
Newtint
It is straightforward to develop an M-file to implement Newton interpolation. As in Fig. 17.7, the first step is to compute the finite divided differences and store them in an array. The dif-
ferences are then used in conjunction with Eq. 17.18 to perform the interpolation. An example of a session using the function would be to duplicate the calculation we
just performed in Example 17.3:
format long x = [1 4 6 5]’;
function yint = Newtintx,y,xx Newtint: Newton interpolating polynomial
yint = Newtintx,y,xx: Uses an n - 1-order Newton interpolating polynomial based on n data points x, y
to determine a value of the dependent variable yint at a given value of the independent variable, xx.
input: x = independent variable
y = dependent variable xx = value of independent variable at which
interpolation is calculated output:
yint = interpolated value of dependent variable
compute the finite divided differences in the form of a difference table
n = lengthx; if lengthy~=n, errorx and y must be same length; end
b = zerosn,n; assign dependent variables to the first column of b.
b:,1 = y:; the : ensures that y is a column vector. for j = 2:n
for i = 1:n-j+1 bi,j = bi+1,j-1-bi,j-1xi+j-1-xi;
end end
use the finite divided differences to interpolate xt = 1;
yint = b1,1; for j = 1:n-1
xt = xtxx-xj; yint = yint+b1,j+1xt;
end
FIGURE 17.7
An M-file to implement Newton interpolation.
y = logx; Newtintx,y,2
ans = 0.62876857890841
17.3 LAGRANGE INTERPOLATING POLYNOMIAL
Suppose we formulate a linear interpolating polynomial as the weighted average of the two values that we are connecting by a straight line:
f x = L
1
f x
1
+ L
2
f x
2
17.19
where the L’s are the weighting coefficients. It is logical that the first weighting coefficient is the straight line that is equal to 1 at x
1
and 0 at x
2
: L
1
= x
− x
2
x
1
− x
2
Similarly, the second coefficient is the straight line that is equal to 1 at x
2
and 0 at x
1
: L
2
= x
− x
1
x
2
− x
1
Substituting these coefficients into Eq. 17.19 yields the straight line that connects the points Fig. 17.8:
f
1
x =
x − x
2
x
1
− x
2
f x
1
+ x
− x
1
x
2
− x
1
f x
2
17.20
where the nomenclature f
1
x designates that this is a first-order polynomial. Equa- tion 17.20 is referred to as the linear Lagrange interpolating polynomial.
The same strategy can be employed to fit a parabola through three points. For this case three parabolas would be used with each one passing through one of the points and equal-
ing zero at the other two. Their sum would then represent the unique parabola that connects the three points. Such a second-order Lagrange interpolating polynomial can be written as
f
2
x =
x − x
2
x − x
3
x
1
− x
2
x
1
− x
3
f x
1
+ x
− x
1
x − x
3
x
2
− x
1
x
2
− x
3
f x
2
+ x
− x
1
x − x
2
x
3
− x
1
x
3
− x
2
f x
3
17.21
Notice how the first term is equal to f x
1
at x
1
and is equal to zero at x
2
and x
3
. The other terms work in a similar fashion.
Both the first- and second-order versions as well as higher-order Lagrange polynomi- als can be represented concisely as
f
n −1
x =
n i
=1
L
i
x f x
i
17.22 17.3 LAGRANGE INTERPOLATING POLYNOMIAL
417
where L
i
x =
n j
=1 j =i
x − x
j
x
i
− x
j
17.23
where n = the number of data points and designates the “product of.”
EXAMPLE 17.5 Lagrange Interpolating Polynomial
Problem Statement. Use a Lagrange interpolating polynomial of the first and second
order to evaluate the density of unused motor oil at T = 15 °C based on the following data: x
1
= f x
1
= 3.85
x
2
= 20
f x
2
= 0.800
x
3
= 40
f x
3
= 0.212
Solution. The first-order polynomial [Eq. 17.20] can be used to obtain the estimate at
x = 15:
f
1
x = 15 − 20
0 − 20 3.85 +
15 − 0 20 − 0
0.800 = 1.5625
f x
2
L
2
f x
2
L
1
f x
1
f x
f x
1
x
1
x
2
x
FIGURE 17.8
A visual depiction of the rationale behind Lagrange interpolating polynomials. The figure shows the first-order case. Each of the two terms of Eq.
17
.
20
passes through one of the points and is zero at the other. The summation of the two terms must, therefore, be the unique straight line
that connects the two points.