Professional Documents
Culture Documents
2
These notes are used by myself in the course. They are provided to students. These
notes are self-contained, and covers almost everything we go through in class. However,
if a student shall be interested in more detailed discussion, he/she should consult the
recommended textbook.
Text: Guide to Scientific Computing, 2nd edition, by Peter Turner. CRC Press, ISBN
0-8493-1242-6.
Chapter 2
Polynomial interpolation
2.1
Introduction
Problem description:
Given (n + 1) points, (xi , yi ), i = 0, 1, 2, , n, with distinct xi , probably sorted
x0 < x1 < x2 < < xn ,
find a polynomial of degree n, call it Pn (x),
Pn (x) = a0 + a1 x + a2 x2 + + an xn
such that it interpolates these points:
Pn (xi ) = yi ,
i = 0, 1, 2, , n
1 0 0
a0
1
1 1 1 a1 = 0
a2
0.5
1 23 94
Easy to solve in Matlab (see Homework 1)
a0 = 1,
Then
a1 = 1/4,
a2 = 3/4.
3
1
P2 (x) = 1 x x2 .
4
4
i = 0, 1, 2, , n
In matrix-vector form
1 x0 x20
1 x1 x2
1
.. ..
.. . .
. .
.
.
2
1 xn xn
a0
y0
xn0
n
x1 a1 y1
.. .. = ..
. . .
xnn
an
yn
:
:
:
2.2
Lagrange interpolation
Given points: x0 , x1 , , xn
Define the cardinal functions: l0 , l1 , , ln : P n , which are polynomials of degree n,
and satisfy the properties
1 , i=j
i = 0, 1, , n
li (xj ) = ij =
0 , i 6= j
In words: the cardinal function li (x) takes value 1 for x = xi , but for all other interpolating points xj with j 6= i, it takes the value 0. For x value between the points xi , it
does not set any restrictions.
The Lagrange form of the interpolation polynomial is
Pn (x) =
n
X
li (x) yi .
i=0
n
X
li (xj ) yi = yj ,
j.
i=0
x x0 x x1
x xi1 x xi+1
x xn
xi x0 xi x1
xi xi1 xi xi+1
xi xn
One can easily check that li (xi ) = 1 and li (xk ) = 0 for i 6= k, i.e., li (xk ) = ik .
Example 2. Consider again (same as in Example 1)
xi 0 2/3 1
yi 1 0.5 0
Write the Lagrange polynomial.
Answer. We first compute the cardinal functions
l0 (x) =
l1 (x) =
l2 (x) =
x 2/3 x 1
3
2
= (x )(x 1)
0 2/3 0 1
2
3
x1
9
x0
= x(x 1)
2/3 0 2/3 1
2
2
x 0 x 2/3
= 3x(x )
1 0 1 2/3
3
so
P2 (x) = l0 (x)y0 + l1 (x)y1 + l2 (x)y2
3
2
9
=
(x )(x 1) x(x 1)(0.5) + 0
2
3
2
3 2 1
= x x+1
4
4
This is the same as in Example 1.
Pros and cons
of Lagrange polynomial:
2.3
x0 x1
y0 y1
xn
yn
P0 (x) = y0
n=1
P1 (x) = P0 (x) + a1 (x x0 )
yn Pn1 (xn )
(xn x0 )(xn x1 ) (xn xn1 )
(2.1)
(2.2)
One can easily check that such polynomial does the interpolating job!
(Detail: For i = 0, 1, , n 1, we have Pn (xi ) = Pn1 (xi ) = yi , since the last term in (2.1)
is 0. Now, for i = n, we have Pn (xn ) = yn since an is chosen as (2.2) which guarantees
this interpolating property. )
This now give the Newtons form for interpolating polynomial:
Pn (x) = a0 + a1 (x x0 ) + a2 (x x0 )(x x1 ) +
+an (x x0 )(x x1 ) (x xn1 ),
where the coefficient an could be determined by (2.2).
There is a more elegant way of computing these coefficients, which we will study now.
The constants ai s are called divided difference, written as
a0 = f [x0 ],
a1 = f [x0 , x1 ]
ai = f [x0 , x1 , , xi ]
(2.3)
Proof for (2.3): (optional) The proof is done through induction. The formula is clearly
true for n = 0 and n = 1. Now, assume that it holds for n = k 1, i.e., one can use it
k1
+ (l.o.t.)
(2.4)
(2.5)
x xk
(q(x) Pk1 (x)) .
xk x0
proving (2.3).
Computation of the divided differences: We compute the f s through the following
table:
f [x0 ] = y0
x1
f [x1 ] = y1
f [x0 , x1 ] =
f [x1 ]f [x0 ]
x1 x0
x2
f [x2 ] = y2
f [x1 , x2 ] =
f [x2 ]f [x1 ]
x2 x1
..
.
..
.
..
.
xn
f [xn ] = yn
f [xn1 , xn ] =
f [xn ]f [xn1 ]
xn xn1
f [x0 , x1 , x2 ] =
..
.
..
f [xn2 , xn1 , xn ] =
...
.
f [x0 , x1 , , xn ]
Example : Use Newtons divided difference to write the polynomial that interpolates
the data
xi 0 1 2/3 1/3
yi 1 0 1/2 0.866
Answer. Set up the triangular table for computation
0
1
2/3
1/3
1
0
0.5
0.8660
-1
-1.5
-1.0981
-0.75
-0.6029
0.4413
So we have
a0 = 1,
a1 = 1,
a2 = 0.75,
a3 = 0.4413,
x0 = 0,
x1 = 1,
x2 = 2/3,
x3 = 1/3,
10
Proof. : The existence of such a polynomial is obvious, since we can construct it using
one of our methods.
Regarding uniqueness: Assume we have two polynomials, call them p(x) and q(x), of
degree n, both interpolate the data, i.e.,
p(xi ) = yi ,
q(xi ) = yi ,
i = 0, 1, , n
Now, let g(x) = p(x) q(x), which will be a polynomial of degree n. Furthermore,
we have
g(xi ) = p(xi ) q(xi ) = yi yi = 0,
i = 0, 1, , n
So g(x) has n + 1 zeros. We must have g(x) 0, therefore p(x) q(x).
2.4
Given a function f (x) on the interval a x b, and a set of distinct points xi [a, b],
i = 0, 1, , n. Let Pn (x) be a polynomial of degree n that interpolates f (x) at xi ,
i.e.,
Pn (xi ) = f (xi ),
i = 0, 1, , n
Define the error
e(x) = f (x) Pn (x),
x [a, b].
Y
1
e(x) =
f (n+1) () (x xi ),
(n + 1)!
i=0
11
Pn+1
i=0
and a constant
c=
f (a) Pn (a)
,
W (a)
i = 0, 1, , n
and
(a) = f (a) Pn (a) cW (a) = 0
So, has at least (n + 2) zeros.
Here goes our deduction:
(x) has at least
(x) has at least
(x) has at least
(n+1) (x) has at least
n+2
n+1
n
..
.
zeros.
zeros.
zeros.
zero.
Call it .
So we have
(n+1) () = f (n+1) () 0 cW (n+1) () = 0.
Use
W (n+1) = (n + 1)!
we get
f (n+1) () = cW (n+1) () =
f (a) Pn (a)
(n + 1)!.
W (a)
Y
1
1
e(x) = f (x) Pn (x) =
f (n+1) ()W (x) =
f (n+1) () (x xi ).
(n + 1)!
(n + 1)!
i=0
Example n = 1, x0 = a, x1 = b, b > a.
12
1
1
(b a)2
1
f () |(x a)(x b)|
f
=
f
(b a)2 .
2
2
4
8
h=
n
Y
ba
,
n
|x xi |
i=0
i = 0, 1, , n.
1 n+1
h
n!
4
where
Mn+1 n+1
1
(n+1) n+1
h
(x) h
|e(x)|
f
4(n + 1)
4(n + 1)
Mn+1 = max f (n+1) (x) .
x[a,b]
Example Consider interpolating f (x) = sin(x) with polynomial on the interval [1, 1]
with uniform nodes. Give an upper bound for error, and show how it is related with
total number of nodes with some numerical simulations.
Answer. We have
so the upper bound for error is
(n+1)
(x) n+1
f
n+1
|e(x)| = |f (x) Pn (x)|
4(n + 1)
n+1
2
.
n
error bound
4.8 101
3.2 103
1.8 109
measured error
1.8 101
1.2 103
6.6 1010
Problem with uniform nodes: peak of errors near the boundaries. See plots.
13
x
i = cos( ni ),
x
i = 12 (a + b) + 12 (b a) cos( ni ),
i = 0, 1, , n
i = 0, 1, , n
|x x
k | = 2n
k=0
n
Y
|x xk |
k=0
1
(n+1) n
(x) 2 .
f
(n + 1)!
Example Consider the same example with uniform nodes, f (x) = sin x. With Chebyshev nodes, we have
1
n+1 2n .
|e(x)|
(n + 1)!
The corresponding table for errors:
n
4
8
16
error bound
1.6 101
3.2 104
1.2 1011
measured error
1.15 101
2.6 104
1.1 1011
1
2i + 1
1
(a + b) + (b a) cos(
),
2
2
2n + 2
i = 0, 1, , n
x 6= xi .
14
n
Y
(a xi ).
i=0
1 (n)
f (),
n!
[a, b].
Proof. Let Pn1 (x) interpolate f (x) at x0 , , xn1 . The error formula gives
n
Y
1
f (xn ) Pn1 (xn ) = f (n) () (xn xi ),
n!
(a, b).
i=0
n
Y
(xn xi )
i=0
:
:
f [x0 , x1 , x2 ] =
2.5
1
1
[f (x + h) 2f (x) + f (x + h)] = f (),
2
2h
2
[x h, x + h].
Here we briefly discuss the convergence issue. The main question to ask is: As n +,
does the polynomial Pn (x) converge to the function f (x)?
15
Convergence may be understood in different ways. Let e(x) = f (x) Pn (x) be the error
function. We list some examples of convergence:
uniform convergence :
L1 convergence :
L2 convergence :
lim
max |e(x)| = 0
Z b
|e(x)| dx = 0
lim
n+ a
Z b
|e(x)|2 dx = 0
lim
n+ axb
n+ a
For uniform nodes, it is known that for some functions f (x), the error grows unbounded
as n +. We have observed it in our simulation, and it is very bad news.
It is possible to have convergence: For each function f (x), there is a way of designing a
sequence of nodes {xi }ni=0 , such that |e(x)| 0 as n +.
The sequence is different for each function.
With the wrong sequence, there will be no convergence!
This is not practical!