You are on page 1of 50

CISE301_Topic5 KFUPM - T212 - Section 01 1

SE301: Numerical Methods


Topic 5:
Interpolation
Lectures 20-22:
KFUPM
(Term 212)
Section 01


Read Chapter 18, Sections 1-5
CISE301_Topic5 KFUPM - T212 - Section 01 2

Lecture 20
Introduction to Interpolation
Introduction
Interpolation Problem
Existence and Uniqueness
Linear and Quadratic Interpolation
Newtons Divided Difference Method
Properties of Divided Differences
CISE301_Topic5 KFUPM - T212 - Section 01 3
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 - T212 - Section 01 4
The Interpolation Problem
Given a set of n+1 points,



Find an n
th
order polynomial
that passes through all points, such that:


( ) ( ) ( ) ) ( , ...., , ) ( , , ) ( ,
1 1 0 0 n n
x f x x f x x f x
) (x f
n
n i for x f x f
i i n
,..., 2 , 1 , 0 ) ( ) ( = =
CISE301_Topic5 KFUPM - T212 - Section 01 5
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.

Temperature
(degree)
Viscosity
0 1.792
5 1.519
10 1.308
15 1.140
CISE301_Topic5 KFUPM - T212 - Section 01 6
Interpolation Problem
Find a polynomial that fits the data
points exactly.


) V(T V
T a V(T)
i i
n
k
k
k
=
=

=0
ts coefficien
Polynomial :
e Temperatur :
Viscosity :
k
a
T
V
Linear Interpolation: V(T)= 1.73 0.0422 T
V(8)= 1.3924
CISE301_Topic5 KFUPM - T212 - Section 01 7
Existence and Uniqueness
Given a set of n+1 points:


Assumption: are distinct

Theorem:
There is a unique polynomial f
n
(x) of order n
such that:

,...,n , i for x f x f
i i n
1 0 ) ( ) ( = =
n
x x x ,..., ,
1 0
( ) ( ) ( ) ) ( , ...., , ) ( , , ) ( ,
1 1 0 0 n n
x f x x f x x f x
CISE301_Topic5 KFUPM - T212 - Section 01 8
Examples of Polynomial Interpolation
Linear Interpolation







Given any two points,
there is one polynomial of
order 1 that passes
through the two points.
Quadratic Interpolation






Given any three points there
is one polynomial of order
2 that passes through the
three points.

CISE301_Topic5 KFUPM - T212 - Section 01 9
Linear Interpolation
Given any two points,

The line that interpolates the two points is:


Example :
Find a polynomial that interpolates (1,2) and (2,4).

( ) ( ) ) ( , , ) ( ,
1 1 0 0
x f x x f x
( )
0
0 1
0 1
0 1
) ( ) (
) ( ) ( x x
x x
x f x f
x f x f

+ =
( ) x x x f 2 1
1 2
2 4
2 ) (
1
=

+ =
CISE301_Topic5 KFUPM - T212 - Section 01 10
Quadratic Interpolation
Given any three points:
The polynomial that interpolates the three points is:
( ) ( ) ( ) ) ( , , ) ( , , ) ( ,
2 2 1 1 0 0
x f x and x f x x f x
( ) ( )( )
0 2
0 1
0 1
1 2
1 2
2 1 0 2
0 1
0 1
1 0 1
0 0
1 0 2 0 1 0 2
) ( ) ( ) ( ) (
] , , [
) ( ) (
] , [
) (
:
) (
x x
x x
x f x f
x x
x f x f
x x x f b
x x
x f x f
x x f b
x f b
where
x x x x b x x b b x f

= =

= =
=
+ + =
CISE301_Topic5 KFUPM - T212 - Section 01 11
General n
th
Order Interpolation
Given any n+1 points:
The polynomial that interpolates all points is:
( ) ( ) ( ) ) ( , ..., , ) ( , , ) ( ,
1 1 0 0 n n
x f x x f x x f x
( ) ( )( ) ( ) ( )
] , ... , , [
....
] , [
) (
... ... ) (
1 0
1 0 1
0 0
1 0 1 0 2 0 1 0
n n
n n n
x x x f b
x x f b
x f b
x x x x b x x x x b x x b b x f
=
=
=
+ + + + =

CISE301_Topic5 KFUPM - T212 - Section 01 12
Divided Differences


0
1 1 0 2 1
1 0
0 2
1 0 2 1
2 1 0
0 1
0 1
1 0
] ,..., , [ ] ,..., , [
] ,..., , [
...... .. . . . .
DD order Second
] , [ ] , [
] , , [
DD order First
] [ ] [
] , [
DD order Zeroth ) ( ] [
x x
x x x f x x x f
x x x f
x x
x x f x x f
x x x f
x x
x f x f
x x f
x f x f
k
k k
k
k k

=
=

CISE301_Topic5 KFUPM - T212 - Section 01 13


Divided Difference Table


x F[ ] F[ , ] F[ , , ] F[ , , ,]
x
0
F[x0] F[x
0
,x
1
] F[x
0
,x
1,
x
2
] F[x
0
,x
1
,x
2
,x
3
]
x
1
F[x
1
] F[x
1
,x
2
] F[x
1
,x
2
,x
3
]
x
2
F[x
2
] F[x
2
,x
3
]
x
3
F[x
3
]
( )
[
=

=
)
`

=
n
i
i
j
j i n
x x x x x F x f
0
1
0
1 0
] ,..., , [ ) (
CISE301_Topic5 KFUPM - T212 - Section 01 14
Divided Difference Table


f(x
i
)
0 -5
1 -3
-1 -15
i
x
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 - T212 - Section 01 15
Divided Difference Table


f(x
i
)
0 -5
1 -3
-1 -15
i
x
x F[ ] F[ , ] F[ , , ]
0 -5 2 -4
1 -3 6
-1 -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 - T212 - Section 01 16
Divided Difference Table


0 -5
1 -3
-1 -15
i
y
i
x
x F[ ] F[ , ] F[ , , ]
0 -5 2 -4
1 -3 6
-1 -15
2
0 1
) 5 ( 3
=


0 1
0 1
1 0
] [ ] [
] , [
x x
x f x f
x x f

=
CISE301_Topic5 KFUPM - T212 - Section 01 17
Divided Difference Table


0 -5
1 -3
-1 -15
i
y
i
x
x F[ ] F[ , ] F[ , , ]
0 -5 2 -4
1 -3 6
-1 -15
6
1 1
) 3 ( 15
=


1 2
1 2
2 1
] [ ] [
] , [
x x
x f x f
x x f

=
CISE301_Topic5 KFUPM - T212 - Section 01 18
Divided Difference Table


0 -5
1 -3
-1 -15
i
y
i
x
x F[ ] F[ , ] F[ , , ]
0 -5 2 -4
1 -3 6
-1 -15
4
) 0 ( 1
) 2 ( 6
=


0 2
1 0 2 1
2 1 0
] , [ ] , [
] , , [
x x
x x f x x f
x x x f

=
CISE301_Topic5 KFUPM - T212 - Section 01 19
Divided Difference Table


0 -5
1 -3
-1 -15
i
y
i
x
x F[ ] F[ , ] F[ , , ]
0 -5 2 -4
1 -3 6
-1 -15
) 1 )( 0 ( 4 ) 0 ( 2 5 ) (
2
+ = x x x x f
f
2
(x)= F[x
0
]+F[x
0
,x
1
] (x-x
0
)+F[x
0
,x
1
,x
2
] (x-x
0
)(x-x
1
)
CISE301_Topic5 KFUPM - T212 - Section 01 20
Two Examples


x y
1 0
2 3
3 8
Obtain the interpolating polynomials for the two examples:
x y
2 3
1 0
3 8
What do you observe?
CISE301_Topic5 KFUPM - T212 - Section 01 21
Two Examples


1
) 2 )( 1 ( 1 ) 1 ( 3 0 ) (
2
2
=
+ + =
x
x x x x P
x Y
1 0 3 1
2 3 5
3 8
x Y
2 3 3 1
1 0 4
3 8
1
) 1 )( 2 ( 1 ) 2 ( 3 3 ) (
2
2
=
+ + =
x
x x x x P
Ordering the points should not affect the interpolating polynomial.
CISE301_Topic5 KFUPM - T212 - Section 01 22
Properties of Divided Difference


] , , [ ] , , [ ] , , [
0 1 2 0 2 1 2 1 0
x x x f x x x f x x x f = =
Ordering the points should not affect the divided difference:
CISE301_Topic5 KFUPM - T212 - Section 01 23
Example
Find a polynomial to
interpolate the data.
x f(x)
2 3
4 5
5 1
6 6
7 9
CISE301_Topic5 KFUPM - T212 - Section 01 24
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
) 6 )( 5 )( 4 )( 2 ( 6750 . 0
) 5 )( 4 )( 2 ( 5417 . 1 ) 4 )( 2 ( 6667 . 1 ) 2 ( 1 3
4

+ + =
x x x x
x x x x x x f
CISE301_Topic5 KFUPM - T212 - Section 01 25
x 1.6 2 2.5 3.2 4 4.5
f(x) 2 8 14 15 8 2
Example
Calculate f (2.8) using Newtons 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 - T212 - Section 01 26
x f(x) f[ , ] f[ , , ] f[ , , , ]
2.5 14 1.4286 -8.8095 1.0120
3.2 15 5.8333 -7.2917
2 8 0
4 8
The first through third-order interpolations can then be implemented as

Example
428571 . 14 ) 5 . 2 8 . 2 ( 428571 . 1 14 ) 8 . 2 (
1
= + = f
485714 . 15 ) 2 . 3 8 . 2 )( 5 . 2 8 . 2 ( 809524 . 8 ) 5 . 2 8 . 2 ( 428571 . 1 14 ) 8 . 2 (
2
= + = f
15.388571 .) 2 8 . 2 )( 2 . 3 8 . 2 )( 5 . 2 8 . 2 ( 1.011905
) 2 . 3 8 . 2 )( 5 . 2 8 . 2 ( 809524 . 8 ) 5 . 2 8 . 2 ( 428571 . 1 14 ) 8 . 2 (
3
= +
+ = f
CISE301_Topic5 KFUPM - T212 - Section 01 27
Summary


. polynomial ing interpolat affect the not should points the Ordering
methods Other -
2] 18. [Section ion Interpolat Lagrange -
] 18.1 [Section Difference Divided Newton -
it obtain to used be can methods Different *
unique. is Polynomial ing interpolat The *
..., , 2 , 1 , 0 ) ( ) ( : Condition ing Interpolat n i f or x f x f
i n i
= =
CISE301_Topic5 KFUPM - T212 - Section 01 28

Lecture 21
Lagrange Interpolation
CISE301_Topic5 KFUPM - T212 - Section 01 29
The Interpolation Problem
Given a set of n+1 points:



Find an n
th
order polynomial:
that passes through all points, such that:


( ) ( ) ( ) ) ( , ...., , ) ( , , ) ( ,
1 1 0 0 n n
x f x x f x x f x
) (x f
n
n i for x f x f
i i n
,..., 2 , 1 , 0 ) ( ) ( = =
CISE301_Topic5 KFUPM - T212 - Section 01 30
Lagrange Interpolation
Problem:
Given


Find the polynomial of least order such that:



Lagrange Interpolation Formula:
n i for x f x f
i i n
,..., 1 , 0 ) ( ) ( = =
) (x f
n
.
.
1
x
n
x
0
y
1
y
n
y
i
x
i
y
( )
( )
( )
[

= =
=

=
=
n
i j j
j i
j
i
n
i
i i n
x x
x x
x
x x f x f
, 0
0
) (
) ( ) (

0
x
CISE301_Topic5 KFUPM - T212 - Section 01 31
Lagrange Interpolation

=
=
=
j i
j i
x
x
j i
th
i
1
0
) (
: s polynomial order n are cardinals The
cardinals. the called are ) (

CISE301_Topic5 KFUPM - T212 - Section 01 32


Lagrange Interpolation Example

x 1/3 1/4 1
y 2 -1 7
( )
( )
( )
( )
( )
( )
( )
( )
( )
( )
( )
( )
( )
( )
( )
( )
( )
( )
( )
( )
( )
( )
( )
( )
{ } { }
{ } ) 4 / 1 )( 3 / 1 ( 2 7
) 1 )( 3 / 1 ( 16 1 ) 1 )( 4 / 1 ( 18 2 ) (
4 / 1 1
4 / 1
3 / 1 1
3 / 1
) (
1 4 / 1
1
3 / 1 4 / 1
3 / 1
) (
1 3 / 1
1
4 / 1 3 / 1
4 / 1
) (
) ( ) ( ) ( ) ( ) ( ) ( ) (
2
1 2
1
0 2
0
2
2 1
2
0 1
0
1
2 0
2
1 0
1
0
2 2 1 1 0 0 2
+
=

=
+ + =
x x
x x x x x P
x x
x x
x x
x x
x x
x
x x
x x
x x
x x
x x
x
x x
x x
x x
x x
x x
x
x x f x x f x x f x P


CISE301_Topic5 KFUPM - T212 - Section 01 33
Example
Find a polynomial to interpolate:

Both Newtons interpolation
method and Lagrange
interpolation method must
give the same answer.
x y
0 1
1 3
2 2
3 5
4 4
CISE301_Topic5 KFUPM - T212 - Section 01 34
Newtons Interpolation Method
0 1 2 -3/2 7/6 -5/8

1 3 -1 2 -4/3
2 2 3 -2
3 5 -1
4 4
CISE301_Topic5 KFUPM - T212 - Section 01 35
Interpolating Polynomial
) 3 )( 2 )( 1 (
8
5
) 2 )( 1 (
6
7
) 1 (
2
3
) ( 2 1 ) (
4

+ + =
x x x x
x x x x x x x f
CISE301_Topic5 KFUPM - T212 - Section 01 36
Interpolating Polynomial Using
Lagrange Interpolation Method
3 4
3
2 4
2
1 4
1
0 4
0
4 3
4
2 3
2
1 3
1
0 3
0
4 2
4
3 2
3
1 2
1
0 2
0
4 1
4
3 1
3
2 1
2
0 1
0
4 0
4
3 0
3
2 0
2
1 0
1
4 5 2 3 ) ( ) (
4
3
2
1
0
4 3 2 1 0
4
0
4

=
+ + + + = =

=
x x x x
x x x x
x x x x
x x x x
x x x x
x f x f
i
i i


CISE301_Topic5 KFUPM - T212 - Section 01 37
Lecture 22
Inverse Interpolation
Error in Polynomial Interpolation
CISE301_Topic5 KFUPM - T212 - Section 01 38
Inverse Interpolation


. ) ( : such that Find
. and table Given the
: Problem
g g g
g
y x f x
y
=
.
.
1
x
n
x
0
y
1
y
n
y
i
x
i
y
One approach:
Use polynomial interpolation to obtain f
n
(x) to interpolate the
data then use Newtons method to find a solution to:
g g n
y x f = ) (
0
x
CISE301_Topic5 KFUPM - T212 - Section 01 39
Inverse Interpolation
Alternative Approach

.
.
1
x
n
x
0
y
1
y
n
y
i
x
i
y
Inverse interpolation:
1. Exchange the roles
of x and y.

2. Perform polynomial
Interpolation on the
new table.
3. Evaluate

) (
g n
y f
.
.
i
y
0
y
1
y
n
y
i
x
0
x
1
x
n
x
0
x
CISE301_Topic5 KFUPM - T212 - Section 01 40
Inverse Interpolation


x
y
y
x
CISE301_Topic5 KFUPM - T212 - Section 01 41
Inverse Interpolation


Question:
What is the limitation of inverse interpolation?


The original function has an inverse.
y
1
, y
2
, , y
n
must be distinct.
CISE301_Topic5 KFUPM - T212 - Section 01 42
Inverse Interpolation
Example


5 . 2 ) ( such that Find table. Given the
: Problem
=
g g
x f x
x 1 2 3
y 3.2 2.0 1.6
3.2 1 -.8333 1.0416
2.0 2 -2.5
1.6 3
2187 . 1 ) 5 . 0 )( 7 . 0 ( 0416 . 1 ) 7 . 0 ( 8333 . 0 1 ) 5 . 2 (
) 2 )( 2 . 3 ( 0416 . 1 ) 2 . 3 ( 8333 . 0 1 ) (
2
2
= + =
+ =
f
y y y y f
CISE301_Topic5 KFUPM - T212 - Section 01 43
-5 -4 -3 -2 -1 0 1 2 3 4 5
-0.5
0
0.5
1
1.5
2
true function
10 th order interpolating polynomial
10
th
Order Polynomial Interpolation
CISE301_Topic5 KFUPM - T212 - Section 01 44
Errors in polynomial Interpolation
Polynomial interpolation may lead to large
errors (especially for high order polynomials).
BE CAREFUL

When an n
th
order interpolating polynomial is
used, the error is related to the (n+1)
th
order
derivative.


CISE301_Topic5 KFUPM - T212 - Section 01 45
1
) 1 ( 1
) 1 ( 4
: Then points). end the (including b] [a, in
points spaced equally 1 at es interpolat that
n degree of polynomial any be Let
. and b], [a, on continuous is
: such that function a be Let
+
+ +
|
.
|

\
|

+
s
+
s
s
n
n ) (n
n
a b
n
M
f (x)-P(x)
n f
P(x)
M f (x) f
f (x)
Errors in polynomial Interpolation
Theorem
CISE301_Topic5 KFUPM - T212 - Section 01 46
Example 1
9
10
1
) 1 (
th
10 34 . 1
9
6875 . 1
) 10 ( 4
1
) 1 ( 4
9 , 1
0 1
. [0,1.6875] interval in the points) spaced equally 0 1 (using
f(x) e interpolat to polynomial order 9 use want to We
sin

+
+
=
|
.
|

\
|
s
|
.
|

\
|

+
s
= =
> s
=
f (x)-P(x)
n
a b
n
M
f (x)-P(x)
n M
n f or f
(x) f (x)
n
n
CISE301_Topic5 KFUPM - T212 - Section 01 47
Interpolation Error
( )
[
=
=
n
i
i n n
n
n
x x x x x x f x f f (x)
x x x x
n f
0
1 0
1 0
] , ,..., , [ ) (
: node a not
any for then , ,..., , nodes at the f(x) function the
es interpolat that degree of polynomial the is (x) If
Not useful. Why?
CISE301_Topic5 KFUPM - T212 - Section 01 48
Approximation of the Interpolation Error
( )
[
=
+
+ +
~
n
i
i n n n
n n
n
n
x x x x x x f x f f (x)
x f x
x x x f (x)
n f
0
1 1 0
1 1
1 0
] , ,..., , [ ) (
: by ed approximat is error ion interpolat The
point. additional an be )) ( , ( Let
. ,..., , nodes at the function the
es interpolat that degree of polynomial the is (x) If
CISE301_Topic5 KFUPM - T212 - Section 01 49
Divided Difference Theorem
( )

) (
1 0
1 0
) (
!
1
] ,..., , [
: b] [a, some for then b], [a, in points distinct 1 any are
,..., , if and b], [a, on continuous is
n
n
n
n
f
n
x x x f
n
x x x f If
=
e +
1 0 ] ,..., , [
: then
, order of polynomial a is ) (
1 0
+ > = n i x x x f
n x f If
i
1 4 1 0 0
2 5 1 0
3 6 1
4 7
x x f + = 3 ) (
CISE301_Topic5 KFUPM - T212 - Section 01 50
Summary
The interpolating polynomial is unique.
Different methods can be used to obtain it.
Newtons divided difference
Lagrange interpolation
Others
Polynomial interpolation can be sensitive to
data.
BE CAREFUL when high order polynomials
are used.

You might also like