Chapter 3
Chapter 3
Core textbook:
1- Kreyszig, E., Kceyszig, H., and Norminton, E.J.,
”Advanced engineering mathematics”2011.
2- Sauer, Timothy., ” Numerical Analysis”2nd edition, 2014.
Websites: https://www.khanacademy.org/math/precalculus/
x9e81a4f98389efdf:matrices
A
0.4 Equal Spacing: Newton’s Backward Difference Formula . . . . . . . . . . . . . . . . . 16
AR
2
Chapter 3
Interpolation
A
We are given the values of a function f (x) at different points x0, x1, · · · , xn.
We want to find approximate values of the function f (x) for ”new” x’s
that lie between these points for which the function values are given. This
process is called interpolation. We write these given values of a function f
AR
in the form
f0 = f (x0) , f1 = f (x1) , ··· , fn = f (xn)
or as ordered pairs
(x0, f0) , (x1, f1) , ··· , (xn, fn)
Where do these given function values come from? They may come from a
”mathematical” function, such as a logarithm or a Bessel function. More
frequently, they may be measured or automatically recorded values of an
”empirical” function, such as air resistance of a car or an airplane at dif-
ferent speeds. Other examples of functions that are ”empirical” are the
yield of a chemical process at different temperatures or the size of the US
population as it appears from censuses taken at 10-year intervals.
A standard idea in interpolation now is to find a polynomial pn(x) of degree
n (or less) that assumes the given values; thus
pn (x0) = f0, pn (x1) = f1, ··· , pn (xn) = fn (1)
We call this pn an interpolation polynomial and x0, · · · , xn the nodes . And
if f (x) is a mathematical function, we call pn an approximation of f (or a
3
polynomial approximation). We use pn to get (approximate) values of f for
x ’s between x0 and xn (”interpolation’) or sometimes outside this interval
x0 5 x 5 xn (”extrapolation”). How Do We Find pn ? We shall explain
several standard methods that give us pn. For given data, the different
methods must give us the same polynomial. However, the polynomials
may be expressed in different forms suitable for different purposes.
A
Given (x0, f0) , (x1, f1) , · · · , (xn, fn) with arbitrarily spaced xi. Lagrange
had the idea multiplying each f j by a polynomial that is 1 at x j and 0 at
the other n nodes and then taking the sum of these n + 1 polynomials. This
AR
gives the unique interpolation polynomial of degree n or less. Beginning
with the simplest case. let us see how this works.
Linear interpolation is interpolation by the straight line through (x0, f0) ,
(x1, f1) ; see Fig. 1. Thus the linear Lagrange polynomial p1 is a sum
p1 = L0 f0 + L1 f1 with L0 the linear polynomial that is 1 at x0 and 0 at x1;
similarly, L1 is 0 at x0 and 1 at x1. Obviously,
x − x1 x − x0
L0(x) = , L1(x) =
x0 − x1 x1 − x0
This gives the linear Lagrange polynomial
x − x1 x − x0
p1(x) = L0(x) f0 + L1(x) f1 = · f0 + · f1 . (2)
x0 − x1 x1 − x0
A
(see Fig. 2 ) and obtain the answer
AR
ln 9.2 ≈ p1(9.2) = 0.1082(9.2) + 1.2234 = 2.2188
The error isε = a − ae = 2.2192 − 2.2188 = 0.0004.
Figure 2: L0 and L1
Quadratic interpolation is interpolation of given (x0, f0) , (x1, f1) , (x2, f2)
by a second degree polynomial p2(x), which by Lagrange’s idea is
A
2 −x0 )(x2 −x1 )
A
(x − 2)(x − 3) (x − 0)(x − 3) (x − 0)(x − 2)
P2(x) = 1 +2 +4
(0 − 2)(0 − 3) (2 − 0)(2 − 3) (3 − 0)(3 − 2)
1 2 1 1
= x − 5x + 6 + 2 − x − 3x + 4
2
x − 2x
2
AR
6 2 3
1 1
= x2 − x + 1
2 2
General Lagrange Interpolation Polynomial. For general n we obtain
n n
lk (x)
f (x) ≈ pn(x) = ∑ Lk(x) fk = ∑ lk (xk) fk (5)
k=0 k=0
where Lk (xk ) = 1 and Lk is 0 at the other nodes, and the Lk are independent
of the function f to be interpolated. We get (Eq. 5) if we take
l0(x) = (x − x1) (x − x2) · · · (x − xn)
lk (x) = (x − x0) · · · (x − xk−1) (x − xk+1) · · · (x − xn) , 0<k<n (6)
ln(x) = (x − x0) (x − x1) · · · (x − xn−1)
We can easily see that pn (xk ) = fk . Indeed, inspection of (Eq. 6) shows
that lk (x j ) = 0 if j ̸= k, so that for x = xk , the sum in (Eq. 5) reduces to
the single term (lk (xk ) /lk (xk )) fk = fk
Hence, suppose that we are presented with n+1 points (x0, f0) , . . . , (xn, fn) .
For each k between 0 and n, define the degree n polynomial
Pn(x) = f0L0(x) + · · · + fnLn(x)
A
(x − 0)(x − 1)(x − 3) (x − 0)(x − 1)(x − 2)
+0 −1
(2 − 0)(2 − 1)(2 − 3) (3 − 0)(3 − 1)(3 − 2)
1 1 1
= − x3 − 6x2 + 11x − 6 + x3 − 5x2 + 6x − x3 − 3x2 + 2x
AR
3 2 6
=−x+2
For given data (x0, f0) , · · · , (xn, fn) the interpolation polynomial pn(x) sat-
isfying (1) is unique, as we have shown. But for different purposes we may
use pn(x) in different forms. Lagrange’s form is useful for deriving formu-
las in numeric differentiation (approximation formulas for derivatives) and
integration.
Practically more important are Newton’s forms of pn(x), which we shall
also use for solving ODEs. They involve fewer arithmetic operations than
Lagrange’s form. Moreover, it often happens that we have to increase the
degree n to reach a required accuracy. Then in Newton’s forms we can
use all the previous work and just add another term, a possibility without
counterpart for Lagrange’s form.
With p0(x) = f [x0] = f0, the Newton’s divided difference interpolation for-
mula can be given as
A
xn f (xn) .
Now the divided differences, which are the real numbers
f [xk ] = f (xk ) ,
AR
f [xk+1] − f [xk ]
f [xk , xk+1] = ,
xk+1 − xk
f [xk+1, xk+2] − f [xk , xk+1]
f [xk , xk+1, xk+2] = ,
xk+2 − xk
f [xk+1, xk+2, xk+3] − f [xk , xk+1, xk+2]
f [xk , xk+1, xk+2, xk+3] = ,
xk+3 − xk
and so on. Hence,
A
For j = 0, · · · , n − m do:
x0 f [x0]
f [x0, x1]
x1 f [x1] f [x0, x1, x2]
f [x1, x2]
x2 f [x2]
A
Now, we have
f [x0] = f (x0) = f0 = 1,
2− 21
∴ f [x0, x1, x2] = 3−0 = 12
Hence f(x) ≈ pn(x) = f0 + (x − x0) f [x0, x1] + (x − x0) (x − x1) f [x0, x1, x2] .
= 1 + (x − 0)( 12 ) + (x − 0)(x − 2)( 21 ) = 12 x2 − 12 x + 1.
we can also arrange differences near the values from which they are ob-
tained. Such an arrangement is called a (divided) difference table. Apply-
This table is computed as follows: After writing down the x and y coor-
dinates in separate columns, calculate the next columns, left to right, as
A
divided differences.
After completing the divided difference triangle, the coefficients of the poly-
nomial 1,1/2,1/2 can be read from the top edge of the table. The interpo-
AR
lating polynomial can be written as
1 1
P(x) = 1 + (x − 0) + (x − 0)(x − 2),
2 2
Alternatively, we could do more algebra and write the interpolating poly-
nomial as
1 1 1 1
P(x) = 1 + x + x(x − 2) = x2 − x + 1,
2 2 2 2
matching the Lagrange interpolation version shown previously.
Note
Using the divided difference approach, new data points that arrive after
computing the original interpolating polynomial can be easily added.
Example
Add the fourth data point (1,0) to the list in above Example. We can keep
the calculations that were already done and just add a new bottom row to
A
1 0
AR
The result is one new term to add to the original polynomial P2(x). Reading
from the top edge of the triangle, we see that the new degree 3 interpolating
polynomial is
1 1 1
P3(x) = 1 + (x − 0) + (x − 0)(x − 2) − (x − 0)(x − 2)(x − 3).
2 2 2
Note that
1
P3(x) = P2(x) − (x − 0)(x − 2)(x − 3),
2
so the previous polynomial can be reused as part of the new one.
Note
It is interesting to compare the extra work necessary to add a new point to
the Lagrange formulation versus the divided difference formulation. The
Lagrange polynomial must be restarted from the beginning when a new
point is added; none of the previous calculation can be used. On the other
hand, in divided difference form, we keep the earlier work and add one new
term to the polynomial. Therefore, the divided difference approach has a
”real-time updating” property that the Lagrange form lacks.
Newton’s formula (7) is valid for arbitrarily spaced nodes as they may
occur in practice in experiments or observations. However, in many appli-
cations the x j ’s are regularly spaced for instance, in measurements taken
at regular intervals of time. Then, denoting the distance by h, we can write
A
We show how (7) now simplify considerably!
AR
To get started, let us define the first forward difference of f at x j by
∆ f j = f j+1 − f j ,
the second forward difference of f at x j by
∆2 f j = ∆ f j+1 − ∆ f j ,
and, continuing in this way, the kth forward difference of f at x j by
∆k f j = ∆k−1 f j+1 − ∆k−1 f j (k = 1, 2, · · · ). (11)
What is the point of this? We show that if we have regular spacing (10),
then
1 k
f [x0, · · · , xk ] = ∆ f0. (12)
k!hk
In (7) we finally set x = x0 + rh. Then x − x0 = rh, x − x1 = (r − 1)h since
x1 − x0 = h, and so on. With this and (12), formula (7) becomes Newton’s
(or Gregory-Newton’s) forward difference interpolation formula
A
= 1, = (s > 0, integer )
0 s s!
(14)
and s! = 1 · 2 · · · s.
AR
Example
Compute cosh 0.56 from (13) and the four values in the following table.
j x j f j = cosh x j
0 0.5 1.127626
1 0.6 1.185465
2 0.7 1.255169
3 0.8 1.337435
Solution
j x j f j = cosh x j ∆fj ∆2 f j ∆3 f j
0 0.5 1.127626
0.057839
1 0.6 1.185465 0.011865
0.069704 0.000697
2 0.7 1.255169 0.012562
0.082266
3 0.8 1.337435
A
∵ the exact 6D-value is cosh 0.56 = 1.160941
∴ The error is ε = a − ae = 1.160941 − 1.160944 = −0.000003.
AR
0.4 Equal Spacing: Newton’s Backward Difference Formula
n
r+s−1
f (x) ≈ pn(x) = ∑ ∇s f0 (x = x0 + rh, r = (x − x0) /h)
s=0
s
r(r + 1) 2 r(r + 1) · · · (r + n − 1) n
= f0 + r∇ f0 + ∇ f0 + · · · + ∇ f0.
2! n!
(16)
A
Example: Newton’s Forward and Backward Interpolations
Compute a 7D-value of the Bessel function J0(x) for x = 1.72 from the four
AR
values in the following table, using
(a) Newton’s forward formula (13).
(b) Newton’s backward formula (16).
j f or jback xj J0(x j )
0 −3 1.7 0.3979849
1 −2 1.8 0.3399864
2 −1 1.9 0.2818186
3 0 2 0.2238908
Solution
A
6
= 0.3979849 − 0.0115997 + 0.0000135 + 0.0000196 = 0.3864183,
which is exact to 6D, the exact 7D -value being 0.3864185.
AR
(b) Backward. For (16) we use j shown in the second column, and in each
column the last number. Since r = (1.72 − 2.00)/0.1 = −2.8, we thus get
from (16)
−2.8(−1.8)
J0(1.72) ≈ 0.2238908−2.8(−0.0579278) + · 0.0002400
2
−2.8(−1.8)(−0.8)
+ · 0.0004093
6
= 0.2238908 + 0.1621978 + 0.0006048 − 0.0002750
= 0.3864184.
Note:
There is a third notation for differences, called the central difference nota-
tion. It is used in numerics for ODEs and certain interpolation formulas.
A
of the points in Exercise 1 , and verify agreement with the Lagrange
interpolating polynomial.
3. Find a polynomial P(x) of degree 3 or less whose graph passes through
AR
the points (0.0), (1,1), (2,2), (3,7).
4. Find a polynomial P(x) of degree 3 or less whose graph passes through
the four data points (-2,8), (0,4), (1,2), (3,-2).
5. Quadratic interpolation. Gamma function.
Calculate the Lagrange polynomial p2(x) for the values Γ(1.00) =
1.0000, Γ(1.02) = 0.9888, Γ(1.04) = 0.9784 of the gamma function
and from it approximations of Γ(1.01) and Γ(1.03).
6. Linear and quadratic interpolation. Find e−0.25 and e−0.75 by linear
interpolation of e−x with x0 = 0, x1 = 0.5 and x0 = 0.5, x1 = 1, respec-
tively. Then find p2(x) by quadratic interpolation of e−x with x0 = 0
x1 = 0.5, x2 = 1 and from it e−0.25 and e−0.75 Compare the errors. Use
4 S-values of e−x .
7. Cubic Lagrange interpolation. Bessel function J0.
Calculate and graph L0, L1, L2, L3 with x0 = 0, x1 = 1, x2 = 2, x3 = 3
on common axes. Find p3(x) for the data
(0, 1), (1, 0.765198), (2, 0.223891)(3.−0.260052) [values of the Bessel
A
AR