ch1 PPT
ch1 PPT
§1 Interpolating Problem
§2 Lagrange Interpolation
§3 Newton’s Interpolation
§4 Interpolation on Equally Spaced Nodes
§5 Hermite Interpolation
§6 Cubic Spline Interpolation
§1.1 Interpolating Problem
Problem
How to Solve
Concept
Time t (Hour) 2 8 14 20
Temperature -4.6 -5.7 6.8 2.6
T(℃)
How to solve?
Find the approximate function g(x)
of y=f(x)
Requirements of g(x) Algebraic Polynomial
Simple, Easily calculate
y=f(x)
g(x) f(x)
y=g(x)
x0 x1 x2 x x3 x4
Polynomial Interpolation
Function f ( x) C[a, b] , and the values of f ( x) at n 1
different points x 0 , x1 ,, x n are yi f ( xi )(i 0,1, , n) .
Determine a polynomial of degree no more than n
Pn ( x) a0 a1x an xn
to satisfy
Pn ( xi ) yi (i 0,1, , n) .
Example
Time t (Hour) 2 8 14 20
Temperature T(℃) -4.6 -5.7 6.8 2.6
From the interpolating condition the parameters
a i should satisfy the linear system
a 0 a1 x0 a x a x y 0
2
2 0
n
n 0
a 0 a1 x1 a 2 x1 a n x1 y1
2 n
a a x a x 2 a x n y
0 1 n 2 n n n n
1 xn xn2 xnn
810
6
5
4
0
2
TT
-5
0
-10
-2
-4
-15
-6
0
-20 5 10 15 20
0 5 10t 15 20
t
P3 (t ) 4.0259 5.7194t 0.7500t 2 0.0234t 3
Remark:Data come from National Meteorological Center of CMA
§1.2 Lagrange Interpolation
Interpolating Remainder
= y +
x 0 x1 0 x1 x 0
y 1
l ( x) y
i 0
i i
l0(x) l1(x)
n 1 Determine li(x),i = 0, …, n to satisfy li(xj)=ij ;
n
Pn ( x ) l (x) y
i0
i i , and then we have Pn(xi) = yi .
First construct n 1 polynomials of n degree li (x )
to satisfy
0 j i
li ( x j ) i, j 0,1,, n
1 j i
n
(x x j )
j 0 n (x x j )
j i
li ( x ) n
( xi x j )
(x
j 0
i xj) j 0
j i
j i
Quadratic Interpolation(n=2)
L2 ( x) y0l0 ( x) y1l1 ( x) y2l2 ( x)
( x x1 )( x x2 ) ( x x0 )( x x2 ) ( x x0 )( x x1 )
l0 ( x) l1 ( x) l2 ( x)
( x0 x1 )( x0 x2 ) ( x1 x0 )( x1 x2 ) ( x2 x0 )( x2 x1 )
Example:100 10, 121 11, 144 12 are given.
Use the linear interpolation and the quadratic
interpolation to approximate 115.
Note:
The interpolating polynomial is NOT unique
unless its degree is constrained to be no greater
than n.A counterexample is n
P( x ) Ln ( x ) a( x ) ( x xi )
i 0
where p(x) can be a polynomial of any degree.
Interpolating Remainder
Suppose a x0 x1 xn b and f Cn + 1[a, b].
Consider the truncation error Rn ( x ) f ( x ) Pn ( x )
n
Rn(x) has
Rolle’s at least If
Theorem: (x)roots
n+1 Rnsmooth
is sufficiently ( x) K (with
x) (x
0 1
( x ) =xi)(x ) = 0,
i 0
then therex exists
Fix any all(xi0=, x0,1)…,
xi for such
n. that ’(the
Define ) =function
0. g for t in [a, b] by
In general, if (x0g(t)
) =
n
(xR ) = (x ) = 0
1 ( t ) 2 K ( x )
n (t xi )
i 0 that ( ) ( ) 0
There exist 0 ( x0 , x1 ), 1 ( x1 , x2 ) such
g ( n1) ( x ) 0, x (a, b)
0 1
g(x) has n+2 distinct roots x0 … xn x
There exists ( 0 , 1 ) such that ( ) 0
f((nx10) )(x
) P(nn( x1 )n()x )0 K ( x )( n 1) ! Rn( n 1 ) ( x ) K ( x ) ( n 1) !
( n 1 )
( x ) (a , b ) such thatf( n1)(( ) ) 0n
( n)
Theref exists
K ( x) Rn ( x ) x
(x x )
( n 1) ! ( n 1) ! i 0
i
Interpolating Remainder
Note:
Since in most of the cases x cannot be determined, we obtain
the upper bound of f (n+1) instead. That is, estimate an Mn+1 such
M n 1 n
( n 1)!
that f
( n 1 )
( x ) M n1 for all x(a,b) and take | x xi |
i 0
11.5 12 11.5 11
ln11.5 P1 (11.5) 2.3979 2.4849 2.4414
11 12 12 11
(ln )
R1 (11.5) (11.5 11)(11.5 12) 1.09 103
2!
Quadratic interpolation x 0 11 x1 12 x 2 13
(ln )(3)
R2 (11.5) (11.5 11)(11.5 12)(11.5 13)
3!
9.3938 105
Example There is a table of the values of f ( x ) sin x
at equally spaced nodes. Suppose the step size of the
function table is h , that is the distance between
adjacent nodes. Determine h so that the truncation
error is not more than 5 105 when using linear
interpolation to approximate sin x .
Solution. From equation (1.17), for arbitrary adjacent nodes xk , xk 1 the
linear interpolating remainder is
f "( k )
R1 ( x) ( x xk )( x xk 1 ) , k ( xk , xk 1 ) .
2!
So when x [ x , x ] , we have
k k 1
1 1
( x xk )( x xk 1 ) ( xk 1 xk ) 2 h 2
4 4 .
Furthermore,
f "(k ) M
R1 ( x) ( x xk )( x xk 1 ) 2 h2 ,
2! 8
where M 2 max f ( x) . When f ( x) sin x , we have
M 2 max (sin x) max sin x 1 .
Therefore,
1 2
h 5 10 5 ,
8
that is,
h 0.02 .
The allowed maximum step size of the function table is 0.02. ■
§1.3 Divided Differences
and Newton’s Interpolation
Divided differences
Newton’s interpolation
Basic Idea of Newton’s Interpolation
It is easy to calculate the Lagrange polynomial.
When you want to take more interpolating
points into account. Then all the Lagrange
basis, li(x), will have to be re-calculated.
Newton’s Nn ( x) a0 a1 ( x x0 ) a2 ( x x0 )( x x1 ) ...
Interpolation an ( x x0 )...( x xn1 )
Divided Differences
f ( xi ) f ( x j ) The 1st divided difference
f [ xi , x j ] ( i j , xi x j )
xi x j of f w.r.t. xi and xj
f [ x0 , x1 , ... , xk ] f [ x1 , ... , xk , xk 1 ]
f [ x0 , ... , xk 1 ]
x 0 x k 1
f [ x0 , ... , xk 1 , xk ] f [ x0 , ... , xk 1 , xk 1 ]
x k x k 1
Properties of Divided Differences
k
f ( xi )
f x0 , x1 , , xk
k
1. where k 1 ( x i ) ( x i x j )
i 0 k 1 ( xi ) j 0
j i
2. f xi , x j , xk f x j , xi , xk f x j , xk , xi
f ( )
(m)
4. f [ xi 0 , xi1 , , xim ]
m!
Newton’s Interpolation
N n ( x ) a0 a1 ( x x0 ) a2 ( x x0 )( x x1 ) ... an ( x x0 )...( x xn1 )
f ( x ) f ( x0 ) ( x x0 ) f [ x , x0 ] 1
f [ x , x0 ] f [ x0 , x1 ] ( x x1 ) f [ x , x0 , x1 ] 2
…………
f [ x , x0 , ... , xn1 ] f [ x0 , ... , xn ] ( x xn ) f [ x , x0 , ... , xn ] n1
f ( x ) f ( x0 ) f [ x0 , x1 ]( x x0 ) f [ x0 , x1 , x2 ]( x x0 )( x x1 ) ...
f [ x0 , ... , xn ]( x x0 )...( x xn1 )
f [ x , x0 , ... , xn ]( x x0 )...( x xn1 )( x xn )
Nn(x) ai = f [ x0, …, xi ]
Rn(x)
Note:
Since the n-th interpolating polynomial is unique, Nn(x) Pn(x).
They must have the same truncation error. That is,
f ( n1) ( x )
f [ x , x0 , ... , xn ] k 1 ( x ) k 1 ( x )
( n 1) !
f ( k ) ( )
f [ x0 , ... , x k ] , ( xmin , xmax )
k!
The procedure is as follows.
f (x0)
f (x1) f [x0, x1]
f (x2) f [x1, x2] f [x0, x1 , x2]
… …… ……
f (xn1) …… ……
f (xn) f [xn1, xn] f [xn2, xn1, xn] f [x0, …, xn]
f (xn+1) f [xn, xn+1] f [xn1, xn, xn+1] f [x1, …, xn+1] f [x0, …, xn+1]
Use Newton’s interpolation to approximate ln11.5.
xi yi ln xi First Second
Divided Divided
Differences Differences
11 2.3979 1
12 2.4849 0.0870
x 11
13 2.5649 0.0800 -0.0035 ( x 11)( x 12)
Linear Interpolation
ln11.5 N1 (11.75)
2.3979 0.0870(11.5 11) 2.4414
Quadratic Interpolation
ln11.5 N 2 (11.75)
N1 (11.75) ( 0.0035) (11.5 11)(11.5 12)
2.4414 0.000875
2.442275
§1.4 Difference and Interpolation on
Equally Spaced Nodes
Difference
Forward f i f i1 f i
k 1
Difference f i (
k
f i ) k 1 f i1 k 1 f i
Backward f i f i f i1
Difference k fi k 1 f i k 1 f i 1
Central k f i k 1 f i k 1 f i
1 1
2 2
Difference where f i 1 f ( x i h2 )
2
Properties of Difference
Linearity: ( a f ( x ) b g ( x )) a f b g
If f (x) is a polynomial of degree m , then k f ( x ) (0 k m ) is a
polynomial of degree m – k and k f ( x ) 0 ( k m )
The values of the differences can be obtained from the function
n
n n
n
fk ( 1) j f k (1) n j
n n
f n k j f k j n
j0 j j 0 j
k f 0 From Rn
f [ x0 , ... , x k ]
k! hk
fn
k k f 0
( )
(k )
f [ xn , xn 1 , ... , xn k ] f
h
k
k ! hk
Newton’s
interpolation N n ( x ) f ( x0 ) f [ x0 , x1 ]( x x0 ) ... f [ x0 , ... , xn ]( x x0 )...( x xn1 )
n t
Let x x n t h , then N n ( x ) N n ( xn t h) (1) k f ( xn )
k
k 0 k
f ( n 1) ( )
Rn ( x ) t (t 1)...( t n )h n 1 , ( x0 , xn )
(n 1)!
Example: Find cubic interpolating polynomial by Newton
forward difference formula. And approximate f(2.8) by
Newton backward difference formula of degree 2.
xi 0 1 2 3
f(xi) 1 1.6487 2.7183 4.4871
§1.5 Hermite Interpolation
Hermite Interpolation
Interpolating Remainder
Example
Not only the values of the approximate function are equal
to that of the primary function, but also the derivatives
are also equal. The interpolating function (x) satisfy
(xi) = f (xi), ’ (xi) = f ’ (xi)
,…, (mi) (xi) = f (mi) (xi).
Note:
Given N conditions (and hence N equations), a polynomial of
degree N 1 can be determined.
The interpolating polynomial that agrees with f and all its
derivatives of order m0 at one point x0 is just the Taylor
polynomial
f ( m0 ) ( x 0 )
P ( x ) f ( x0 ) f ( x0 )( x x0 ) ... ( x x 0 ) m0
m0 !
f ( m0 1) ( )
with remainder R( x ) f ( x ) ( x ) ( x x0 )( m0 1)
(m0 1)!
The case considering f and f’ gives the Hermite polynomials.
Hermite Interpolation
H ( xi ) y i , H ( xi ) y i, (i 0,1,, n)
0 j i
hi ( x j )
1 j i , hi( x j ) 0 (i 0,1, , n)
0 j i
hi ( x j ) 0, hi( x j )
1 j i (i, j 0,1, , n)
n
H ( x) yi hi ( x) yihi ( x )
i 0
x x0 x x1 2 x x1 x x0 2
H ( x) (1 2 )( ) y0 (1 2 )( ) y1
x1 x0 x0 x1 x 0 x1 x1 x0
x x1 2 x x0 2
( x x0 )( ) y0 ( x x1 )( ) y1
x0 x1 x1 x0
Method 2(Method of Order Reducing)
Suppose
H ( x ) N n ( x ) Pn ( x )n 1 ( x ),
where N n ( x ) is the Newton's interpolating polynomial of
f ( x ) passing through points x0 , , xn , and we have
N n ( xi ) f ( xi ), i 0,1, , n.
Polynomial Pn ( x ) is of degree n and to be determined.
n
n 1 ( x ) ( x xi )
i 0
Obvious H ( xi ) N n ( xi ) Pn ( xi )n1 ( xi ) yi
H ( xi ) N n ( xi ) Pn ( xi ) n 1 ( xi ) y i
yi 0 1
y i 3 9
H ( x) 10 x 12 x 3x
3 2
Method of order reducing
1 0
N1 ( x) 0 ( x 0) x
1 0
H ( x ) 1 bx( x 1) (a bx)( x 1 x )
H (0) 1 a 3 H (1) 1 a b 9
a 2, b 10
H ( xi ) f ( xi ), H ( xi ) f '( xi ), (i 0,1, , n)
is unique.
Interpolating Remainder
P( xi ) f ( xi ), i 0,1, 2
P( x1 ) f ( x1 )
Piecewise Interpolation
Two Remarks
Disadvantage of Polynomial Interpolation
1
Example: Consider the Lagrange polynomial Ln(x) of f ( x) on
1 x2
[5, 5]. Take xi 5 10 i ( i 0, ... , n)
n
2.5
-0.5
-5 -4 -3 -2 -1 0 1 2 3 4 5
Piecewise Linear Interpolation
Approximate f (x) by linear polynomials on each subinterval [ xi 1 , xi ] :
x xi x xi 1
f ( x ) Pi ( x ) yi 1 yi for x [ xi 1 , xi ]
xi 1 xi xi xi 1
uniform
Let h max | xi 1 xi | . Then P h ( x )
f ( x) as h 0.
y
y=f(x)
No longer smooth.
xi 0 1 2 3 4 5
f ( xi ) 1.00000 0.50000 0.20000 0.10000 0.05882 0.3846
x 1 x0
( x) 1.00000 0.50000 1 0.5 x
0 1 1 0
x 1 x0
( x) 1.00000 0.50000 1 0.5 x
0 1 1 0
Similarly,
1 0.5 x x 0,1
0.8 0.3 x x (1,2]
( x ) 0.4 0.1x x ( 2,3]
0.22354 0.04118x x (3,4]
0.14026 0.02036x x ( 4,5]
f(x) H(x)
S(x)
Described by the first derivatives at nodes
x x j 1 x x j 2 x x j x x j 1 2
S j ( x) (1 2 )( ) y j 1 (1 2 )( ) yj
hj hj hj hj
x xj x x j 1
( x x j 1 )( ) m j 1 ( x x j )(
2
)2 m j ()
hj hj
x x j 1 , x j ( j 1, , n)
6 x 2 xi 1 4 xi 6 x 4 xi 1 2 xi 6( xi 1 xi 2 x)
Si( x) 2
mi 1 2
mi 3
( f ( xi ) f ( xi 1 ))
hi hi hi
6 x 2 xi 4 xi 1 6 x 4 xi 2 xi 1 6( xi xi 1 2 x)
Si1 ( x) 2
mi 2
mi 1 3
( f ( xi 1 ) f ( xi ))
hi 1 hi 1 hi 1
2 4 6
Si( xi ) mi 1 mi 2 ( f ( xi ) f ( xi 1 ))
hi hi hi
.
4 2 6
Si1 ( xi ) mi mi 1 2 ( f ( xi 1 ) f ( xi ))
hi 1 hi 1 hi 1
S ( x) C (2)
a, b, Si1( xi ) Si( xi )
Described by the first derivatives at nodes
2 4 4 2
mi 1 ( )mi mi 1 6( f ( xi1 ) 2 f ( xi ) f ( xi ) f ( xi 1 )
2
)
hi hi hi 1 hi 1 hi 1 hi
hi 1 hi
i , i 1 i
hi hi 1 hi hi 1
gi 3( i f [ xi , xi 1 ] i f [ xi 1 , xi ])
i mi 1 2mi i mi 1 gi
n+1unknowns,n1 equations i 1, 2, , n 1
We still need 2 boundary conditions
Boundary Conditions (a)
(a) The first derivatives at two end points are given, that is,
m0 f ( x0 ) mn f ( xn )
2 1 m1 g1 1 f ( x0 )
2 2 m g
2 2 2
n 2 2 n 2 mn 2 gn2
n 1 2 mn 1 g n 1 n 1 f ( xn )
Boundary Conditions (b)
(b) The second derivatives at two end points are given, that is,
2 1 m0 g0
2 1 m g
1 1 1
n 2 n mn 1 g n 1
1 2 mn g n
f ( x1 ) f ( x0 ) h1 f ( xn ) f ( xn1 ) hn
g0 3 f ( x0 ) gn 3 f ( xn )
h1 2 hn 2
EX. Given the data table
x 0 1 2 3
f(x) 0 2 3 6
f′(x) 1 0
Determine the cubic spline interpolating
function according to the above data.
Solution.
For [0,1],
EX. Given the data table
x 0 1 2 3
f(x) 0 2 3 6
f′(x) 1 0
Determine the cubic spline interpolating
function according to the above data.
Described by the second derivatives at nodes
S ( x) Si ( x) is a cubic polynomial on [ xi 1 , xi ],
so Si( x) is linear,by interpolation we have
x xi 1 x xi
Si( x) M i M i 1
hi hi
intergration
( x xi 1 ) ( x xi )
3 3
Si ( x ) M i M i 1 C1 ( x xi ) C2
6hi 6hi
M i hi2 M i hi2
Si ( xi ) yi , Si ( xi 1 ) yi 1 C 2 yi C2 yi
6 6
Described by the second derivatives at nodes
M i hi2 M i 1hi2
C1hi ( yi ) yi
6 6
1 M i hi2 M i 1hi2
C1 yi ( yi 1 )
hi 6 6
( x xi 1 )3
( x xi ) 3
So Si ( x) M i M i 1
6hi 6hi
M h x xi 1
2
M h x xi 2
( yi ) i i
( yi 1 ) i 1 i
(*)
6 hi 6 hi
i 1, n
( xi x)2 ( x xi 1 )2 f ( xi ) f ( xi 1 ) M i M i 1
Si( x) M i 1 Mi hi
2hi 2hi hi 6
hi hi
Si( xi ) M i 1 M i f [ xi 1 , xi ]
6 3
hi 1 hi 1
Si1 ( xi ) Mi M i 1 f [ xi , xi 1 ]
3 6
S ( x) C (2)
a, b , Si1 ( xi ) Si( xi )
.
hi hi hi 1 hi 1
M i 1 Mi M i 1 f [ xi , xi 1 ] f [ xi 1 , xi ]
6 3 6
Described by the second derivatives at nodes
i M i 1 2M i i M i 1 d i
i 1, 2, , n 1
hi 1 hi
i , i 1 i
hi 1 hi hi 1 hi
.
di 6 f [ xi 1 , xi , xi 1 ]
n+1unknowns,n1 equations
S1( x0 ) f ( x0 ), Sn ( xn ) f ( xn )
2 1 M 0 d0
2 1 M d
1 1 1
n 1 2 n 1 M n 1 d n 1
1 2 M n d n
6 6
2M 0 M1 ( f [ x0 , x1 ] f ( x0 )) d0 M n1 2M n ( f ( xn ) f [ xn1 , xn ]) dn
h1 hn
Boundary Conditions (b)
(b) The second derivatives at two end points are given, that is,
M 0 f ( x0 ) M n f ( xn )
2 1 M 1 d1 1 f ( x0 )
2 2 M d
2 2 2
n 2 2 n 2 M n 2 d n 2
n 1 2 M n 1 d n 1 n 1 f ( xn )
EX Given the data table
x 2 4 6
f(x) 3 7 13
f′(x) 1 -1
Determine the cubic spline interpolating
function according to the above data.
h1 h1
3
d1 6 f [ x0 , x1 , x2 ]
2
The system is
2 M0 + M 1 = 3
0.5 M0 + 2M1 +0.5 M2 = 1.5
M1 +2 M2 = -12
We have M0 =0.25 , M1 =2.5 M2 = -7.25
The cubic spline interpolating functions are
( x x0 )3 ( x x1 )3
S1 ( x) M 1 M0
6h0 6h0
y0 M 0 y1 M 1
( h0 )( x x1 ) ( h0 )( x x0 )
h0 6 h0 6
1 5 17 8
( x 4) ( x 2) ( x 4) ( x 2), x [2,4]
3 3
48 24 12 3
Similarly,
5 29 3 8 107
S2 ( x) ( x 6) ( x 4) ( x 6)
3
( x 4), x [4,6]
24 48 3 12
That is,
1 5 3 17 8
48 ( x 4) 24 ( x 2) 12 ( x 4) 3 ( x 2), x [2, 4]
3
S ( x)
5 ( x 6)3 29 ( x 4)3 8 ( x 6) 107 ( x 4), x [4,6]
24 48 3 12
Convergence
f ( m ) ( x) S ( m ) ( x) Cm h(4m ) f (4) ,
m 0,1, 2,3 ,
5 1 3 1 h
where C0 , C1 , C2 , C3 , h max hi , ,
384 24 8 2 i min hi
i
S1 ( x) x [ x0 , x1 ]
S ( x)
S2 ( x) x [ x1 , x2 ]
S1 ( x) x [ x0 , x1 ]
S ( x)
2
S ( x ) b1 ( x x1 ) 3
x [ x1 , x2 ]
0 x x1
(x x ) 3
1
( x x1 ) 3
x x1
Summary
Lagrange : y0 … yn are given, basis functions are li(x),
n
Ln ( x ) li ( x ) yi
i 0