Download as pdf or txt
Download as pdf or txt
You are on page 1of 35

Chapter 3: Curve Fitting

& Interpolation

Lecture 2:
Interpolation
Problem on Flood-tide Levels
The flood-tide levels measured at a station at different
times in a certain day are given in the following table
Time (h) 15 16 17 18
Level (m) 0.4 0.6 1.0 1.2

a) Estimate the flood-tide level at 16h30

b) At what time the flood tide level is 0.8m?

MAFE208IU-L7 2
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

MAFE208IU-L7 3
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
MAFE208IU-L7 4
Examples of Polynomial Interpolation
Linear Interpolation Quadratic Interpolation

 Given any two points, Given any three points there


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

MAFE208IU-L7 5
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

MAFE208IU-L7 6
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
MAFE208IU-L7 7
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 kth-order DD

MAFE208IU-L7 8
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 ]

This is called Newton’s divided-difference interpolating polynomial


MAFE208IU-L7 9
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 

MAFE208IU-L7 10
Example
 Find a polynomial to
interpolate the data. x f(x)

2 3

4 5

5 1

6 6

7 9
MAFE208IU-L7 11
Solution
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 ( x) = 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)

f (3)  f 4 (3) = 3 + 1(3 − 2) − 1.6667(3 − 2)(3 − 4) + 1.5417(3 − 2)(3 − 4)(3 − 5)


− 0.6750(3 − 2)(3 − 4)(3 − 5)(3 − 6) = 12.8001
MAFE208IU-L7 12
MAFE208IU-L7 13
Exercise
The money (in millions USD) donated for a certain
event is given in the following table.

Days 1 3 5 6
Money 2 4 8 3

Use a third-degree interpolating polynomial to


predict the money donated in the 2nd and 4th days

1/24/2021 14
Lagrange Interpolation
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 ) for i = 0,1, 2,..., n

MAFE208IU-L7 16
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 )  i ( x)
i =0

(x − x )
n
 i ( x) =  (x − x )
j =0, j i
j

i j
MAFE208IU-L7 17
Lagrange Interpolating Polynomial
n
f n ( x) =  f (xi )  i ( x)
i =0

(x − x )
n
 i ( x) =  (x − x )
j =0, j i
j

i j

 i ( x) are called the cardinals.


th
The cardinals are n order polynomials :
0 i  j
 i (x j ) = 
1 i = j
MAFE208IU-L7 18
Example: Find Langrange Interpolating polynomial that pases
though the data points
x 1/3 1/4 1
y 2 -1 7
Solution
f 2 ( x) = f ( x0 ) 0 ( x) + f ( x1 ) 1 ( x) + f ( x2 ) 2 ( x)
( 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 )
f 2 ( x) = 2 −18( x − 1/ 4)( x − 1) − 116( x − 1/ 3)( x − 1)
MAFE208IU-L7 + 7 2( x − 1/ 3)( x − 1/ 4) 19
Example
Find a polynomial to interpolate: x y

0 1
Both Newton’s interpolation
method and Lagrange 1 3
interpolation method must
give the same answer. 2 2

3 5

4 4

MAFE208IU-L7 20
Newton’s 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

MAFE208IU-L7 21
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

115 95 2 59 3 5 4
f4 ( x) = 1 + x− x + x − x
12 8 12 8

MAFE208IU-L7 22
Interpolating Polynomial Using
Lagrange Interpolation Method


4

f4 ( x) = f ( xi )  i =  0 + 31 + 2 2 + 5 3 + 4 4
i =0
( x − 1) ( x − 2) ( x − 3) ( x − 4) ( x − 1)( x − 2)( x − 3)( x − 4)
0 = =
(0 − 1) ( 0 − 2) (0 − 3) ( 0 − 4) 24
( x − 0) ( x − 2) ( x − 3) ( x − 4) x ( x − 2)( x − 3)( x − 4)
1 = =
(1 − 0) (1 − 2) (1 − 3) (1 − 4) −6
( x − 0) ( x − 1) ( x − 3) ( x − 4) x ( x − 1)( x − 3)( x − 4)
2 = =
( 2 − 0) ( 2 − 1) ( 2 − 3) ( 2 − 4) 4
( x − 0) ( x − 1) ( x − 2) ( x − 4) x ( x − 1)( x − 2)( x − 4)
3 = =
( 3 − 0) (3 − 1) ( 3 − 2) ( 3 − 4) −6
( x − 0) ( x − 1) ( x − 2) ( x − 3) x ( x − 1)( x − 2)( x − 3)
4 = =
( 4 − 0) ( 4 − 1) ( 4 − 2) ( 4 − 3) 24
MAFE208IU-L7 23
Inverse Interpolation
Error in Polynomial Interpolation
Inverse Interpolation
Problem: Given a table of values
Find x such that: f ( x) = y, where y is given

xi x0 x1 …. xn
yi y0 y1 …. yn

One approach:
Use polynomial interpolation to obtain fn(x) to interpolate the
data then use Newton’s method to find a solution to x

f n ( x) = y
MAFE208IU-L7 25
Inverse Interpolation
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

x = f n ( y)
MAFE208IU-L7 26
Inverse Interpolation

x
y

x y

MAFE208IU-L7 27
Inverse Interpolation
Question:

What is the limitation of inverse interpolation?

• The original function has an inverse.


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

MAFE208IU-L7 28
Inverse Interpolation
Example

x 1 2 3
Problem : y 3.2 2.0 1.6

Given the table. Find x such that f ( x ) = 2.5


3.2 1 -.8333 1.0417
2.0 2 -2.5
1.6 3

x = f 2 ( y ) = 1 − 0.8333( y − 3.2) + 1.0417( y − 3.2)( y − 2)


x = f 2 (2.5) = 1 − 0.8333( −0.7) + 1.0417( −0.7)(0.5) = 1.2187
MAFE208IU-L7 29
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.

MAFE208IU-L7 30
10th 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

MAFE208IU-L7 31
Errors in polynomial Interpolation
Theorem

Suppose the distinct x0 , x1 ,..., xn  [ a, b] and f  C n +1[ a, b].


Then, x  [a, b],   (a, b) such that
f ( n +1) ( )
f ( x) = P( x) + ( x − x0 )( x − x1 )...( x − xn )
(n + 1)!
where P( x) is the interpolating polynomial

MAFE208IU-L7 32
Exercise
The flood-tide levels measured at a station at different
times in a certain day are given in the following table
Time (h) 15 16 17 18
Level (m) 0.4 0.6 1.0 1.2

a) Develop Newton’s interpolating polynomial for


these data. Use it to to estimate the flood-tide level
at 16h30
b) Develop Lagrange interpolating polynomial for
these data. Use it to to estimate the flood-tide level
at 17h30
c) At what time the flood tide level is 0.9m?
MAFE208IU-L7 33
Life expectancy improved dramatically in the 20th century. The
table gives the life expectancy at birth ( in years) of males born
in the US. Predict the life span of a male born in the year 2010
using least squares regression with
a) Linear model, b) Quadratic model, c) Exponential model with
Linearization
Which one is the best? Why?
QUIZ 4

1. The money flow rate into a bank in a morning


is given in the following table

Time (h) 8 9 10 11
Rate (millions S/h) 18 16 12 5

a) Use 3rd-degree Newton interpolating polynomial to


estimate the flow rate at 9h30
b) Use 3rd-degree Lagrange interpolating polynomial to
estimate the flow rate at 10h30

c) Use inverse interpolation to determine the time the


flow rate reaches 10 millions/h

MAFE208IU-L7 35

You might also like