You are on page 1of 49

SE301:Numerical Methods

Topic 5
Interpolation
Dr. Samir Al-Amer
(Term 063)

Read Chapter 18, Sections 1-5

SE301_Topic5 (c)AL-AMER2006 ١
SE301:Numerical Methods
Lecture 14:
Introduction to Interpolation
Introduction
Interpolation problem
Existence and uniqueness
Linear and Quadratic interpolation
Newton’s Divided Difference method
Properties of Divided Differences
SE301_Topic5 (c)AL-AMER2006 ٢
Introduction
Interpolation was used for x sin(x)
long time to provide an
0 0.0000
estimate of a tabulated
function at values that are 0.1 0.0998
not available in the table.
0.2 0.1987

What is sin (0.15)? 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
SE301_Topic5 (c)AL-AMER2006 ٣
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

f n ( xi ) = f ( xi ) for i = 0,1, 2,..., n

SE301_Topic5 (c)AL-AMER2006 ٤
Example
Temperature Viscosity
An experiment is used to determine (degree)
the viscosity of water as a
function of temperature. The
0 1.792
following table is generated
5 1.519

10 1.308
Problem: Estimate the viscosity
when the temperature is 8 degrees.
15 1.140

SE301_Topic5 (c)AL-AMER2006 ٥
Interpolation Problem
Find a polynomial that fit the data points
exactly.
V : viscosity
n
V(T) = ∑ ak T k T : Temperature
k =0 ak : polynomial
Vi = V(Ti ) coefficients
Linear Interpolation V(T)= 1.73 − 0.0422 T
V(8)= 1.3924
SE301_Topic5 (c)AL-AMER2006 ٦
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 ) for i = 0,1,..., n
SE301_Topic5 (c)AL-AMER2006 ٧
Examples of Polynomial Interpolation
Linear Interpolation Quadratic Interpolation

S Given any two points, Given any three points there


there is one polynomial of is one polynomial of order ≤ 2
order ≤ 1 that passes that passes through the three
through the two points. points.

SE301_Topic5 (c)AL-AMER2006 ٨
475

Linear Interpolation
Given any two points, ( x0 , f ( x0 ) ), ( x1 , f ( x1 ) )

The line that interpolates the two points is


f ( x1 ) − f ( x0 )
f1 ( x) = f ( x0 ) + (x − x0 )
x1 − x0
Example :
find a polynomial that interpolates (1,2) and (2,4)

4−2
f1 ( x) = 2 + (x − 1) = 2 x
2 −1

SE301_Topic5 (c)AL-AMER2006 ٩
477

Quadratic Interpolation
S Given any three points, (x0 , f ( x0 ) ), ( x1, f ( x1 ) )and (x2 , f ( x2 ) )
S 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
SE301_Topic5 (c)AL-AMER2006 ١٠
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 ]

SE301_Topic5 (c)AL-AMER2006 ١١
Divided Differences
f [ x k ] = 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

SE301_Topic5 (c)AL-AMER2006 ١٢
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]

⎧ i −1 ⎫
(x − x j )⎬
n
f n ( x) = ∑ ⎨ F [ x0 , x1 ,..., xi ] ∏
i =0 ⎩ j =0 ⎭

SE301_Topic5 (c)AL-AMER2006 ١٣
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

SE301_Topic5 (c)AL-AMER2006 ١٤
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

The first two column of the


table are the data columns
Third column : first order differences
Fourth column: Second order differences
SE301_Topic5 (c)AL-AMER2006 ١٥
Divided Difference Table
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

SE301_Topic5 (c)AL-AMER2006 ١٦
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

SE301_Topic5 (c)AL-AMER2006 ١٧
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
SE301_Topic5 (c)AL-AMER2006 ١٨
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)

f2(x)= F[x0]+F[x0,x1] (x-x0)+F[x0,x1,x2] (x-x0)(x-x1)


SE301_Topic5 (c)AL-AMER2006 ١٩
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?

SE301_Topic5 (c)AL-AMER2006 ٢٠
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 −12 = x2 −1

Ordering the points should not affect the interpolating polynomial

SE301_Topic5 (c)AL-AMER2006 ٢١
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 ]

SE301_Topic5 (c)AL-AMER2006 ٢٢
Example
S Find a polynomial to x f(x)
interpolate the data.
2 3

4 5

5 1

6 6

7 9

SE301_Topic5 (c)AL-AMER2006 ٢٣
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)

SE301_Topic5 (c)AL-AMER2006 ٢٤
Summary
Interpolating Condition : f ( xi ) = f n ( xi ) for i = 0,1,2,..., n
* The interpolating Polynomial is unique.
* Different methods can be used to obtain it
- Newton Divided Difference [Section 18.1 ]
- Lagrange Interpolation [Section 18. 2]
- Other methods

Ordering the points should not affect the interpolating polynomial

SE301_Topic5 (c)AL-AMER2006 ٢٥
SE301: Numerical Methods

Lecture 15
Lagrange Interpolation

Dr. Samir Al-Amer


(Term 051)

SE301_Topic5 (c)AL-AMER2006 ٢٦
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

f n ( xi ) = f ( xi ) for i = 0,1, 2,..., n

SE301_Topic5 (c)AL-AMER2006 ٢٧
486

Lagrange Interpolation
Problem: xi x0
x1 …. xn
Given
yi y0 y1 …. yn

Find the polynomial of least order f n (x) such that

f n ( xi ) = f ( xi ) for i = 0,1,..., n
n
Lagrange Interpolation Formula f n ( x) = ∑ f ( xi ) l i ( x)
i =0

(x − x )
n
l i ( x) = ∏ (x − x )
j =0, j ≠i
j

i j
SE301_Topic5 (c)AL-AMER2006 ٢٨
Lagrange Interpolation

l i ( x) are called the cardinals


The cardinals are n th order polynomials
⎧0 i ≠ j
l i (x j ) = ⎨
⎩1 i = j

SE301_Topic5 (c)AL-AMER2006 ٢٩
Lagrange Interpolation Example
P2 ( x) = f ( x0 )l 0 ( x) + f ( x1 )l 1 ( x) + f ( x2 )l 2 ( x) x 1/3 1/4 1

l 0 ( x) =
(x − x1 ) (x − x2 ) = (x − 1 / 4) (x − 1) y 2 -1 7
(x0 − x1 ) (x0 − x2 ) (1 / 3 − 1 / 4) (1 / 3 − 1)
l 1 ( x) =
(x − x0 ) (x − x2 ) = (x − 1 / 3) (x − 1)
(x1 − x0 ) (x1 − x2 ) (1 / 4 − 1 / 3) (1 / 4 − 1)
l 2 ( x) =
(x − x0 ) (x − x1 ) = (x − 1 / 3) (x − 1 / 4)
(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)}

SE301_Topic5 (c)AL-AMER2006 ٣٠
Example
find a polynomial to interpolate x y

0 1
both Newton’s
interpolation method 1 3
and Lagrange
2 2
interpolation method
must give the same 3 5
answer
4 4

SE301_Topic5 (c)AL-AMER2006 ٣١
0 1 2 -3/2 7/6 -5/8

1 3 -1 2 -4/3

2 2 3 -2

3 5 -1

4 4

SE301_Topic5 (c)AL-AMER2006 ٣٢
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

SE301_Topic5 (c)AL-AMER2006 ٣٣
Interpolating Polynomial Using
Lagrange Interpolation method
4
f 4 ( x) = ∑ f ( xi ) l i = l 0 + 3l 1 + 2l 2 + 5l 3 + 4l 4
i =0

x −1 x − 2 x−3 x−4
l0 =
0 −1 0 − 2 0−3 0−4
x−0 x−2 x−3 x−4
l1 =
1− 0 1− 2 1− 3 1− 4
x − 0 x −1 x −3 x−4
l2 =
2 − 0 2 −1 2−3 2−4
x − 0 x −1 x−2 x−4
l3 =
3 − 0 3 −1 3− 2 3− 4
x − 0 x −1 x−2 x −3
l4 =
4 − 0 4 −1 4−2 4−3
SE301_Topic5 (c)AL-AMER2006 ٣٤
SE301Numerical Methods
Lecture 16
Inverse interpolation
Error in polynomial interpolation

Dr. Samir Al-Amer


(Term 042)

SE301_Topic5 (c)AL-AMER2006 ٣٥
491

Inverse Interpolation
xi x0 x1 …. xn
Problem :
Given the table and y g yi y0 y1 …. yn
Find x g such that f ( x g ) = 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
fn (x g ) = y g
SE301_Topic5 (c)AL-AMER2006 ٣٦
Inverse Interpolation
Alternative Approach

Inverse interpolation: xi x0 x1 …. xn
1. Exchange the roles
yi y0 y1 …. yn
of x and y

2. Perform polynomial
Interpolation on the yi y0 y1 …. yn
new table.
xi x0 x1 …. xn
3. Evaluate

fn ( y g )

SE301_Topic5 (c)AL-AMER2006 ٣٧
Inverse Interpolation

x
y

x y

SE301_Topic5 (c)AL-AMER2006 ٣٨
Inverse Interpolation
Question:

What is the limitation of inverse interpolation

• The original function has an inverse


• y1,y2,…,yn must be distinct.

SE301_Topic5 (c)AL-AMER2006 ٣٩
Inverse Interpolation
Example

x 1 2 3
Problem : y 3.2 2.0 1.6
Given the table. Find x g such that f ( x g ) = 2.5

3.2 1 -.8333 1.0416


2.0 2 -2.5
1.6 3

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
SE301_Topic5 (c)AL-AMER2006 ٤٠
10 th order Polynomial Interpolation
2

1.5 10 th order interpolating polynomial

0.5

true function

-0.5
-5 -4 -3 -2 -1 0 1 2 3 4 5

SE301_Topic5 (c)AL-AMER2006 ٤١
Errors in polynomial Interpolation
S Polynomial interpolation may lead to large error
(especially for high order polynomials)
BE CAREFUL

S When an nth order interpolating polynomial is


used, the error is related to the (n+1) th order
derivative

SE301_Topic5 (c)AL-AMER2006 ٤٢
Errors in polynomial Interpolation
Theorem
Let f(x) be a function such that
(n +1) ( n +1)
f (x) is continuous on [a, b], f ≤M
Let P(x) be any polynomial of degree ≤ n
that interpolates f at n + 1 equally spaced points
in [a, b] (including the end points). Then
n +1
M ⎛b−a⎞
f(x) - P(x) ≤ ⎜ ⎟
4(n + 1) ⎝ n ⎠
SE301_Topic5 (c)AL-AMER2006 ٤٣
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
n +1
M ⎛b−a⎞
f(x) - P(x) ≤ ⎜ ⎟
4( n + 1) ⎝ n ⎠
10
1 ⎛ 1.6875 ⎞ −9
f(x) - P(x) ≤ ⎜ ⎟ = 1.34 × 10
4(10) ⎝ 9 ⎠
SE301_Topic5 (c)AL-AMER2006 ٤٤
Interpolation Error
If f n (x) is the polynomial of degree n that interpolates
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?


SE301_Topic5 (c)AL-AMER2006 ٤٥
Approximation of the Interpolation Error
If f n (x) is the polynomial of degree n that interpolates
the function f(x) at the nodes x0 , x1 ,..., xn
Let( xn +1 , f ( xn +1 )) be an additional point

The interpolation error is approximated by

n
f(x) − f n ( x) ≈ f [ x0 , x1 ,..., xn , xn +1 ] ∏ (x − xi )
i =0

SE301_Topic5 (c)AL-AMER2006 ٤٦
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]

f [ x0 , x1 ,..., xn ] = f (ξ )
1 (n)
n!

If f ( x) is a polynomial of order n 1 4 1 0 0
then 2 5 1 0
3 6 1
f [ x0 , x1 ,..., xi ] = 0 ∀i ≥ n + 1
4 7
f ( x) = 3 + x
SE301_Topic5 (c)AL-AMER2006 ٤٧
Summary
S The interpolating polynomial is unique
S Different methods can be used to obtain it
Q Newton’s Divided difference
Q Lagrange interpolation
Q others

S Polynomial interpolation can be sensitive


to data.
S BE CAREFUL when high order
polynomials are used

SE301_Topic5 (c)AL-AMER2006 ٤٨
HW
S Chick WebCT for HW problems and due
dates

SE301_Topic5 (c)AL-AMER2006 ٤٩

You might also like