Professional Documents
Culture Documents
Week10 Interpolation
Week10 Interpolation
Interpolation
1
Introduction
Estimation of intermediate values between
precise data points. The most common method is
polynomial interpolation:
f ( x) = a0 + a1 x + a2 x 2 + + an x n
n=3 n=4
n=2
n = number of data
3
Introduction
4
Newton’s Divided-Difference
Interpolating Polynomials
Linear Interpolation
• Is the simplest form of interpolation, connecting two
data points with a straight line.
Slope and a
finite divided
f1 ( x) − f ( x0 ) f ( x1 ) − f ( x0 )
= difference
x − x0 x − x0 approximation to
1st derivative
f ( x1 ) − f ( x0 )
f1 ( x) = f ( x0 ) + ( x − x0 ) Linear-interpolation
x − x0 formula
5
Linear Interpolation
6
Quadratic Interpolation
• If three data points are available, the estimate is
improved by introducing some curvature into the
line connecting the points.
f 2 ( x) = b0 + b1 ( x − x0 ) + b2 ( x − x0 )( x − x1 )
• A simple procedure can be used to determine
the values of the coefficients.
x = x0 b0 = f ( x0 )
f ( x1 ) − f ( x0 )
x = x1 b1 =
x1 − x0
f ( x2 ) − f ( x1 ) f ( x1 ) − f ( x0 )
−
x2 − x1 x1 − x0
x = x2 b2 =
x2 − x0
7
Linear vs Quadratic Interpolation
8
Quadratic Interpolation
f 2 ( x) = b0 + b1 ( x − x0 ) + b2 ( x − x0 )( x − x1 )
where :
b0 = f ( x0 )
f ( x1 ) − f ( x0 )
b1 = f [ x0 , x1 ] =
x1 − x0
f ( x2 ) − f ( x1 ) f ( x1 ) − f ( x0 )
−
x2 − x1 x1 − x0
b2 = f [ x0 , x1 , x2 ] =
x2 − x0
9
General nth Order Interpolation
f n ( x) = b0 + b1 ( x − x0 ) + b2 ( x − x0 )( x − x1 ) + ... + bn ( x − x0 )...( x − xn −1 )
b0 = f ( x0 )
b1 = f [ x0 , x1 ]
....
bn = f [ x0 , x1 , ... , xn ]
10
Divided Differences
f [ xk ] = f ( xk ) Zeroth order DD
f [ x1 ] − f [ x0 ]
f [ x0 , x1 ] = First order DD
x1 − x0
f [ x1 , x2 ] − f [ x0 , x1 ]
f [ x0 , x1 , x2 ] = Second order DD
x2 − x0
............
f [ x1 , x2 ,..., xk ] − f [ x0 , x1 ,..., xk −1 ]
f [ x0 , x1 ,..., xk ] =
xk − x0
11
Divided Difference Table
x F[ ] F[ , ] F[ , , ] F[ , , ,]
x0 F[x0] F[x0,x1] F[x0,x1,x2] F[x0,x1,x2,x3]
x1 F[x1] F[x1,x2] F[x1,x2,x3]
x2 F[x2] F[x2,x3]
x3 F[x3]
12
Divided Difference Table
x F[ ] F[ , ] F[ , , ]
xi f(xi)
0 -5 2 -4
1 -3 6
0 -5
-1 -15 1 -3
-1 -15
Entries of the divided difference table
are obtained from the data table using
simple operations.
13
Divided Difference Table
x F[ ] F[ , ] F[ , , ] xi f(xi)
0 -5 2 -4 0 -5
1 -3 6 1 -3
-1 -15 -1 -15
x F[ ] F[ , ] F[ , , ] xi yi
0 -5 2 -4 0 -5
1 -3 6
-1 -15 1 -3
-1 -15
− 3 − (−5)
=2
1− 0
f [ x1 ] − f [ x0 ]
f [ x0 , x1 ] =
x1 − x0
15
Divided Difference Table
x F[ ] F[ , ] F[ , , ] xi yi
0 -5 2 -4 0 -5
1 -3 6
-1 -15 1 -3
-1 -15
− 15 − (−3)
=6
−1 −1
f [ x2 ] − f [ x1 ]
f [ x1 , x2 ] =
x2 − x1
16
Divided Difference Table
x F[ ] F[ , ] F[ , , ] xi yi
0 -5 2 -4 0 -5
1 -3 6
-1 -15 1 -3
-1 -15
6 − ( 2)
= −4
− 1 − ( 0)
f [ x1 , x2 ] − f [ x0 , x1 ]
f [ x0 , x1 , x2 ] =
x2 − x0
17
Divided Difference Table
x F[ ] F[ , ] F[ , , ] xi yi
0 -5 2 -4 0 -5
1 -3 6
-1 -15 1 -3
-1 -15
f 2 ( x) = −5 + 2( x − 0) − 4( x − 0)( x − 1)
x y x y
1 0 2 3
2 3 1 0
3 8 3 8
19
Two Examples
x Y
x Y
1 0 3 1 2 3 3 1
2 3 5 1 0 4
3 8 3 8
P2 ( x) = 0 + 3( x − 1) + 1( x − 1)( x − 2) P2 ( x) = 3 + 3( x − 2) + 1( x − 2)( x − 1)
= x −1
2 = x2 −1
20
Properties of Divided Difference
f [ x0 , x1 , x2 ] = f [ x1 , x2 , x0 ] = f [ x2 , x1 , x0 ]
21
Example
x f(x)
• Find a polynomial to
interpolate the data.
2 3
4 5
5 1
6 6
7 9
22
Example
x f(x) f[ , ] f[ , , ] f[ , , , ] f[ , , , , ]
2 3 1 -1.6667 1.5417 -0.6750
4 5 -4 4.5 -1.8333
5 1 5 -1
6 6 3
7 9
f 4 = 3 + 1( x − 2) − 1.6667( x − 2)( x − 4) + 1.5417( x − 2)( x − 4)( x − 5)
− 0.6750( x − 2)( x − 4)( x − 5)( x − 6)
23
Errors of Newton’s Interpolating Polynomials
• Structure of interpolating polynomials is similar to the
Taylor series expansion in the sense that finite divided
differences are added sequentially to capture the higher
order derivatives.
• For an nth-order interpolating polynomial, an analogous
relationship for the error is:
is somewhere
f ( n+1) ( )
Rn = ( x − x0 )( x − x1 ) ( x − xn ) containing the
(n + 1)! unknown and the data
24
Problem 18.6
25
Lagrange Interpolating Polynomials
26
Lagrange Interpolating Polynomials
x − x1 x − x0
f1 ( x ) = f ( x0 ) + f ( x1 )
x0 − x1 x1 − x0
Lo (x ) L1 ( x )
27
Lagrange Interpolating Polynomials
f 2 ( x) =
( x − x1 )( x − x2 )
f ( x0 ) Lo ( x) , j 0
(x0 − x1 )(x0 − x 2 )
+
( x − x0 )( x − x2 )
f ( x1 ) L1 ( x) , j 1
(x1 − x0 )(x1 − x 2 )
+
( x − x0 )(x − x1 )
f ( x2 ) L2 ( x) , j 2
(x2 − x0 )(x2 − x1 )
28
Lagrange Interpolating Polynomials -
Example
x0 = 1 f ( x0) = ln(1) = 0
x1 = 4 f ( x1) = ln( 4) = 1.386294
x2 = 6 f ( x 2) = ln( 6) = 1.791760
29
Lagrange Interpolating Polynomials –
Example (cont’d)
x − x1 x − x0
f 1( x) = f ( x 0) + f ( x1)
x 0 − x1 x1 − x 0
2−4 2 −1
f 1(2) = 0 + 1.386294 = 0.4620981
1− 4 4 −1
30
Lagrange Interpolating Polynomials –
Example (cont’d)
x − x1 x − x2 x−4 x−6
Lo ( x ) = =
xo − x1 xo − x2 0 − 4 0 − 6
x − xo x − x 2 x − 0 x − 6
L1 ( x ) = =
x1 − xo x1 − x2 4 − 0 4 − 6
x − xo x − x1 x − 0 x − 4
L2 ( x ) = =
x2 − xo x2 − x1 6 − 0 6 − 4
31
Lagrange Interpolating Polynomials –
Example (cont’d)
n n
x − xj
f n ( x ) = Li ( x ) f ( xi ) Li ( x ) = ( j i)
i =0 j =0 xi − x j
(2 − 4)(2 − 6)
f 2 ( 2) = 0
(1 − 4)(1 − 6)
(2 − 1)(2 − 6)
+ 1.386294
(4 − 1)(4 − 6)
(2 − 1)(2 − 4)
+ 1.791760 = 0.5658444
(6 − 1)(6 − 4)
32
Lagrange Interpolating Polynomials –
Example (cont’d)
33
Pseudocode – Lagrange interpolation
34
Summary
Ordering the points should not affect the interpolat ing polynomial .
35
Spline Interpolation
40
Spline Interpolation
The concept of spline is using a thin, flexible strip
(called a spline) to draw smooth curves through a
set of points….natural spline (cubic)
41
42
Why Spline Interpolation?
43
Why Splines ?
1
f ( x) =
1 + 25 x 2
Table : Six equidistantly spaced points in [-1, 1]
1
x y=
1 + 25 x 2
-1.0 0.038461
-0.6 0.1
-0.2 0.5
0.2 0.5
0.6 0.1
44
Why Splines ?
17th Order
Polynomial
Original
Function
5th Order
Polynomial
9th Order
Polynomial
45
Linear Spline
The first order splines for a group of ordered data
points can be defined as a set of linear functions:
f ( x) = f ( x0 ) + m0 ( x − x0 ) x0 x x1
f ( x) = f ( x1 ) + m1 ( x − x1 ) x1 x x2
f ( x) = f ( xn −1 ) + mn −1 ( x − xn −1 ) xn −1 x xn
f ( xi +1 ) − f ( xi )
mi =
xi +1 − xi
46
Linear spline - Example
Fit the following data with first order splines. Evaluate
the function at x = 5.
2.5 − 1
x f(x) m= = 0.6
7 − 4.5
3.0 2.5 f (5) = f (4.5) + m(5 − 4.5)
4.5 1.0 = 1.0 + 0.6 0.5
7.0 2.5
9.0 0.5 = 1.3
47
Linear Spline
f i ( x) = ai x 2 + bi x + ci
49
Software: MATLAB / Octave (GNU)
70