Professional Documents
Culture Documents
Polynomial Interpolation
In this chapter, we consider the important problem of approximating a function f (x), whose values at a set of
distinct points x0 , x1 , x2 , . . . , xn are known, by a polynomial P (x) such that P (xi ) = f (xi ), i = 0, 1, 2, . . . , n.
Such a polynomial is known as an interpolating polynomial. An approximation of this function is desirable
if f (x) is difficult to evaluate or manipulate like the error function
! x
2 2
erf(x) = √ e−t dt,
π 0
for example. Note that polynomials are easily evaluated, differentiated or integrated. Another purpose of
such an approximation is that a very long table of function values f (xi ) may be replaced by a short table
and a compact interpolation subroutine.
αxi + β = fi
αxi+1 + β = fi+1 ,
Therefore, " #
fi+1 − fi
P1 (x) = fi + (x − xi ).
xi+1 − xi
Example 4.1 Using linear interpolation, approximate sin 6.5◦ from a table which gives
(a) sin 6◦ = 0.10453; sin 7◦ = 0.12187.
(b) sin 0◦ = 0; sin 10◦ = 0.17365.
Chap. 4. Polynomial Interpolation CS414 Class Notes 57
Solution
$ %
(a) P1 (6.5) = 0.10453 + 0.12187−0.10453
7−6 ≈ 0.11320.
f(x)
Pn(x)
f(x)
x0 x1 x2 x3 ... xn
Pn (x) = a0 + a1 x + a2 x2 + · · · + an xn .
Pn (xj ) = f (xj ), j = 0, 1, 2, . . . , n.
The matrix V is known as the Vandermonde matrix. It is nonsingular with nonzero determinant
n−1
,
det(V ) = (xi − xj ).
j=0
i>j
Hence a can be uniquely determined as a = V −1 f . Another proof of the uniqueness of the interpolating
polynomial can be given as follows.
Theorem 4.1 Uniqueness of interpolating polynomial. Given a set of points x0 < x1 < · · · < xn ,
there exists only one polynomial that interpolates a function at those points.
Proof Let P (x) and Q(x) be two interpolating polynomials of degree at most n, for the same set of points
x0 < x1 < · · · < xn . Also, let
R(x) = P (x) − Q(x).
Then R(x) is also a polynomial of degree at most n. Since
P (xi ) = Q(xi ) = fi ,
we have, R(xi ) = 0 for i = 0, 1, . . . , n. In other words R(x) has (n + 1) roots. From the Fundamental
Theorem of Algebra however, R(x) cannot have more than n roots. A contradiction! Thus, R(x) ≡ 0, and
P (x) ≡ Q(x). !
Example 4.2 Given the following table for the function f (x), obtain the lowest degree interpolating
polynomial.
xk –1 2 4
fk –1 –4 4
P2 (x) = a0 + a1 x + a2 x2 ,
P2 (x) = −4 − 2x + x2 .
We can use this approximation to estimate the root of f (x) that lies in the interval [2, 4]:
√
2 + 4 + 16 √
γ= = 1 + 5.
2
Chap. 4. Polynomial Interpolation CS414 Class Notes 59
!
An important remark is in order. One, in general, should not determine the interpolating polynomial by
solving the Vandermonde linear system. These systems are surprisingly ill-conditioned for n no larger than
10. For example, for 0 < x0 < x1 < · · · < xn = 1 uniformly distributed in [0,1], large n yields a Vandermonde
matrix with almost linearly dependent columns, and the Vandermonde system becomes almost singular.
A more satisfactory form of the interpolating polynomial is due to Lagrange,
Pn (x) = f (x0 )L0 (x) + f (x1 )L1 (x) + · · · + f (xn )Ln (x).
Here Lj (x), for 0 ≤ j ≤ n, are polynomials of degree n called fundamental polynomials or Lagrange polyno-
mials. From the (n + 1) conditions
Pn (xi ) = f (xi ), 0 ≤ i ≤ n,
we see that -
0 i "= j
Lj (xi ) =
1 i=j
The above property is certainly satisfied if we choose
i.e.,
,n
(x − xi )
Lj (x) = .
i=0
(xj − xi )
i#=j
The fact that Lj (x) is unique follows from the uniqueness of the interpolation polynomial.
Recall that there is one and only one polynomial of degree n or less that interpolates f (x) at the (n + 1)
nodes x0 < x1 < · · · < xn . Thus, for this given set of nodes, both forms yield the same polynomial!
Vandermonde Approach.
n
.
Pn (x) = ai xi Va=f
i=0
Operation count: It can be shown that the Vandermonde system V a = f can be solved in O(n 2 ) arithmetic
operations rather than O(n3 ) operations because of the special form of the Vandermonde matrix.
Lagrange Approach.
n
,
n n (x − xi ) n
. . i=0 .
Pn (x) = fj Lj (x) = gj =
(x − xj ) gj · νj
j=0 j=0 j=0
where
f (xj )
gj = n .
,
(xj − xi )
i=0
i#=j
Operation count: The Lagrange form avoids solving the ill-conditioned Vandermonde linear, systems, and
evaluates the polynomials
,n
1
νj = (x − xi )
(x − xj ) i=0
Chap. 4. Polynomial Interpolation CS414 Class Notes 60
f(x)
Pn(x)
f(x)
x0 x1 x2 x3 ... xn
g(x) = 0,
g(xj ) = 0, 0 ≤ j ≤ n,
Chap. 4. Polynomial Interpolation CS414 Class Notes 61
i.e., g(z) has (n+2) distinct roots. Assuming that f (x) has at least n+1 continuous derivatives, the (n+1)th
derivative of g(z), i.e.,
d(n+1)
g(z) ≡ g (n+1) (z)
dz (n+1)
has at least one root x∗ . Hence,
x0 x2 x4
g(z)
x1 x3
g! ( z )
g!! ( z )
g!!! ( z )
iv
g (z)
x*
Figure 4.3: The (n + 1)th derivative of a function g(x) with n + 2 roots (n = 3) must have at least one root.
where π (n+1) (z) = (n + 1)! Moreover, since en (z) = f (z) − Pn (z), therefore,
e(n+1)
n (z) = f (n+1) (z) − Pn(n+1) (z)
(n+1)
in which the last term Pn (z) is zero. Using the above equations, we have
We had shown earlier that g (n+1) (z) has at least one root x∗ in the interval containing x and xj , j = 0, . . . , n.
This implies that g (n+1) (x∗ ) = 0, and therefore,
f (n+1) (x∗ )
h(x) =
(n + 1)!
f (n+1) (x∗ )
en (x) = f (x) − Pn (x) = (x − x0 )(x − x1 ) · · · (x − xn )
(n + 1)!
where x∗ is in the interval containing x and xj , j = 0, . . . , n.
Chap. 4. Polynomial Interpolation CS414 Class Notes 62
Example 4.3 Obtain the Lagrange interpolating polynomial from the data
√
π 1 π 3 π
sin 0 = 0, sin = , sin = , sin = 1,
6 2 3 2 2
and use it to evaluate sin 12
π
and sin π4
Solution The interpolating polynomial is given by
|f (4) (x)| ≤ 1.
Therefore, 7 $ π %7 π π π π 1
7 7
7e3 7≤ · · · · = 1.76 × 10−3 .
4 4 12 12 4 4!
Similarly, en (x) at x = π
12 is bounded by
7 $ π %7 π π π 5π 1
7 7
7e3 7≤ · · · · = 2.94 × 10−3 .
12 12 12 4 12 4!
!
Chap. 4. Polynomial Interpolation CS414 Class Notes 63
2j
xj = −1 + , j = 0, 1, . . . , n.
n
Figure ?? shows how the polynomials P4 (x), P8 (x), P12 (x), and P16 (x) approximate f (x) on [−1, 1]. We see
n= 4 n= 8
1 1
0.8
0.8
0.6
0.6
0.4
0.2
0.4
0.2
−0.2
−0.4
0
−0.6
−0.2
−0.8
−0.4 −1
−1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 1 −1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 1
n = 12 n = 16
1 2
0.5 0
0
−2
−0.5
−4
−1
−1.5 −6
−2
−8
−2.5
−10
−3
−12
−3.5
−4 −14
−1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 1 −1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 1
that as n increases, the interpolation error in the central portion of the interval diminishes, while increasing
rapidly near the ends of the interval. Such behavior is typical in equidistant interpolation with polynomials
of high degree. This is known as Runge’s phenomenon, and the function f (x) is known as Runge’s function.
If the (n + 1) interpolation nodes are not chosen equally spaced, but rather placed near the ends of the
interval at the roots of the so called Chebyshev polynomial of degree (n + 1), the problem with Runge’s
function disappears (see Fig. ??). The roots of the Chebyshev polynomial of degree (n + 1) are given by
" #
k + 21
xk = − cos π , k = 0, 1, . . . , n.
n+1
Chap. 4. Polynomial Interpolation CS414 Class Notes 64
n= 4 n= 8
1.2 1.2
1 1
0.8 0.8
0.6 0.6
0.4 0.4
0.2 0.2
0 0
−0.2 −0.2
−1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 1 −1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 1
n = 12 n = 16
1 1
0.9 0.9
0.8 0.8
0.7 0.7
0.6 0.6
0.5 0.5
0.4 0.4
0.3 0.3
0.2 0.2
0.1 0.1
0 0
−1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 1 −1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 1
Pn (x) = c0 + c1 (x − x0 ) + c2 (x − x0 )(x − x1 ) +
c3 (x − x0 )(x − x1 )(x − x2 ) + · · · +
cn (x − x0 )(x − x1 ) · · · (x − xn−1 ).
Note that the evaluation of L for n nodes requires O(n2 ) arithmetic operations. Assuming that the nodes
are equidistant, i.e., xi+1 − xi = h, the system Lc = f is given by
1 0 0 0 c0 f0
1 h 0 0 f1
c1 = .
1 2h 2h2 0 c2 f2
1 3h 6h2 6h3 c3 f3
Step 1.
c0 = f0
(1)
f1 = (f1 − f0 )/h
(1)
f2 = (f2 − f0 )/2h
(1)
f3 = (f3 − f0 )/3h.
Step 2.
(1)
c1 = f1
(2) (1) (1)
f2 = (f2 − f1 )/h
(2) (1) (1)
f3 = (f3 − f1 )/2h
Step 3.
(2)
c2 = f2
(3) (2) (2)
f3 = (f3 − f2 )/h
Step 4.
(3)
c3 = f 3
MATLAB
function c = InterpolateNewton(x,f)
% x: interpolating nodes
% f: function values at x
% c: coef. of Newton’s form of interpolating polynomial
n = length(x);
for k = 1:n-1
f(k+1:n) = (f(k+1:n)-f(k))./(x(k+1:n)-x(k));
end
c = y;
Chap. 4. Polynomial Interpolation CS414 Class Notes 66
∞
∞
∞
∞
x1 x2 x3 x4
that this mechanical spline is given by a cubic polynomial (degree 3 polynomial) in each subinterval [xi , xi+1 ],
i = 1, 2, . . . , n − 1, with adjacent cubics joint continuously with continuous first and second derivatives. Let
s(x) = a0 + a1 x + a2 x2 + a3 x3 ,
be the form of each cubic spline. Since we have (n − 1) subintervals [xi , xi+1 ], 1 ≤ i ≤ n − 1, then we have
4(n − 1) unknowns; (4 parameters for each subinterval: x0 ,a1 ,a2 , and a3 ). Suppose si (x) denotes the cubic
spline the ith interval. The conditions to be satisfied by these cubic splines are:
1. Continuity at each interior node:
s(xj ) = f (xj ), j = 1, 2, . . . , n.
These provide 3(n − 2) + n = 4n − 6 conditions; however, in order to completely specify the cubic splines,
we still need 2 additional conditions. These are conditions specified at the end points x1 and xn . For the
“mechanical” or “natural” spline we set
xj+1 − xj = h
and let,
1 %%
σj = s (xj )
6
i.e.,
s%%i−1 (xi ) = s%%i (xi ) = 6σi
for all i satisfying condition ??. Since
s(x) = a0 + a1 x + a2 x2 + a3 x3 ,
we have
i.e., s%% (x) is a straight line. Thus, s%%i (x) takes the following form (see Fig. ??):
xi+1 − x (x − xi )
s%%i (x) = (6σi ) + (6σi+1 ), i = 1, 2, . . . , n − 1.
h h
s'' i ( x ) 6σi+1
6σi
xi x xi+1
si (xi ) = fi ⇒ fi = σi h2 + γ2 h
si (xi+1 ) = fi+1 ⇒ fi+1 = σi+1 h2 + γ1 h
Chap. 4. Polynomial Interpolation CS414 Class Notes 68
Therefore,
fi+1
γ1 = − σi+1 h,
h
fi
γ2 = − σi h,
h
and
" #
σi σi+1 fi+1
si (x) = (xi+1 − x) +
3
(x − xi ) +
3
− σi+1 h (x − xi )
h h h
" #
fi
+ − σi h (xi+1 − x)
h
" #
−3σi 3σi+1 fi+1
s%i (x) = (xi+1 − x) +
2
(x − xi ) +
2
− σi+1 h
h h h
" #
fi
− − σi h .
h
Using condition ??, i.e., s%i (xi ) = s%i−1 (xi ), we get
" # " #
fi+1 − fi fi − fi−1
−3σi h + − h(σi+1 − σi ) = 3σi h + − h(σi − σi−1 )
h h
or
∆i − ∆i−1
σi+1 + 4σi + σi−1 = i = 2, 3, . . . , n − 1,
h
where
fi+1 − fi
∆i = .
h
Using the additional conditions σ1 = σn = 0, we have
4σ2 + σ3 = (∆2 − ∆1 )/h
σi−1 + 4σi + σi+1 = (∆i − ∆i−1 )/h i = 3, 4, . . . , n − 2
σn−2 + 4σn−1 = (∆n−1 − ∆n−2 )/h.
Now, assigning
∆j − ∆j−1 fj+1 − 2fj + fj−1
gj = = ,
h h2
we have the linear system
4 1 σ2 g2
1 4 1 σ3 g3
.. .. .. .. ..
. . . . = . .
1 4 1 σn−2 gn−2
1 4 σn−1 gn−1
The tridiagonal system above, denoted by [1, 4, 1], may be factored as follows:
µ 1
1 1
λ1 1 µ 2 1
..
λ2 1 .
µ3
. .. . ..
..
.
1
λn−3 1 µn−2
The following conditions must be satisfied:
µ1 = 4, λi µi = 1, λi + µi+1 = 4
The algorithm for computing L
$ and U is given below.
Chap. 4. Polynomial Interpolation CS414 Class Notes 69
Once L
$ and U are obtained, the above system is solved as shown in Chapter ??.