Interpolation
Interpolation
Chapter 18
1
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Interpolation : Estimation of a function value at an intermediate point
that lie between precise data points.
There is one and only one nth-order polynomial that perfectly fits n+1 data
points:
f ( x) a0 a1 x a2 x an x
2 n
2
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Newtons Divided-Difference Interpolating Polynomials
Linear Interpolation
Connecting two data points with a straight line
f1 ( x) f ( x0 ) f ( x1 ) f ( x0 )
x x0 x1 x0
f ( x1 ) f ( x0 )
f1 ( x) f ( x0 ) ( x x0 )
x1 x0
Linear-interpolation Slope
formula
3
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Quadratic Interpolation
If three (3) data points are available, the estimate is improved by introducing
some curvature into the line connecting the points.
A second-order polynomial (parabola) can be used for this purpose Represents a
second order
polynomial
A simple procedure can be used to determine the values of the coefficients
f 2 ( x) b0 b1 ( x x0 ) b2 ( x x0 )( x x1 )
x x0 b0 f ( x0 ) Could you
figure out how
f ( x1 ) f ( x0 )
to derive this
using the above
x x1 b1 equation?
x1 x0
f ( x2 ) f ( x1 ) f ( x1 ) f ( x0 )
x2 x1 x1 x0
x x2 b2
x 2 x0
4
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
f ( x) b0 b1 ( x x0 ) b2 ( x x0 )( x x1 )
f ( x1 ) f ( x0 )
b0 f ( x0 ) b1
x1 x0
f ( x1 ) f ( x0 )
f ( x2 ) f ( x0 ) ( x2 x0 )
f ( x2 ) f ( x0 ) b1 ( x2 x0 ) x1 x0
x x2 b2 b2
( x2 x0 )( x2 x1 ) ( x2 x0 )( x2 x1 )
( f ( x2 ) f ( x1 ) f ( x1 ) f ( x0 ))( x2 x1 ) ( f ( x1 ) f ( x0 ))( x2 x1 x1 x0 )
( x2 x1 ) ( x1 x0 )
x x2 b2
( x2 x0 )( x2 x1 )
( f ( x2 ) f ( x1 ))( x2 x1 ) ( f ( x1 ) f ( x0 ))( x2 x1 )
( x2 x1 ) ( x1 x0 )
b2
( x2 x0 )( x2 x1 )
f ( x2 ) f ( x1 ) f ( x1 ) f ( x0 )
( x2 x1 ) ( x1 x0 )
b2
( x2 x0 )
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
General Form of Newtons Interpolating Polynomials
f n ( x ) b0 b1 ( x x0 ) b2 ( x x0 )( x x1 ) bn ( x x0 )( x x1 )( x xn1 )
b0 f ( x0 ) b1 f [ x1 , x0 ] b2 f [ x2 , x1 , x0 ] bn f [ xn , xn1 , , x1, x0 ]
f ( xi ) f ( x j ) Bracketed function
f [ xi , x j ] evaluations are finite
xi x j divided differences
f [ xi , x j ] f [ x j , xk ]
f [ xi , x j , xk ]
xi xk
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
DIVIDED DIFFERENCE TABLE EXAMPLE
x0 f(x0) x0=0 2
7
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Given:
x0=1 f(x0)=ln(1) = 0
x1=e f(x1)=ln(2.72) = 1
xi f(xi) f[xi,xj] f[xi,xj xk]
x2=e2 f(x2)=ln(7.39) = 2
x0=1 0
Estimate ln(2) = ?
f(x) = 0.58(x-1)
using interpolation x1=2.72 1 .58
-0.057(x-1)(x-2.72)
Find f(x) first x2=7.39 2 .214 -.057
Then calculate
f(2)=0.58(2-1)-0.057(2-1)(2-2.72)
= 0.621
8
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Yet Another Example:
Given:
x0=1 f(x0)=ln(1)=0
x1=4 f(x1)=ln(4)=1.386
f[xi,xj] f[xi,xj xk]
x2=6 f(x2)=ln(6)=1.791 xi f(xi)
x0=1 0
Estimate ln(2) = ?
using interpolation x1=4 1.386 .462 f(x) = 0.462(x-1)
Find f(x) first -.052
-0.052(x-1)(x-4)
x2=6 1.79 .2025
Then calculate
f(2)=0.462*(2-1) -0.052*(2-1)(2-4)
= 0.566
9
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Error Estimation in Newtons Interpolating Polynomials
Rn f n1 ( x) f n ( x) in other words f n1 ( x) f n ( x) Rn
If an additional point (xn+1 , f(xn+1)) is available, then
Rn f [ xn1 , xn , xn1 ,, x0 ]( x x0 )( x x1 )( x xn )
This result is based on the assumption that the series is strongly convergent. i.e.
(n+1)th-order prediction is closer to the true value than the nth-order prediction.
10
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Previous Example: Example (for computing error):
In the previous Example, add a fourth point
x0=1 f(x0)=ln(1) = 0 x3=4 f(x3) = 1.386
x1=e f(x1)=ln(2.72) = 1 And estimate the approximate error in computing ln(2)
x2=e2 f(x2)=ln(7.39) = 2
2nd order polynomial estimation: f(2) = 0.621
f(x) = 0.58(x-1) True error = ln(2) f(2) = 0.693 - 0.621 = 0.072
-0.057(x-1)(x-2.72)
R2 = f3(x) - f2(x) = f[ x3, x2, x1, x0] (x- x0)(x- x1)(x- x2)
f(2) = 0.621 or
R2= 0.011*(x-1)(x-2.72)(x-7.39)
11
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Previous Example: Example (for computing error):
In the previous Example, add a fourth point
x0=1 f(x0)=0 x3=5 f(x3) = 1.609
x1=4 f(x1)=1.386 And estimate the error in computing ln(2)= f(2)
x2=6 f(x2)=1.791
2nd order polynomial estimation: f(2) = 0.566
f(x) = 0.462(x-1) True error = ln(2) f(2) = 0.693 - 0.566 = 0.127
-0.052(x-1)(x-4)
R2= f3(x)-f2(x) = f[ x3, x2, x1, x0] (x- x0)(x- x1)(x- x2)
f(2) = 0.566 or
R2= 0.008*(x- 1)(x- 4)(x- 6)
12
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Lagrange Interpolating Polynomials
The Lagrange interpolating polynomial is simply a reformulation of the Newtons
polynomial that avoids the computation of divided differences:
n x x1 x x0
f1 ( x) f ( x0 )
f n ( x) Li ( x) f ( xi )
f ( x1 )
x0 x1 x1 x0
i 0
f 2 ( x)
x x1 x x2
f ( x0 )
x0 x1 x0 x 2
x x0 x x2
n x xj
x1 x0 x1 x 2
f ( x1 )
Li ( x)
j 0 xi x j
x x0 x x1
f ( x2 )
j i x2 x0 x2 x1
Above formula can be easily verified by plugging in x0, x1in the equation one at a
time and checking if the equality is satisfied.
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
A visual depiction of the rationale behind
the Lagrange polynomial . The figure
shows a second order case:
f 2 ( x)
x x1 x x2 f ( x )
x0 x1 x0 x 2 0
x x0 x x2 f ( x )
x1 x0 x1 x 2 1
x x0 x x1
f ( x2 )
x2 x0 x2 x1
Each of the three terms passes through
one of the data points and zero at the
other two. The summation of the three
terms must, therefore, be unique second
order polynomial f2(x) that passes exactly
through three points.
14
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Coefficients of an Interpolating Polynomial
Although both the Newton and Lagrange polynomials are well suited for
determining intermediate values between points, they do not provide a
polynomial in conventional form: 2
f ( x ) a0 a1 x a2 x an x n
Since n+1 data points are required to determine n+1 coefficients,
simultaneous linear systems of equations can be used to calculate as.
2. Plug in the value of f(xk) in the above equation and find one of the real
roots of the resultant equation using a root finding method:
a0 a1 x a2 x an x f ( xk ) 0 2 n
16
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Spline Interpolation
EXAMPLE:
spline fits for a set of 4 points:
(a) linear
(b) quadratic
(c) cubic splines
linear spline
is superior to higher-order
interpolating polynomials (parts
a, b, and c)
17
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Quadratic Spline example
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Quadratic Splines - Equations
Given (n+1) points, there are 3(n) coefficients to find and hence, need to
determine 3n equations to solve:
1. Each polynomial must pass through the endpoints of the interval that
they are associated with. And these
conditions result in 2n equations:
ai xi2 bi xi ci f ( xi ) i 1,2,, n
ai xi21 bi xi 1 ci f ( xi 1 ) i 1,2,, n
1. The first derivatives at the interior knots must be equal ((n-1) equations):
2ai xi bi 2ai 1 xi bi 1 i 1,2,, n 1
2. So far, we are one equation short. Since the last equation will be derived
using only 2 points, it must be a line equation with only bn and cn to be
determined (an = 0)
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.