Professional Documents
Culture Documents
2: Interpolation
Introduce the basic terms:
interpolation polynomial;
Lagrange interpolation polynomial;
Newton interpolation polynomial;
interpolation points (nodes);
linear interpolation;
piecewise linear interpolation;
deviation;
interpolation error.
(i = 0, 1, . . . n).
(1)
f (b) = F (b).
(2)
(3)
F (b) = Ab + B.
(4)
f (b) f (a)
,
ba
B =
1
bf (a) af (b)
ba
(5)
and, by (2),
F (x) = f (a) +
xa
(f (b) f (a)).
ba
(6)
One can verify directly that for each x the point (x, F (x)) lies on the line joining (a, f (a))
and (b, f (b)) (see Fig. 1).
We can rewrite (6) in the form
F (x) = w0 (x)f (a) + w1 (x)f (b)
(7)
bx
,
ba
w1 (x) =
xa
.
ba
(8)
(9)
i = 0, 1.
(10)
Evidently, if f (x) is a linear function, then interpolation process is exact and the function
F (x) from (5) coincides with f (x): the bold curve and the dot line on Fig. 1 between the points
(a, f (a)), (b, f (b)) coincide.
The interpolation error
(x) = f (x) F (x)
(11)
shows the deviation between interpolating and interpolated functions at the given point x
[a, b]. Of course,
(a) = (b) = 0
and
(x) 0, x [a, b]
if f (x) is a linear function.
In the previous example we had only two interpolation points, x = x0 = a, x = x1 = b.
Now let us consider the case of linear (piecewise linear) interpolation with the use of several
interpolation points spaced at equal intervals:
xk = a + kh; k = 0, 1, 2, . . . , M, h =
ba
; M = 2, 3, . . . .
M
(12)
For a given integer M we construct the interpolating function F (M ; x) which is piecewise linear
and which agrees with f (x) at the M + 1 interpolation points (see Fig. 2).
In each subinterval [xk , xk+1 ] we determine F (M ; x) by linear interpolation using the formula
(5). Thus we have for x [xk , xk+1 ]
F (M ; x) = f (xk ) +
x xk
(f (xk+1 ) f (xk )).
xk+1 xk
2
(13)
If we denote fk = f (xk ) and use the first forward difference fk = fk+1 fk we obtain
F (M ; x) = fk + (x xk )
fk
,
h
x [xk , xk+1 ].
(14)
One can calculate interpolation error by the formula (11) in each subinterval and, obviously,
(xk ) = 0, k = 0, 1, 2, . . . M.
(15)
x x1
,
x0 x1
L1 (x) =
x x0
,
x1 x0
x x1
x x0
f0 +
f1 .
x0 x1
x1 x0
In the case under consideration, x0 = 9.0, x1 = 9.5, f0 = 2.1972, and f1 = 2.2513. Calculate
L0 (9.2) =
9.2 9.5
= 0.6,
9.0 9.5
L1 (9.2) =
9.2 9.0
= 0.4,
9.5 9.0
(16)
(17)
3) if there is another polynomial Q2 (x) of degree 2 such that Q2 (xj ) = fj , then R2 (x) =
P2 (x)Q2 (x) is also a polynomial of degree 2, which vanishes at the 3 different points x0 , x1 , x2 ,
or, in other words, the quadratic equation R2 (x) = 0 has three different roots; therefore,
necessarily, R2 (x) 0.
Hence (17), or, what is the same, the Lagrange interpolation formula yields the uniquely
determined interpolation polynomial of degree 2 corresponding to the given interpolation points
and ordinates.
Example. For x0 = 1, x1 = 2, x2 = 4 the Lagrange polynomials (16) are:
x2 x4
1
= (x2 6x + 8);
12 14
3
x1 x4
1
l1 (x) =
= (x2 5x + 4);
21 24
2
x1 x2
1
l2 (x) =
= (x2 3x + 2).
41 42
6
l0 (x) =
Therefore,
P2 (x) =
f1
f2
f0 2
(x 6x + 8) (x2 5x + 4) + (x2 3x + 2).
3
2
6
(18)
1 2
1
(x 5x + 6) = (x 2)(x 3)
2
2
and it coincides with the given ordinates at interpolation points (see Fig. 3 where the curve for
P2 (x) on the interpolation interval [1, 4] is bold):
P2 (1) = 1; P2 (2) = 0; P2 (4) = 1.
Evidently, if f (x) is a quadratic function, f (x) = ax2 + bx + c, a 6= 0, then interpolation
process is exact and the function P2 (x) from (17) will coincide with f (x).
The interpolation error
(x) = f (x) P2 (x)
(19)
shows the deviation between interpolation polynomial and interpolated function at the given
point x [x0 , x2 ]. Of course,
(x0 ) = (x1 ) = (x2 ) = 0
and
if f (x) is a quadratic function.
r(x) 0, x [x0 , x2 ]
(x x1 )(x x2 )
l0 (x)
=
,
l0 (x0 )
(x0 x1 )(x0 x2 )
4
L1 (x) =
L2 (x) =
l1 (x)
(x x0 )(x x2 )
=
,
l1 (x1 )
(x1 x0 )(x1 x2 )
(x x0 )(x x1 )
l2 (x)
=
,
l2 (x2 )
(x2 x0 )(x2 x1 )
L0 (x) =
L1 (x) =
L2 (x) =
(x 9.0)(x 11.0)
1
=
(x2 20x + 99),
(9.5 9.0)(9.5 11.0)
0.75
1
(x 9.0)(x 9.5)
= (x2 18.5x + 85.5),
(11.0 9.0)(11.0 9.5)
3
L0 (9.2) = 0.5400;
L1 (9.2) = 0.4800;
L2 (9.2) = 0.0200
(20)
where
wjk (x) =
x xj
;
xk xj
k = 0, 1, . . . n, j = 0, 1, . . . n, k 6= j.
(21)
Furthermore,
lk (xk ) = 1,
lk (xj ) = 0, j 6= k.
(22)
(23)
and it uniquely determines the interpolation polynomial of degree n corresponding to the given
interpolation points and ordinates.
x x1
,
x0 x1
L1 (x) =
x x0
,
x1 x0
x x1
x x0
f0 +
f1 .
x0 x1
x1 x0
In the case under consideration, x0 = 9.0, x1 = 9.5, f0 = 2.1972, and f1 = 2.2513. and
ln 9.2 a
= p1 (9.2) = L0 (9.2)f0 + L1 (9.2)f1 = 0.6 2.1972 + 0.4 2.2513 = 2.2188.
The error is = a a
= 2.2192 2.2188 = 0.0004.
Estimate the error according to the general formula with n = 1
1 (x) = f (x) p1 (x) = (x x0 )(x x1 )
f 00 (t)
,
2
t (9.0, 9.5)
(1)
,
t2
1 (9.2) = (0.2)(0.3)
(1)
0.03
= 2 (t (9.0, 9.5)),
2
2t
t
0.03
0.03
0.03
0.03
0.00033 =
= min 2 |1 (9.2)| max 2 =
= 0.00037
2
t[9.0,9.5]
t[9.0,9.5]
9.5
t
t
9.02
so that 0.00033 |1 (9.2)| 0.00037, which disagrees with the obtained error = a a
=
0.0004. In fact, repetition of computations with 5D instead of 4D gives
ln 9.2 a
= p1 (9.2) = 0.6 2.19722 + 0.4 2.25129 = 2.21885.
with an actual error
= 2.21920 2.21885 = 0.00035
which lies in between 0.00033 and 0.00037. A discrepancy between 0.0004 and 0.00035 is thus
caused by the round-off-to-4D error which is not taken into acount in the general formula for
the interpolation error.
Estimation by the error principle. First we calculate
p1 (9.2) = 2.21885
6
and then
p2 (9.2) = 0.54 2.1972 + 0.48 2.2513 0.02 2.3979 = 2.21916
from EXAMPLE 2 but with 5D. The difference
p2 (9.2) p1 (9.2) = 2.21916 2.21885 = 0.00031
is the approximate error of p1 (9.2): 0.00031 is an approximation of the error 0.00035 obtained
above.
The Lagrange interpolation formula (23) is very unconvenient for actual calculation. Moreover, when computing with polynomials Pn (x) for varying n, the calculation of Pn (x) for a
particular n is of little use in calculating a value with a larger n. These problems are avoided
by using another formula for Pn (x), employing the divided differences of the data being
interpolated.
Assume that it is given the grid of points x0 , x1 , x2 , . . . ; xi 6= xj , i 6= j and corresponding
values of a function f (x) : f0 , f1 , f2 , . . .
The first divided differences are defined as
f [x0 , x1 ] =
f1 f0
f2 f1
; f [x1 , x2 ] =
; ...
x1 x0
x2 x1
(24)
(25)
(26)
and of order n
f [x0 , x1 , . . . , xn , xn+1 ] =
(27)
It is easy to see that the order of x0 , x1 , x2 , . . . , xn will not make a difference in the calculation
of divided difference. In other words, any permutation of the grid points does not change the
value of divided difference. Indeed, for n = 1
f [x1 , x0 ] =
f0 f1
f1 f0
=
= f [x0 , x1 ].
x0 x1
x1 x0
For n = 2, we obtain
f [x0 , x1 , x2 ] =
f0
f1
+
(x0 x1 )(x0 x2 )
(x1 x0 )(x1 x2 )
f2
+
.
(x2 x0 )(x2 x1 )
(28)
If we interchange values of x0 , x1 and x2 , then the fractions of the right-hand side will interchange their order, but the sum will remain the same.
When the grid points (nodes) are spaced at equal intervals (forming the uniform grid),
the divided difference are coupled with the forward differences by simple formulas. Set
7
xj = x0 + jh, j = 0, 1, 2, . . . and assume that fj = f (x0 + jh) are given. Then the first
forward difference is
f (x0 + h) f (x0 )
f1 f0
f0
=
=
.
x0 + h x0
h
1!h
f [x0 , x1 ] = f [x0 , x0 + h] =
(29)
f1
f0
1!h
1!y
2 f0
2!h2
(30)
f [x0 , x0 + h, . . . , x0 + nh] =
(31)
f [x0 , x1 , x2 ]
f [x1 , x2 ]
f [x0 , x1 , x2 , x3 ]
x2 f (x2 )
f [x1 , x2 , x3 ]
f [x2 , x3 ]
..
.
..
.
f [x1 , x2 , x3 , x4 ] . . .
...
f [xn1 , xn ]
xn f (xn )
Construct the table of divided differences for the function
f (x) =
1
,
1 + x2
0.100
0.2 0.962
0.280
0.3 0.917
0.450
0.900
0.167
0.850
Let Pn (x) denote the polynomial interpolating f (x) at the nodes xi for i = 0, 1, 2, . . . , n.
Thus, in general, the degree of Pn (x) is less or equal n and
Pn (xi ) = f (xi ), i = 0, 1, 2, . . . n.
(32)
Then
P1 (x) = f0 + (x x0 )f [x0 , x1 ];
P2 (x) = f0 + (x x0 )f [x0 , x1 ] + (x x0 )(x x1 )f [x0 , x1 , x2 ]
.
.
.
Pn (x) = f0 + (x x0 )f [x0 , x1 ] + . . .
+ (x x0 )(x x1 )(x xn1 )f [x0 , x1 , . . . xn ].
(33)
(34)
(35)
This is called the Newtons divided difference formula for the interpolation polynomial.
Note that for k 0
Pk+1 = Pk (x) + (x x0 ) . . . (x xk )f [x0 , x1 , . . . xk+1 ].
(36)
Thus we can go from degree k to degree k + 1 with a minimum of calculation, once the divided
differences have been computed (for example, with the help of the table of finite differences).
We will consider only the proof of (33) and (34). For the first case, one can see that
P1 (x0 ) = f0 and
f (x1 ) f (x0 )
x1 x0
= f0 + (f1 f0 ) = f1 .
P1 (x1 ) = f0 + (x1 x0 )
Thus P1 (x) is a required interpolation polynomial, namely, it is a linear function which satisfies
the interpolation conditions (32).
For the formula (34) we have the polynomial of a degree 2
P2 (x) = P1 (x) + (x x0 )(x x1 )f [x0 , x1 , x2 ]
(37)
and for x0 , x1
P2 (xi ) = P1 (xi ) + 0 = fi , i = 0, 1.
Also,
P2 (x2 ) = f0 + (x2 x0 )f [x0 , x1 ] + (x2 x0 )(x2 x1 )f [x0 , x1 , x2 ]
= f0 + (x2 x0 )f [x0 , x1 ] + (x2 x1 )(f [x1 , x2 ] f [x0 , x1 ])
= f0 + (x1 x0 )f [x0 , x1 ] + (x2 x1 )f [x1 , x2 ]
= f0 + (f1 f0 ) + (f2 f1 ) = f2 .
By the uniqueness of interpolation polynomial this is the quadratic interpolation polynomial
for the function f (x) at x0 , x1 , x2 .
In the general case the formula for the interpolation error may be represented as follows
f (x) = Pn (x) + n (x), x [x0 , xn ]
(38)
where x0 , x1 , . . . , xn are (different) interpolation points, Pn (x) is interpolation polynomial constructed by any of the formulas verified above and n (x) is the interpolation error.
2.079442
9.0
2.197225
9.5
2.251292
0.117783
0.108134
0.006433
0.097735
0.005200
0.000411
11.0 2.397895
We have
f (x) p3 (x) = 2.079442 + 0.117783(x 8.0)
0.006433(x 8.0)(x 9.0) + 0.000411(x 8.0)(x 9.0)(x 9.5).
At x = 9.2,
f (9.2) 2.079442 + 0.141340 0.001544 0.000030 = 2.219208.
We can see how the accuracy increases from term to term:
p1 (9.2) = 2.220782,
p2 (9.2) = 2.219238,
p3 (9.2) = 2.219208.
Note that interpolation makes sense only in the closed interval between the first (minimal)
and the last (maximal) interpolation points.
The Newtons interpolation formula (35) becomes especially simple when interpolation
points x0 , x0 + h, x0 + 2h, . . . are spaced at equal intervals. In this case one can rewrite
(38) using the formulas for divided differences and introducing the variable
r =
x x0
h
(39)
such that
x = x0 + rh, x x0 = rh, (x x0 )(x x0 h) = r(r 1)h2 , . . .
(40)
Substituting this new variable into (13) and (16) we obtain the Newtons forward difference
interpolation formula
f (x) Pn (x) = f0 + rf0 +
r(r 1) . . . (r n + 1) n
r(r 1) 2
f0 + . . . +
f0 .
2!
n!
hn+1
r(r 1) . . . (r n)f n+1 (t),
(n + 1)!
n = 1, 2, . . . , t (x0 , xn )
10
(41)
0.011865
0.069704
0.7 1.255169
0.000697
0.012562
0.082266
0.8 1.337435
In (39), we have
x = 0.56,
x0 = 0.50,
h = 0.1,
r=
x x0
0.56 0.50
=
= 0.6
h
0.1
and
cosh(0.56) p3 (0.56) = 1.127626+0.60.057839+
0.6(0.4)
0.6(0.4)(1.4)
0.011865+
0.000697 =
2
6
Error estimate. We have f (t) = cosh(t) with f (4) (t) = cosh(4) (t) = cosh(t), n = 3,
h = 0.1, and r = 0.6, so that
3 (0.56) = cosh(0.56) p3 (0.56) =
(0.1)4
0.6(0.6 1)(0.6 2)(0.6 3) cosh(4) (t) = A cosh(t),
(4)!
t (0.5, 0.8)
11
PROBLEM 17.3.1
Compute ln 9.3 from ln 9.0 = 2.1972 and ln 9.5 = 2.2513 by the linear Lagrange interpolation
and determine the error from a = ln 9.3 = 2.2300 (exact to 4D).
Solution. Given (x0 , f0 ) and (x1 , f1 ) we set
L0 (x) =
x x1
,
x0 x1
L1 (x) =
x x0
,
x1 x0
x x0
x x1
f0 +
f1 .
x0 x1
x1 x0
x 9.5
= 2(9.5 x) = 19 2x,
(0.5)
L1 (x) =
x 9.0
= 2(x 9) = 2x 18.
0.5
9.3 9.5
= 0.4,
9.0 9.5
L1 (9.3) =
9.3 9.0
= 0.6,
9.5 9.0
ln 9.3 a
= p1 (9.3) = L0 (9.3)f0 + L1 (9.3)f1 = 0.4 2.1972 + 0.6 2.2513 = 2.2297.
The error is = a a
= 2.2300 2.2297 = 0.0003.
PROBLEM 17.3.2
Estimate the error of calculating ln 9.3 from ln 9.0 = 2.1972 and ln 9.5 = 2.2513 by the linear
Lagrange interpolation (ln 9.3 = 2.2300 exact to 4D).
Solution. We estimate the error according to the general formula with n = 1
1 (x) = f (x) p1 (x) = (x x0 )(x x1 )
f 00 (t)
,
2
t (9.0, 9.5)
(1)
,
t2
1 (9.3) = (0.3)(0.2)
(1)
0.03
= 2 (t (9.0, 9.5)),
2
2t
t
0.03
0.03
0.03
0.03
0.00033 =
= min 2 |1 (9.3)| max 2 =
= 0.00037
2
t[9.0,9.5]
t[9.0,9.5]
9.5
t
t
9.02
so that 0.00033 |1 (9.3)| 0.00037, which disagrees with the obtained error = a
a = 0.0003
because in the 4D computations we cannot round-off the last digit 3. In fact, repetition of
computations with 5D instead of 4D gives
ln 9.3 a
= p1 (9.3) = 0.4 2.19722 + 0.6 2.25129 = 0.87889 + 1.35077 = 2.22966
12
PROBLEM 17.3.3
Compute e0.25 and e0.75 by linear interpolation with x0 = 0, x1 = 0.5 and x0 = 0.5, x1 = 1.
Then find p2 (x) interpolating ex with x0 = 0, x1 = 0.5, and x2 = 1 and from it e0.25 and
e0.75 . Compare the errors of these linear and quadratic interpolation.
Solution. Given (x0 , f0 ) and (x1 , f1 ) we set
L0 (x) =
x x1
,
x0 x1
L1 (x) =
x x0
,
x1 x0
x x1
x x0
f0 +
f1 .
x0 x1
x1 x0
In the case of linear interpolation, we will interpolate ex and take first the nodes x0 = 0.5
and x1 = 0 and f0 = e0.5 = 0.6065 and f1 = e0 = 1.0000.
L0 (x) =
x0
= 2x,
(0.5)
L1 (x) =
x + 0.5
= 2(x + 0.5) = 2x + 1.
(0.5)
x + 0.5
= 2(x + 0.5) = 2x 1,
(0.5)
L1 (x) =
x+1
= 2(x + 1).
(0.5)
l0 (x)
(x x1 )(x x2 )
=
,
l0 (x0 )
(x0 x1 )(x0 x2 )
L1 (x) =
l1 (x)
(x x0 )(x x2 )
=
,
l1 (x1 )
(x1 x0 )(x1 x2 )
L2 (x) =
l2 (x)
(x x0 )(x x1 )
=
,
l2 (x2 )
(x2 x0 )(x2 x1 )
(x + 0.5)(x)
= 2x(x + 0.5);
(0.5)(1)
(x + 1)(x)
= 4x(x + 1);
(0.5)(0.5)
(x + 1)(x + 0.5)
= 2(x + 0.5)(x + 1);
(1)(0.5)
et tx1 dt,
(1.00) = 1.0000, (1.02) = 0.9888, and (1.04) = 0.9784, and from it the approximation of
(1.01) and (1.03).
14
Solution. We will interpolate (x) taking the nodes x0 = 1.00, x1 = 1.02, and x2 = 1.04 and
f0 = 1.0000, f1 = 0.9888, and f2 = 0.9784.
Given (x0 , f0 ), (x1 , f1 ), and (x2 , f2 ) we set
L0 (x) =
l0 (x)
(x x1 )(x x2 )
=
,
l0 (x0 )
(x0 x1 )(x0 x2 )
L1 (x) =
l1 (x)
(x x0 )(x x2 )
=
,
l1 (x1 )
(x1 x0 )(x1 x2 )
L2 (x) =
l2 (x)
(x x0 )(x x1 )
=
,
l2 (x2 )
(x2 x0 )(x2 x1 )
(x 1.02)(x 1.04)
= 1250(x 1.02)(x 1.04);
(0.02)(0.04)
(0.01)(0.03)
3
= = 0.375,
(0.02)(0.04)
8
L1 (x) =
L1 (1.01) =
(0.01)(0.01)
1
= = 0.125.
(0.02)(0.04)
8
(x 1)(x 1.04)
= 2500(x 1)(x 1.04);
(0.02)(0.02)
(0.01)(0.03)
3
= = 0.75,
(0.02)(0.02)
4
L2 (x) =
L2 (1.01) =
L0 (1.03) =
L1 (1.03) =
(0.03)(0.01)
3
= = 0.75.
(0.02)(0.02)
4
(x 1)(x 1.02)
= 1250(x 1)(x 1.02);
(0.04)(0.02)
(0.01)(0.01)
1
= = 0.125,
(0.04)(0.02)
8
L1 (1.03) =
(0.03)(0.01)
3
= = 0.375.
(0.04)(0.02)
8
0.0008
0.0104
1.04 0.9784
From Newtons forward difference formula, we have
x = 1.01, 1.03, 1.05;
x0 = 1.00,
h = 0.02,
r=
x1
= 50(x 1);
h
r(r 1) 2
r(r 1)
f0 = 1.000 0.0112r + 0.0008
= x2 2.580x + 2.580,
2
2
which coincides with the quadratic interpolation polynomial derived above. Therefore, we can
perform direct calculations to obtain
p2 (x) = f0 + rf0 +
or
6a + 2b = 26
8a + 2b = 32
which yields 2a = 6, a = 3, b = 13 3a = 4, and c = 5 b a = 2.
Thus, the desired polynomial of degree n = 2 is p2 (x) = 3x2 + 4x 2.
It is easy to see that p2 (1) = 5, p2 (2) = 18, p2 (3) = 37, p2 (4) = 62, and p2 (5) = 93.
17