Download Interpolation - KFUPM Faculty List

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
SE301: Numerical Methods
Topic 5:
Interpolation
Lectures 20-22:
KFUPM
Read Chapter 18, Sections 1-5
CISE301_Topic5
KFUPM
1
Lecture 20
Introduction to Interpolation
Introduction
Interpolation
Problem
Existence and Uniqueness
Linear and Quadratic Interpolation
Newton’s Divided Difference Method
Properties of Divided Differences
CISE301_Topic5
KFUPM
2
Introduction
Interpolation was used for
long time to provide an
estimate of a tabulated
function at values that are
not available in the table.
What is sin (0.15)?
x
sin(x)
0
0.0000
0.1
0.0998
0.2
0.1987
0.3
0.2955
0.4
0.3894
Using Linear Interpolation sin (0.15) ≈ 0.1493
True value (4 decimal digits) sin (0.15) = 0.1494
CISE301_Topic5
KFUPM
3
The Interpolation Problem
Given a set of n+1 points,
x0 , f ( x0 ), x1, f ( x1), ...., xn , f ( xn )
Find an nth order polynomial f n (x )
that passes through all points, such that:
f n ( xi )  f ( xi )
CISE301_Topic5
for i  0,1, 2,..., n
KFUPM
4
Example
An experiment is used to determine
the viscosity of water as a function
of temperature. The following table
is generated:
Problem: Estimate the viscosity
when the temperature is 8 degrees.
CISE301_Topic5
KFUPM
Temperature
(degree)
Viscosity
0
1.792
5
1.519
10
1.308
15
1.140
5
Interpolation Problem
Find a polynomial that fits the data
points exactly.
V : Viscosity
n
V(T)   ak T
k
T : Temperatur e
ak : Polynomial
k 0
Vi  V(Ti )
coefficien ts
Linear Interpolation: V(T)= 1.73 − 0.0422 T
V(8)= 1.3924
CISE301_Topic5
KFUPM
6
Existence and Uniqueness
Given a set of n+1 points:
x0 , f ( x0 ), x1, f ( x1), ...., xn , f ( xn )
Assumption:
x0 , x1 ,..., xn
are distinct
Theorem:
There is a unique polynomial fn(x) of order ≤ n
such that:
f n ( xi )  f ( xi )
CISE301_Topic5
for
KFUPM
i  0,1,...,n
7
Examples of Polynomial Interpolation
Linear Interpolation

Quadratic Interpolation
Given any two points,
there is one polynomial of
order ≤ 1 that passes
through the two points.
CISE301_Topic5
Given any three points there
is one polynomial of order ≤
2 that passes through the
three points.
KFUPM
8
Linear Interpolation
Given any two points, x0 , f ( x0 ) , x1, f ( x1 ) 
The line that interpolates the two points is:
f ( x1 )  f ( x0 )
x  x0 
f1 ( x)  f ( x0 ) 
x1  x0
Example :
Find a polynomial that interpolates (1,2) and (2,4).
f1 ( x)  2 
CISE301_Topic5
42
x  1  2 x
2 1
KFUPM
9
Quadratic Interpolation


Given any three points: x0 , f ( x0 ), x1 , f ( x1 ), and x2 , f ( x2 )
The polynomial that interpolates the three points is:
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
CISE301_Topic5
KFUPM
10
General nth Order Interpolation
Given any n+1 points: x0 , f ( x0 ), x1 , f ( x1 ), ..., xn , f ( xn )
The polynomial that interpolates all points is:
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 ]
CISE301_Topic5
KFUPM
11
Divided Differences
f [ xk ]  f ( xk )
Zeroth order DD
f [ x1 ]  f [ x0 ]
f [ x0 , x1 ] 
x1  x0
First order DD
f [ x0 , x1 , x2 ] 
f [ x1 , x2 ]  f [ x0 , x1 ]
x2  x0
Second order DD
............
f [ x1 , x2 ,..., xk ]  f [ x0 , x1 ,..., xk 1 ]
f [ x0 , x1 ,..., xk ] 
xk  x0
CISE301_Topic5
KFUPM
12
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]

f n ( x)    F [ x0 , x1 ,..., xi ]
i 0 
n
CISE301_Topic5
KFUPM

x  x j 

j 0

i 1
13
Divided Difference Table
x
F[ ]
F[ , ]
F[ , , ]
0
-5
2
-4
1
-3
6
-1
-15
Entries of the divided difference
table are obtained from the data
table using simple operations.
CISE301_Topic5
KFUPM
xi
f(xi)
0
-5
1
-3
-1
-15
14
Divided Difference Table
x
F[ ]
F[ , ]
F[ , , ]
0
-5
2
-4
1
-3
6
-1
-15
xi
f(xi)
0
1
-1
-5
-3
-15
The first two column of the
table are the data columns.
Third column: First order differences.
Fourth column: Second order differences.
CISE301_Topic5
KFUPM
15
Divided Difference Table
x
F[ ]
F[ , ]
F[ , , ]
0
-5
2
-4
1
-3
6
-1
-15
 3  (5)
2
1 0
xi
yi
0
-5
1
-3
-1
-15
f [ x1 ]  f [ x0 ]
f [ x0 , x1 ] 
x1  x0
CISE301_Topic5
KFUPM
16
Divided Difference Table
x
F[ ]
F[ , ]
F[ , , ]
xi
yi
0
-5
2
-4
1
-3
6
0
-5
-1
-15
1
-3
-1
-15
 15  ( 3)
6
11
f [ x2 ]  f [ x1 ]
f [ x1 , x2 ] 
x2  x1
CISE301_Topic5
KFUPM
17
Divided Difference Table
x
F[ ]
F[ , ]
F[ , , ]
xi
yi
0
-5
2
-4
1
-3
6
0
-5
-1
-15
1
-3
-1
-15
6  (2)
 4
 1  (0)
f [ x1 , x2 ]  f [ x0 , x1 ]
f [ x0 , x1 , x2 ] 
x2  x0
CISE301_Topic5
KFUPM
18
Divided Difference Table
x
F[ ]
F[ , ]
F[ , , ]
xi
yi
0
-5
2
-4
1
-3
6
0
-5
-1
-15
1
-3
-1
-15
f 2 ( x)  5  2( x  0)  4( x  0)( x 1)
f2(x)= F[x0]+F[x0,x1] (x-x0)+F[x0,x1,x2] (x-x0)(x-x1)
CISE301_Topic5
KFUPM
19
Two Examples
Obtain the interpolating polynomials for the two examples:
x
y
x
y
1
0
2
3
2
3
1
0
3
8
3
8
What do you observe?
CISE301_Topic5
KFUPM
20
Two Examples
x
Y
1
0
3
2
3
5
3
8
1
x
Y
2
3
3
1
0
4
3
8
1
P2 ( x)  3  3( x  2)  1( x  2)( x  1)
P2 ( x)  0  3( x  1)  1( x  1)( x  2)
 x2 1
 x 1
2
Ordering the points should not affect the interpolating polynomial.
CISE301_Topic5
KFUPM
21
Properties of Divided Difference
Ordering the points should not affect the divided difference:
f [ x0 , x1 , x2 ]  f [ x1 , x2 , x0 ]  f [ x2 , x1 , x0 ]
CISE301_Topic5
KFUPM
22
Example

Find a polynomial to
interpolate the data.
CISE301_Topic5
KFUPM
x
f(x)
2
3
4
5
5
1
6
6
7
9
23
Example
x
2
4
5
f(x) f[ , ]
3
1
5
-4
1
5
6
7
6
9
f[ , , ]
-1.6667
4.5
-1
f[ , , , ]
1.5417
-1.8333
f[ , , , , ]
-0.6750
3
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)
CISE301_Topic5
KFUPM
24
Example
x
f(x)

1.6
2
2
8
2.5
14
3.2
15
4
8
4.5
2
Calculate f (2.8) using Newton’s interpolating
polynomials of order 1 through 3. Choose the
sequence of the points for your estimates to
attain the best possible accuracy.
CISE301_Topic5
KFUPM
25
Example
x
f(x)
f[ , ]
f[ , , ]
f[ , , , ]
2.5
3.2
2
4
14
15
8
8
1.4286
5.8333
0
-8.8095
-7.2917
1.0120
The first through third-order interpolations can then be implemented as
f1 (2.8)  14  1.428571(2.8  2.5)  14.428571
f 2 (2.8)  14  1.428571(2.8  2.5)  8.809524 (2.8  2.5)(2.8  3.2)  15.485714
f 3 (2.8)  14  1.428571(2.8  2.5)  8.809524 (2.8  2.5)(2.8  3.2)
 1.011905 (2.8  2.5)(2.8  3.2)(2.8  2.)  15.388571
CISE301_Topic5
KFUPM
26
Summary
Interpolat ing Condition : f ( xi )  f n ( xi ) for i  0, 1, 2, ..., n
* The interpolat ing Polynomial is unique.
* Different methods can be used to obtain it
- Newton Divided Difference [Section 18.1 ]
- Lagrange Interpolat ion
[Section 18. 2]
- Other methods
Ordering the points should not affect the interpolat ing polynomial .
CISE301_Topic5
KFUPM
27
Lecture 21
Lagrange Interpolation
CISE301_Topic5
KFUPM
28
The Interpolation Problem
Given a set of n+1 points:
x0 , f ( x0 ), x1, f ( x1), ...., xn , f ( xn )
Find an nth order polynomial: f n (x )
that passes through all points, such that:
f n ( xi )  f ( xi )
CISE301_Topic5
for i  0,1, 2,..., n
KFUPM
29
Lagrange Interpolation
Problem:
Given
xi
x0
x1
….
xn
yi
y0
y1
….
yn
Find the polynomial of least order
f n ( xi )  f ( xi )
for
f n (x)
such that:
i  0,1,..., n
Lagrange Interpolation Formula:
n
f n ( x)   f  xi   i ( x)
i 0
 i ( x) 
x  x 
 x  x 
n
j
j 0, j i
CISE301_Topic5
KFUPM
i
j
30
Lagrange Interpolation
 i ( x) are called the cardinals.
The cardinals are n th order polynomial s :
0 i  j
i (x j )  
1 i  j
CISE301_Topic5
KFUPM
31
Lagrange Interpolation Example
P2 ( x)  f ( x0 ) 0 ( x)  f ( x1 ) 1 ( x)  f ( x2 ) 2 ( x)
x
y


x  x1  x  x2 
x  1 / 4   x  1
 0 ( x) 

x0  x1  x0  x2  1 / 3  1 / 4 1 / 3  1
x  x0  x  x2   x  1 / 3 x  1
 1 ( x) 
x1  x0  x1  x2  1 / 4  1 / 3 1 / 4  1
x  x0  x  x1   x  1 / 3 x  1 / 4
 2 ( x) 
x2  x0  x2  x1  1  1 / 3 1  1 / 4
P2 ( x)  2 18( x  1 / 4)( x  1) 116( x  1 / 3)( x  1)
 72( x  1 / 3)( x  1 / 4)
CISE301_Topic5
KFUPM
1/3 1/4 1
2
-1 7
32
Example
Find a polynomial to interpolate:
Both Newton’s interpolation
method and Lagrange
interpolation method must
give the same answer.
CISE301_Topic5
KFUPM
x
y
0
1
1
3
2
2
3
5
4
4
33
Newton’s Interpolation Method
0
1
2
-3/2
1
3
-1
2
2
2
3
-2
3
5
-1
4
4
CISE301_Topic5
7/6
-5/8
-4/3
KFUPM
34
Interpolating Polynomial
3
7
f 4 ( x)  1  2( x)  x( x  1)  x( x  1)( x  2)
2
6
5
 x( x  1)( x  2)( x  3)
8
CISE301_Topic5
KFUPM
35
Interpolating Polynomial Using
Lagrange Interpolation Method
4
f 4 ( x)   f ( xi )  i   0  3 1  2 2  5 3  4 4
i 0
x 1 x  2
0 
0 1 0  2
x0 x2
1 
1 0 1 2
x  0 x 1
2 
2  0 2 1
x  0 x 1
3 
3  0 3 1
x  0 x 1
4 
4  0 4 1
CISE301_Topic5
x 3
03
x3
1 3
x 3
23
x2
3 2
x2
42
x4
04
x4
1 4
x4
24
x4
3 4
x 3
43
KFUPM
36
Lecture 22
Inverse Interpolation
Error in Polynomial Interpolation
CISE301_Topic5
KFUPM
37
Inverse Interpolation
Problem :
xi
x0
x1
….
xn
Given the table and y g .
yi
y0
y1
….
yn
Find xg such that : f ( xg )  y g .
One approach:
Use polynomial interpolation to obtain fn(x) to interpolate the
data then use Newton’s method to find a solution to:
f n ( xg )  y g
CISE301_Topic5
KFUPM
38
Inverse Interpolation
Alternative Approach
Inverse interpolation:
1. Exchange the roles
of x and y.
xi
yi
x0
y0
x1
….
xn
y1
….
yn
yi
y0
y1
….
yn
xi
x0
x1
….
xn
2. Perform polynomial
Interpolation on the
new table.
3. Evaluate
fn ( yg )
CISE301_Topic5
KFUPM
39
Inverse Interpolation
x
y
x
CISE301_Topic5
y
KFUPM
40
Inverse Interpolation
Question:
What is the limitation of inverse interpolation?
• The original function has an inverse.
• y1, y2, …, yn must be distinct.
CISE301_Topic5
KFUPM
41
Inverse Interpolation
Example
x
y
Problem :
1
2
3
3.2 2.0 1.6
Given the table. Find xg such that f ( xg )  2.5
3.2
1
-.8333
2.0
2
-2.5
1.6
3
1.0416
f 2 ( y )  1  0.8333( y  3.2)  1.0416( y  3.2)( y  2)
f 2 (2.5)  1  0.8333(0.7)  1.0416(0.7)(0.5)  1.2187
CISE301_Topic5
KFUPM
42
10th Order Polynomial Interpolation
2
1.5
10 th order interpolating polynomial
1
0.5
0
true function
-0.5
-5
CISE301_Topic5
-4
-3
-2
-1
0
KFUPM
1
2
3
4
5
43
Errors in polynomial Interpolation

Polynomial interpolation may lead to large
errors (especially for high order polynomials).
BE CAREFUL

When an nth order interpolating polynomial is
used, the error is related to the (n+1)th order
derivative.
CISE301_Topic5
KFUPM
44
Errors in polynomial Interpolation
Theorem
Let f(x) be a function such that :
f
(n1 )
(x) is continuous on [a, b], and f
( n 1)
 M.
Let P(x) be any polynomial of degree  n
that interpolat es f at n  1 equally spaced points
in [a, b] (including the end points). Then :
M ba
f(x)-P(x) 


4(n  1)  n 
CISE301_Topic5
KFUPM
n 1
45
Example 1
f(x)  sin (x)
We want to use 9 th order polynomial to interpolat e f(x)
(using 10 equally spaced points) in the interval [0,1.6875].
f ( n 1)  1
for n  0
M  1, n  9
f(x)-P(x) 
M ba


4(n  1)  n 
n 1
10
1  1.6875 
9
f(x)-P(x) 

  1.34  10
4(10)  9 
CISE301_Topic5
KFUPM
46
Interpolation Error
If f n (x) is the polynomial of degree n that interpolat es
the function f(x) at the nodes x0 , x1 ,..., xn , then for any x
not a node :
n
f(x)  f n ( x)  f [ x0 , x1 ,..., xn , x]  x  xi 
i 0
Not useful. Why?
CISE301_Topic5
KFUPM
47
Approximation of the Interpolation Error
If f n (x) is the polynomial of degree n that interpolat es
the function f(x) at the nodes x0 , x1 ,..., xn .
Let ( xn 1 , f ( xn 1 )) be an additional point.
The interpolat ion error is approximat ed by :
n
f(x)  f n ( x)  f [ x0 , x1 ,..., xn , xn 1 ]   x  xi 
i 0
CISE301_Topic5
KFUPM
48
Divided Difference Theorem
If f ( n ) is continuous on [a, b], and if x0 , x1 ,..., xn
are any n  1 distinct points in [a, b], then for some   [a, b] :
1 (n)
f [ x0 , x1 ,..., xn ]  f  
n!
If f ( x) is a polynomial of order n,
then :
f [ x0 , x1 ,..., xi ]  0 i  n  1
1
2
3
4
5
6
4
7
1
1
1
0
0
0
f ( x)  3  x
CISE301_Topic5
KFUPM
49
Summary
The interpolating polynomial is unique.
 Different methods can be used to obtain it.




Newton’s divided difference
Lagrange interpolation
Others
Polynomial interpolation can be sensitive to
data.
 BE CAREFUL when high order polynomials
are used.

CISE301_Topic5
KFUPM
50
Related documents