Beruflich Dokumente
Kultur Dokumente
Tsung-Ming Huang
Department of Mathematics
National Taiwan Normal University, Taiwan
師
大
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 1 / 60
Outline
2 Divided Differences
3 Hermite Interpolation
師
大
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 2 / 60
Introduction
Question
In reviewing these data, how to provide a reasonable estimate of the
population, say, in 1965, or even in 2010.
師
大
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 3 / 60
Interpolation
Suppose we do not know the function f , but a few information (data)
about f , now we try to compute a function g that approximates f .
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 4 / 60
Interpolation and the Lagrange polynomial
Property
The linear function
passing through
(x0 , f (x0 )) and
(x1 , f (x1 )) is unique.
Let
x − x1 x − x0
L0 (x) = , L1 (x) =
x0 − x1 x1 − x0
and
P (x) = L0 (x)f (x0 ) + L1 (x)f (x1 ).
Then 師
大
Theorem
If (xi , yi ), xi , yi ∈ R, i = 0, 1, . . . , n, are n + 1 distinct pairs of data
point, then there is a unique polynomial Pn of degree at most n such that
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 6 / 60
Proof of Existence (by mathematical induction)
1 The theorem clearly holds for n = 0 (only one data point (x0 , y0 ))
since one may choose the constant polynomial P0 (x) = y0 for all x.
2 Assume that the theorem holds for n ≤ k, that is, there is a
polynomial Pk , deg(Pk ) ≤ k, such that yi = Pk (xi ), for 0 ≤ i ≤ k.
3 Next we try to construct a polynomial of degree at most k + 1 to
interpolate (xi , yi ), 0 ≤ i ≤ k + 1. Let
where
yk+1 − Pk (xk+1 )
c= .
(xk+1 − x0 )(xk+1 − x1 ) · · · (xk+1 − xk )
Since xi are distinct, the polynomial Pk+1 (x) is well-defined and
deg(Pk+1 ) ≤ k + 1. It is easy to verify that
師
大
Pk+1 (xi ) = yi , 0 ≤ i ≤ k + 1.
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 7 / 60
Proof of Uniqueness
Suppose there are two such polynomials Pn and Qn satisfying (1). Define
師
大
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 8 / 60
Idea
Construct polynomial P (x) with deg(P ) ≤ n as
where
1 Ln,k (x) are polynomial with degree n for 0 ≤ k ≤ n.
2 Ln,k (xk ) = 1 and Ln,k (xi ) = 0 for i 6= k.
Then
Note that we will write Ln,k (x) simply as Lk (x) when there is no
confusion as to its degree.
師
大
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 10 / 60
Example
Given the following 4 data points,
xi 0 1 3 5
yi 1 2 6 7
find a polynomial in Lagrange form to interpolate these data.
(x − 1)(x − 3)(x − 5) 1
L0 (x) = =− (x − 1)(x − 3)(x − 5),
(0 − 1)(0 − 3)(0 − 5) 15
(x − 0)(x − 3)(x − 5) 1
L1 (x) = = x(x − 3)(x − 5),
(1 − 0)(1 − 3)(1 − 5) 8
(x − 0)(x − 1)(x − 5) 1
L2 (x) = = − x(x − 1)(x − 5),
(3 − 0)(3 − 1)(3 − 5) 12
師
(x − 0)(x − 1)(x − 3) 1 大
L3 (x) = = x(x − 1)(x − 3).
(5 − 0)(5 − 1)(5 − 3) 40
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 11 / 60
Question
What’s the error involved in approximating f (x) by the interpolating
polynomial P (x)?
Theorem
Suppose
1 x0 , . . . , xn are distinct numbers in [a, b],
2 f ∈ C n+1 [a, b].
Then, ∀x ∈ [a, b], ∃ ξ(x) ∈ (a, b) such that
f n+1 (ξ(x))
f (x) = P (x) + (x − x0 )(x − x1 ) · · · (x − xn ). (2)
(n + 1)!
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 12 / 60
If x 6= xk , for all k = 0, 1, . . . , n, define
n
Y t − xi
g(t) = f (t) − P (t) − [f (x) − P (x)] .
x − xi
i=0
Since f ∈ C n+1 [a, b] and P ∈ C ∞ [a, b], it follows that g ∈ C n+1 [a, b].
Since
n
Y xk − xi
g(xk ) = [f (xk ) − P (xk )] − [f (x) − P (x)] = 0,
x − xi
i=0
and
n
Y x − xi
g(x) = [f (x) − P (x)] − [f (x) − P (x)] = 0,
x − xi
i=0
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 13 / 60
0 = g (n+1) (ξ) (3)
n
" #
dn+1 Y (t − xi )
= f (n+1) (ξ) − P (n+1) (ξ) − [f (x) − P (x)] .
dtn+1 (x − xi )
i=0 t=ξ
n
Y (t − xi ) 1
= Qn tn+1 + (lower-degree terms in t),
(x − xi ) i=0 (x − xi )
i=0
and
" n #
dn+1 Y (t − xi ) (n + 1)!
n+1
= Qn .
dt (x − xi ) i=0 (x − xi )
i=0 師
大
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 14 / 60
Equation (3) becomes
(n + 1)!
0 = f (n+1) (ξ) − [f (x) − P (x)] Qn ,
i=0 (x − xi )
i.e.,
n
f (n+1) (ξ) Y
f (x) = P (x) + (x − xi ).
(n + 1)!
i=0
Example
1 Goal: Prepare a table for the function f (x) = ex for x ∈ [0, 1].
2 xj+1 − xj = h for j = 0, 1, . . . , n − 1.
3 What should h be for linear interpolation to give an absolute error of
at most 10−6 ? 師
大
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 15 / 60
Suppose x ∈ [xj , xj+1 ]. Equation (2) implies that
f (2) (ξ)
|f (x) − P (x)| = (x − xj )(x − xj+1 )
2!
|f (2) (ξ)|
= |x − xj ||x − xj+1 |
2!
eξ
= |x − jh||x − (j + 1)h|
2
1 ξ
≤ max e max |x − jh||x − (j + 1)h|
2 ξ∈[0,1] xj ≤x≤xj+1
e
= max |x − jh||x − (j + 1)h| .
2 xj ≤x≤xj+1
師
大
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 16 / 60
Let
Then
h2
1
max |g(x)| = g
j+ h = .
xj ≤x≤xj+1 2 4
Consequently,
eh2
|f (x) − P (x)| ≤ ≤ 10−6 ,
8
which implies that
Since n = (1 − 0)/h must be an integer, one logical choice for the step 師
大
size is h = 0.001.
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 17 / 60
Difficulty for the Lagrange interpolation
1 If more data points are added to the interpolation problem, all the
cardinal functions Lk have to be recalculated.
2 We shall now derive the interpolating polynomials in a manner that
uses the previous calculations to greater advantage.
Definition
1 f is a function defined at x0 , x1 , . . . , xn
2 Suppose that m1 , m2 , . . . , mk are k distinct integers with 0 ≤ mi ≤ n
for each i.
The Lagrange polynomial that interpolates f at the k points
xm1 , xm2 , . . . , xmk is denoted Pm1 ,m2 ,...,mk (x).
師
大
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 18 / 60
Theorem
Let f be defined at distinct points x0 , x1 , . . . , xk , and 0 ≤ i, j ≤ k, i 6= j.
Then
(x − xj ) (x − xi )
P (x) = P0,1,...,j−1,j+1,...,k (x) − P0,1,...,i−1,i+1,...,k (x)
(xi − xj ) (xi − xj )
Proof: Since
deg(P0,1,...,j−1,j+1,...,k ) ≤ k − 1
and
deg(P0,1,...,i−1,i+1,...,k ) ≤ k − 1,
師
大
it implies that deg(P ) ≤ k. If 0 ≤ r ≤ k and r 6= i, j, then
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 19 / 60
(xr − xj ) (xr − xi )
P (xr ) = P0,1,...,j−1,j+1,...,k (xr ) − P0,1,...,i−1,i+1,...,k (xr )
(xi − xj ) (xi − xj )
(xr − xj ) (xr − xi )
= f (xr ) − f (xr ) = f (xr ).
(xi − xj ) (xi − xj )
Moreover
(xi − xj ) (xi − xi )
P (xi ) = P0,1,...,j−1,j+1,...,k (xi ) − P0,1,...,i−1,i+1,...,k (xi )
(xi − xj ) (xi − xj )
= f (xi )
and
(xj − xj ) (xj − xi )
P (xj ) = P0,1,...,j−1,j+1,...,k (xj ) − P0,1,...,i−1,i+1,...,k (xj )
(xi − xj ) (xi − xj )
= f (xj ).
Therefore P (x) agrees with f at all points x0 , x1 , . . . , xk . By the
師
uniqueness theorem, P (x) is the k-th Lagrange polynomial that 大
1 Denote
Qi,j = Pi−j,i−j+1,...,i−1,i .
2 Hence Qi,j , 0 ≤ j ≤ i, denotes the interpolating polynomial of degree
j on the j + 1 points xi−j , xi−j+1 , . . . , xi−1 , xi .
3 The polynomials can be computed in a manner as shown in the
following table.
x0 P0 = Q0,0
x1 P1 = Q1,0 P0,1 = Q1,1
x2 P2 = Q2,0 P1,2 = Q2,1 P0,1,2 = Q2,2
x3 P3 = Q3,0 P2,3 = Q3,1 P1,2,3 = Q3,2 P0,1,2,3 = Q3,3
x4 P4 = Q4,0 P3,4 = Q4,1 P2,3,4 = Q4,2 P1,2,3,4 = Q4,3 P0,1,2,3,4 = 師大Q4,4
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 21 / 60
x0 P0 = Q0,0
x1 P1 = Q1,0 P0,1 = Q1,1
x2 P2 = Q2,0 P1,2 = Q2,1 P0,1,2 = Q2,2
x3 P3 = Q3,0 P2,3 = Q3,1 P1,2,3 = Q3,2 P0,1,2,3 = Q3,3
x4 P4 = Q4,0 P3,4 = Q4,1 P2,3,4 = Q4,2 P1,2,3,4 = Q4,3 P0,1,2,3,4 = Q4,4
x f (x)
1.0 0.7651977
1.3 0.6200860
1.6 0.4554022
1.9 0.2818186
2.2 0.1103623
師
大
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 23 / 60
1 The first-degree approximation:
(x − x0 )Q1,0 − (x − x1 )Q0,0
Q1,1 (1.5) =
x1 − x0
(1.5 − 1.0)Q1,0 − (1.5 − 1.3)Q0,0
= = 0.5233449,
1.3 − 1.0
(x − x1 )Q2,0 − (x − x2 )Q1,0
Q2,1 (1.5) =
x2 − x1
(1.5 − 1.3)Q2,0 − (1.5 − 1.6)Q1,0
= = 0.5102968,
1.6 − 1.3
(x − x2 )Q3,0 − (x − x3 )Q2,0
Q3,1 (1.5) =
x3 − x2
(1.5 − 1.6)Q3,0 − (1.5 − 1.9)Q2,0
= = 0.5132634,
1.9 − 1.6
(x − x3 )Q4,0 − (x − x4 )Q3,0
Q4,1 (1.5) =
x4 − x3
(1.5 − 1.9)Q4,0 − (1.5 − 2.2)Q3,0 師
= = 0.5104270. 大
2.2 − 1.9
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 24 / 60
1 The second-degree approximation:
(x − x1 )Q2,1 − (x − x2 )Q1,1
Q2,2 (1.5) =
x2 − x1
(1.5 − 1.3)Q2,1 − (1.5 − 1.6)Q1,1
= = 0.5124715,
1.6 − 1.3
(x − x2 )Q3,1 − (x − x3 )Q2,1
Q3,2 (1.5) =
x3 − x2
(1.5 − 1.6)Q3,1 − (1.5 − 1.9)Q2,1
= = 0.5112857,
1.9 − 1.6
(x − x3 )Q4,1 − (x − x4 )Q3,1
Q4,2 (1.5) =
x4 − x3
(1.5 − 1.9)Q4,1 − (1.5 − 2.2)Q3,1
= = 0.5137361.
2.2 − 1.9
師
大
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 25 / 60
x f (x) 1st-deg 2nd-deg 3rd-deg 4th-deg
1.0 0.7651977
1.3 0.6200860 0.5233449
1.6 0.4554022 0.5102968 0.5124715
1.9 0.2818186 0.5132634 0.5112857 0.5118127
2.2 0.1103623 0.5104270 0.5137361 0.5118302 0.5118200
Table: Results of the higher-degree approximations
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 26 / 60
Divided Differences
Neville’s method: generate successively higher-degree polynomial
approximations at a specific point.
Divided-difference methods: successively generate the polynomials
themselves.
Suppose that Pn (x) is the nth Lagrange polynomial that agrees with f at
distinct x0 , x1 , . . . , xn . Express Pn (x) in the form
Pn (x) = a0 + a1 (x − x0 ) + a2 (x − x0 )(x − x1 ) + · · ·
+an (x − x0 )(x − x1 ) · · · (x − xn−1 ).
Determine constant a0 :
a0 = Pn (x0 ) = f (x0 )
Determine a1 :
f (x1 ) − f (x0 ) 師大
f (x0 ) + a1 (x1 − x0 ) = Pn (x1 ) = f (x1 ) ⇒ a1 = .
x1 − x0
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 27 / 60
The zero divided difference of the function f with respect to xi :
f [xi ] = f (xi )
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 28 / 60
As might be expected from the evaluation of a0 , a1 , . . . , an in Pn (x), the
required coefficients are given by
ak = f [x0 , x1 , . . . , xk ], k = 0, 1, . . . , n.
Therefore Pn (x) can be expressed as
n
X
Pn (x) = f [x0 ] + f [x0 , x1 , . . . , xk ](x − x0 )(x − x1 ) · · · (x − xk−1 ).
k=1
This formula is known as the Newton’s divided-difference formula.
xi k=0 k=1 k=2 k=3
x0 f [x0 ]
> f [x0 , x1 ]
x1 f [x1 ] > f [x0 , x1 , x2 ]
> f [x1 , x2 ] > f [x0 , x1 , x2 , x3 ]
x2 f [x2 ] > f [x1 , x2 , x3 ]
> f [x2 , x3 ]
x3 f [x3 ]
師
大
Table: Outline for the generation of the divided differences
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 29 / 60
Example
Given the following 4 points (n = 3)
xi 0 1 3 5
yi 1 2 6 7
find a polynomial of degree 3 in Newton’s form to interpolate these data.
Solution:
xi k=0 k=1 k=2 k=3
0 1
> 1
1
1 2 > 3
17
> 2 > − 120
3 6 > − 38
1
> 2
5 7
So, 師
大
1 17
P (x) = 1 + x + x(x − 1) − x(x − 1)(x − 3).
T.M. Huang (Nat. Taiwan Normal Univ.)
3Interpol. & Poly. Approx.
120 November 18, 2007 30 / 60
Theorem
Suppose f ∈ C n [a, b] and x0 , x1 , . . . , xn are distinct numbers in [a, b].
Then there exists ξ ∈ (a, b) such that
f (n) (ξ)
f [x0 , x1 , . . . , xn ] = .
n!
Proof: Define
g(x) = f (x) − Pn (x).
Since Pn (xi ) = f (xi ) for i = 0, 1, . . . , n, g has n + 1 distinct zeros in
[a, b]. By the generalized Rolle’s Theorem, ∃ ξ ∈ (a, b) such that
0 = g (n) (ξ) = f (n) (ξ) − Pn(n) (ξ).
Note that
Pn(n) (x) = n!f [x0 , x1 , . . . , xn ].
As a consequence
f (n) (ξ) 師
f [x0 , x1 , . . . , xn ] = . 大
n!
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 31 / 60
Let
xn − x0
h= = xi+1 − xi , i = 0, 1, . . . , n − 1.
n
Then each xi = x0 + ih, i = 0, 1, . . . , n. For any x ∈ [a, b], write
x = x0 + sh, s ∈ R.
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 32 / 60
The binomial formula
s s(s − 1) · · · (s − k + 1)
=
k k!
The forward difference notation 4
4f (xi ) = f (xi+1 ) − f (xi )
and
4k f (xi ) = 4k−1 f (xi+1 ) − 4k−1 f (xi ) = 4 4k−1 f (xi ) ,
for i = 0, 1, . . . , n − 1.
With this notation,
f (x1 ) − f (x0 ) 1
f [x0 , x1 ] = = 4f (x0 )
x1 − x0 h
f [x1 , x2 ] − f [x0 , x1 ]
f [x0 , x1 , x2 ] =
x2 − x0
1 1
h 4f (x1 ) − h 4f (x0 ) 1 師
= = 2 42 f (x0 ), 大
2h 2h
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 33 / 60
In general
1
f [x0 , x1 , . . . , xk ] = 4k f (x0 ).
k! hk
The Newton forward-difference formula:
n
X s
Pn (x) = f (x0 ) + 4k f (x0 ).
k
k=1
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 34 / 60
If the nodes are equally spaced with
xn − x0
h= , xi = xn − (n − i)h, x = xn + sh,
n
then
n
X
Pn (x) = f [xn ] + f [xn , xn−1 , . . . , xn−k ]sh(s + 1)h · · · (s + k − 1)h
k=1
n
X
k −s k
= f (xn ) + f [xn , xn−1 , . . . , xn−k ](−1) k! h
k
k=1
Binomial formula:
−s −s(−s − 1) · · · (−s − k + 1) s(s + 1) · · · (s + k − 1)
= = (−1)k .
k k! k!
師
大
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 35 / 60
Backward-difference:
∇k f (xi ) = ∇k−1 f (xi ) − ∇k−1 f (xi−1 ) = ∇ ∇k−1 f (xi ) ,
then
1 1 2
f [xn , xn−1 ] = ∇f (xn ), f [xn , xn−1 , xn−2 ] = ∇ f (xn ),
h 2h2
and, in general,
1
f [xn , xn−1 , . . . , xn−k ] = ∇k f (xn ).
k! hk
Newton backward-difference formula:
n
X
k −s
Pn (x) = f (x0 ) + (−1) ∇k f (xk ).
k
k=1
師
大
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 36 / 60
Hermite Interpolation
↓ ↓ ↓
m0 + 1 conditions m1 + 1 conditions · · · mn + 1 conditions
師
大
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 37 / 60
Determine a polynomial P of degree at most N , where
n
!
X
N= mi + n, (5)
i=0
師
大
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 38 / 60
Theorem
If f ∈ C 1 [a, b] and x0 , . . . , xn ∈ [a, b] are distinct, then the polynomial of
least degree agreeing with f and f 0 at x0 , . . . , xn is unique and is given by
n
X n
X
H2n+1 (x) = f (xj )Hn,j (x) + f 0 (xj )H
b n,j (x),
j=0 j=0
where
Hn,j (x) = 1 − 2(x − xj )L0n,j (xj ) L2n,j (x), b n,j (x) = (x − xj )L2 (x),
H n,j
and
(x − x0 ) · · · (x − xj−1 )(x − xj+1 ) · · · (x − xn )
Ln,j (x) = .
(xj − x0 ) · · · (xj − xj−1 )(xj − xj+1 ) · · · (xj − xn )
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 40 / 60
It implies that if i 6= j,
0
(xi ) = −2L0n,j (xj )L2n,j (xi ) + 2 1 − 2(xi − xj )L0n,j (xj ) Ln,j (xi )L0n,j (
Hn,j
= −2L0n,j (xj ) · 0 + 2 1 − 2(xi − xj )L0n,j (xj ) · 0 · L0n,j (xi ) = 0,
0
H
b n,j (xi ) = L2n,j (xi ) + 2(xi − xj )Ln,j (xi )L0n,j (xi )
= 0 + 2(xi − xj ) · 0 · L0n,j (xi ) = 0
and
0
(xi ) = −2L0n,i (xi )L2n,i (xi ) + 2 1 − 2(xi − xi )L0n,i (xi ) Ln,i (xi )L0n,i (xi
Hn,i
= −2L0n,i (xi ) + 2L0n,i (xi ) = 0,
b 0 (xi ) = L2 (xi ) + 2(xi − xi )Ln,i (xi )L0 (xi ) = 1.
H n,i n,i n,i
Therefore, ∀ i,
n
X n
X
0 0
H2n+1 (xi ) = f (xj )Hn,j (xi ) + f 0 (xj )H
b 0 (xi ) + f 0 (xi )H
n,j
b 0 (xi ) = f
n,i
j=0 j=0,j6=i 師
大
i=0
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 42 / 60
However, deg(q) = 2n + 2 whereas P has degree at most N .
Therefore, P (x) = 0, i.e. u = 0.
That is, A is nonsingular, and the Hermite interpolation problem has
a unique solution.
師
大
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 43 / 60
Divided Difference Method for Hermite Interpolation
Denote the N + 1 conditions pairs
(x0 , f (x0 )), (x0 , f 0 (x0 )), (x1 , f (x1 )), (x1 , f 0 (x1 )), . . . , (xn , f (xn )), (xn , f 0 (xn )
(z0 , f (x0 )), (z1 , f 0 (x0 )), (z2 , f (x1 )), (z3 , f 0 (x1 )), . . . , (zN −1 , f (xn )), (zN , f 0 (xn
If zi 6= zi+k , then
f [zi+1 , zi+2 , . . . , zi+k ] − f [zi , zi+1 , . . . , zi+k−1 ]
f [zi , zi+1 , . . . , zi+k ] = . 師
大
zi+k − zi
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 44 / 60
However the divided-difference formula has to be modified because there
may be repetitions among zi . Since z2i = z2i+1 = xi for each i, let
師
大
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 45 / 60
z f (z)
z0 = x0 f [z0 ] = f (x0 )
f [z0 , z1 ] = f 0 (x0 )
f [z1 ,z2 ]−f [z0 ,z1 ]
z1 = x0 f [z1 ] = f (x0 ) f [z0 , z1 , z2 ] = z2 −z0
f [z2 ]−f [z1 ]
f [z1 , z2 ] = z2 −z1
f [z2 ,z3 ]−f [z1 ,z2 ]
z2 = x1 f [z2 ] = f (x1 ) f [z1 , z2 , z3 ] = z3 −z1
0
f [z2 , z3 ] = f (x1 )
f [z3 ,z4 ]−f [z2 ,z3 ]
z3 = x1 f [z3 ] = f (x1 ) f [z2 , z3 , z4 ] = z4 −z2
f [z4 ]−f [z3 ]
f [z3 , z4 ] = z4 −z3
f [z4 ,z5 ]−f [z3 ,z4 ]
z4 = x2 f [z4 ] = f (x2 ) f [z3 , z4 , z5 ] = z5 −z3
0
f [z4 , z5 ] = f (x2 )
z5 = x2 f [z5 ] = f (x2 )
師
大
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 46 / 60
Cubic spline interpolation
The previous sections concern the approximation of an arbitrary
function on a closed interval by a polynomial. However, the
oscillatory nature of high-degree polynomials restricts their use.
Piecewise polynomial interpolation: divide the interval into a
collection of subintervals and construct different approximation on
each subinterval.
The simplest piecewise polynomial approximation is piecewise linear
interpolation.
A disadvantage of linear function approximation is that the
interpolating function is not smooth at each of the endpoints of the
subintervals. It is often required that the approximating function is
continuously differentiable.
An alternative procedure is to use a piecewise polynomial of Hermite
type. However, to use Hermite piecewise polynomials for general
interpolation, we need to know the derivatives of the function being 師大
approximated, which is frequently not available.
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 47 / 60
The most common piecewise-polynomial use cubic polynomials
between each successive pair of nodes and is called cubic spline
interpolation.
Definition
Given a function f defined on [a, b], and a set of nodes
a = x0 < x1 < · · · < xn = b, a cubic spline interpolation S for f is a
function that satisfies the following conditions:
(a) S is a cubic polynomial, denoted Sj (x), on [xj , xj+1 ] for each
j = 0, 1, . . . , n − 1;
(b) Sj (xj ) = f (xj ) and Sj (xj+1 ) = f (xj+1 ) ∀ j = 0, 1, . . . , n − 1;
(c) Sj+1 (xj+1 ) = Sj (xj+1 )∀ j = 0, 1, . . . , n − 2;
0
(d) Sj+1 (xj+1 ) = Sj0 (xj+1 )∀ j = 0, 1, . . . , n − 2;
00 (x 00
(e) Sj+1 j+1 ) = Sj (xj+1 )∀ j = 0, 1, . . . , n − 2;
(f) One of the following sets of boundary conditions is satisfied:
(i) S 00 (x0 ) = S 00 (xn ) = 0 (free or natural boundary); 師
大
(ii) S 0 (x0 ) = f 0 (x0 ) and S 0 (xn ) = f 0 (xn ) (clamped boundary).
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 48 / 60
Construction of cubic spline interpolation
Remark
In general, clamped boundary conditions lead to more accurate
approximations since they include more information about the function.
Write
Sj (x) = aj + bj (x − xj ) + cj (x − xj )2 + dj (x − xj )3 , ∀ j = 0, 1, . . . , n − 1.
That is
aj = Sj (xj ) = f (xj ).
Since Sj+1 (xj+1 ) = Sj (xj+1 ), it implies that
aj+1 = aj + bj (xj+1 − xj ) + cj (xj+1 − xj )2 + dj (xj+1 − xj )3 .
Let
hj = xj+1 − xj , ∀ j = 0, 1, . . . , n − 1.
Then 師
大
implies that
bj = Sj0 (xj ), ∀ j = 0, 1, . . . , n − 1.
0
Applying Sj+1 (xj+1 ) = Sj0 (xj+1 ) gives
cj+1 = cj + 3dj hj , ∀ j = 0, 1, . . . , n − 1.
Hence
cj+1 − cj
dj = . (9)
師
大
3hj
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 50 / 60
Substituting dj in (9) into (7) and (8), it obtains
h2j
aj+1 = aj + bj hj + (2cj + cj+1 ) (10)
3
and
1 hj
bj = (aj+1 − aj ) − (2cj + cj+1 ), (12)
hj 3
and then
1 hj−1
bj−1 = (aj − aj−1 ) − (2cj−1 + cj ). (13)
hj−1 3
師
大
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 51 / 60
Substituting (12) and (13) into (11), we get
3 3
hj−1 cj−1 + 2(hj−1 + hj )cj + hj cj+1 = (aj+1 − aj ) − (aj − aj−1 ).(14
hj hj−1
for each j = 1, 2, . . . , n − 1.
Theorem
If f is defined at a = x0 < x1 < · · · < xn = b, then f has a unique natural
spline interpolant S on the nodes x0 , x1 , . . . , xn that satisfies
S 00 (a) = S 00 (b) = 0.
cn = S 00 (xn )/2 = 0,
0 = S 00 (x0 ) = 2c0 + 6d0 (x0 − x0 ) ⇒ c0 = 0.
師
大
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 52 / 60
Substituting c0 = cn = 0 into (14), it produces a linear system Ax = b,
where A is an (n + 1) × (n + 1) matrix
1 0
h0 2(h0 + h1 ) h1
h1 2(h1 + h2 ) h2
A = ,
.. .. ..
. . .
hn−2 2(hn−2 + hn−1 ) hn−1
0 1
0
3 3 c0
h1 (a2 − a1 ) − h0 (a1 − a0 )
c1
..
b = , x = .. .
.
3 3
.
hn−1 (an − an−1 ) − hn−2 (an−1 − an−2 )
cn
0
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 53 / 60
Solving tridiagonal linear system
Let
1 u12
`11 1 u23
`21 `22
.. ..
A = LU ≡
.. .. . . .
. .
..
`n,n−1 `nn
. un−1,n
1
a11 = `11 ,
ai,i−1 = `i,i−1 , for i = 2, 3, . . . , n,
aii = `i,i−1 ui−1,i + `ii , for i = 2, 3, . . . , n,
ai,i+1 = `ii ui,i+1 , for i = 1, 2, . . . , n − 1.
師
大
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 54 / 60
It implies that
and, for i = 2, . . . , n − 1,
`i,i−1 = ai,i−1 ,
`ii = aii − `i,i−1 ui−1,i ,
ui,i+1 = ai,i+1 /`ii ,
and
`n,n−1 = an,n−1 ,
`nn = ann − `n,n−1 un−1,n .
師
大
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 55 / 60
Forward substitution
Solve Ly = b
`11 y1 = b1 ,
`21 y1 + `22 y2 = b2 ,
⇒ ..
.
`n,n−1 yn−1 + `nn yn = bn .
y1 = b1 /`11 ,
y2 = (b2 − `21 y1 )/`22 ,
⇒ ..
.
yn = (bn − `n,n−1 yn−1 )/`nn .
y1 = b1 /`11 ,
⇒
yi = (bi − `i,i−1 yi−1 )/`ii , for i = 2, . . . , n.
師
大
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 56 / 60
Back substitution
Solve U x = y,
x1 + u12 x2 = y1 ,
..
⇒ .
x n−1 + u x
n−1,n n = yn−1 ,
xn = yn ,
xn = yn ,
xn−1 = yn−1 − un−1,n xn ,
⇒ ..
.
x1 = y1 − u12 x2 ,
xn = yn ,
⇒
xi = yi − ui,i+1 xi+1 , for i = n − 1, . . . , 1.
師
大
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 57 / 60
Theorem
If f is defined at a = x0 < x1 < · · · < xn = b and differentiable at a and
b, then f has a unique clamped spline interpolant S on the nodes
x0 , x1 , . . . , xn that satisfies S 0 (a) = f 0 (a) and S 0 (b) = f 0 (b).
1 h0
f 0 (a) = (a1 − a0 ) − (2c0 + c1 ).
h0 3
Consequently,
3
2h0 c0 + h0 c1 = (a1 − a0 ) − 3f 0 (a).
h0
Similarly,
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 58 / 60
so Eq. (12) with j = n − 1 implies that
an − an−1 hn−1
f 0 (b) = − (2cn−1 + cn ) + hn−1 (cn−1 + cn )
hn−1 3
an − an−1 hn−1
= + (cn−1 + 2cn ),
hn−1 3
and
3
hn−1 cn−1 + 2hn−1 cn = 3f 0 (b) − (an − an−1 ).
hn−1
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 59 / 60
determine the linear system Ax = b, where
2h0 h0
h0 2(h0 + h1 ) h1
h 1 2(h 1 + h2 ) h2
A = ,
. .. . .. ..
.
hn−2 2(hn−2 + hn−1 ) hn−1
hn−1 2hn−1
3 0
h0 (a1 − a0 ) − 3f (a)
3 3 c0
h1 (a2 − a1 ) − h0 (a1 − a0 )
c1
..
b = , x = .
. ..
3 (a − a 3
.
n−1 ) − hn−2 (an−1 − an−2 )
hn−1 n
cn
3f 0 (b) − hn−13
(an − an−1 )
T.M. Huang (Nat. Taiwan Normal Univ.) Interpol. & Poly. Approx. November 18, 2007 60 / 60