Interporation
Interporation
Numerical Methods
Interpolation
1
Interpolation
• Estimating intermediate values between precise data points.
• We first fit a function that exactly passes through the given data points and than evaluate
intermediate values using this function.
f(x) f(x)
extrapolation
interpolation
x x
2
Polynomial Interpolation
• Given the following n+1 data points
(x1, y1), (x2, y2), (x3, y3), ..., (xn+1, yn+1)
there is a unique nth order polynomial that passes through them
p(x) = a0 + a1 x + a2 x2 + . . . + an xn
• The question is to find the coefficients a0 , a1 , . . ., an
• Linear Interpolation:
• Given: (x0, y0) and (x1, y1)
• A straight line passes from these two points.
y1 = f(x1) • Using similar triangles
a0 + a 1 x
f(x) = ? f (x ) f (x 0 ) f (x 1 ) f (x 0 )
x x0 x1 x 0
y0 = f(x0)
x
x0 x x1 f (x 1 ) f (x 0 )
f (x ) f (x 0 ) (x x 0 )
x1 x 0
or
f1 (x ) b 0 b1 (x x 0 )
f2 (x ) b 0 b1 (x x 0 ) b2 (x x 0 )( x x 1 )
y0 = f(x0)
x
x0 x1 x2 Quadratic interpolation formula
f (x 1 ) f(x 0 )
• at x=x1 f2(x) = f(x1) = b0 + b1x1 b1
x1 x 0
where the bracketed functions are finite divided differences evaluated recursively
f (x i ) f(x j )
f [x i , x j ] 1st finite divided difference
xi x j
f [x i , x j ] f [x j , x k ]
f [x i , x j , x k ] 2nd finite divided difference
xi xk
x f(x)=log(x)
4.0 0.60206 (a) Interpolate log(5) using the points x=4 and x=6
4.5 0.6532125 (b) Interpolate log(5) using the points x=4.5 and x=5.5
6
Example 29 (cont’d):
x f(x)=log(x) (c) Interpolate log(5) using the points x=4.5, x=5.5 and x=6
4.0 0.6020600
4.5 0.6532125
5.5 0.7403627
6.0 0.7781513
7
Finite Divided Difference (FDD) Table
Finite divided differences used in the Newton’s Interpolating Polynomials can be presented in a table
form. This makes the calculations much simpler.
Exercise 27: The first two columns of the following table is given. Calculate the missing finite
divided differences.
x f( ) f[, ] f[, ,] f[, , ,]
4 0.6020600 ? ? ?
4.5 0.6532125 ? ?
5.5 0.7403627 ?
6 0.7781513
• The numbers decrease as we go right in the table. This means that the contribution of higher order
terms are less than the lower order terms.
• This is expected. The opposite behavior is an indication of an inappropriate interpolation (see exam
questions of Fall 2006). 8
Example 30: x f( ) f[, ] f[, ,] f[, , ,]
4 0.6020600 0.1023050 -0.0101032 0.001194
4.5 0.6532125 0.0871502 -0.0077153
5.5 0.7403627 0.0755772
6 0.7781513
Exercise 29: Complete the following table given for the log function. Do you observe anything
strange? Comment.
f n 1 (x )
Rn ( x x 0 )( x x 1 ) . . . ( x x n )
(n 1)!
where x is somewhere in the interval containing the interpolated point x and other data points.
• But usually only the set of data points is given and the function f is not known.
• An alternative formulation uses a finite divided difference to approximate the (n+1)th derivative.
R n f[x , x n , x n 1 , . . . , x 0 ] (x x 0 )( x x 1 ) . . . (x x n )
12
Lagrange Interpolating Polynomials
• It is a reformulation of Newton’s Interpolating Polynomials.
n n x xj
fn (x ) L i (x)f (x i ) where L i (x ) xi x j
i 0 j 0
ji
x x1 x x0
• For n=1 (linear): f1 (x ) f (x 0 ) f (x 1 )
x 0 x1 x1 x 0
(x x 1 )( x x 2 ) (x x 0 )( x x 2 ) (x x 0 )( x x 1 )
• For n=2: f2 (x ) f (x 0 ) f (x 1 ) f (x 2 )
(x 0 x 1 )( x 0 x 2 ) (x 1 x 0 )( x 1 x 2 ) (x 2 x 0 )( x 2 x 1 )
• To generalize, nth order polynomial is the summation of (n+1) nth order polynomials.
• Each of these nth order polynomials have a value of 1 at one of the data points and have values of 0
at all other data points.
1 at x xi
• This is due to the following property of Lagrange functions L i ( x )
0 at all other data points
+ + =
x0 x1 x213
Example 31:
Exercise 30: Solve part (b) using the last three points. Also solve part (c).
14
Spline Interpolation
• We learned how to interpolate between n+1 data points using nth order polynomials.
• For high number of data points (typically n > 6 or 7), high order polynomials are necessary, but
sometimes they suffer from oscillatory behavior.
actual function
interpolation
function
• Instead of using a single high order polynomial that passes through all data points, we can use
different lower order polynomials between each data pair.
• These lower order polynomials that pass through only two points are called splines.
• Third order (cubic) splines are the most preferred ones.
15
Linear Splines:
• Given a set of ordered data points, each two point can be connected using a straight line.
x
where the slopes are mi = [f(xi+1) – f(xi)] / (xi+1 - xi)
x0 x1 x2 x3
• Functions are not continuous at the interior points.
Quadratic Splines:
• Every pair of data points are connected using quadratic functions.
a2x2+b2x+c2
f(x) a1x2+b1x+c1 anx2+bnx+cn
• For n+1 data points, there are n splines
and 3n unknown constants.
x
x0 x1 x2 .... xn-1 xn 16
Quadratic Splines (cont’d):
• These 3n equations are
• The first and last functions must pass through the end points (2 equations).
a1 x02 + b1 x0 + c1 = f(x0)
an xn2 + bn xn + cn = f(xn)
• This makes a total of 3n-1 equations. One more equation is necessary and we need to make an
arbitrary choice. Among many possibilities we will use the following,
• Solve this set of 3n linear algebraic equations with any of the methods that we learned.
17
Cubic Splines:
• For n+1 points, there will be n intervals and for each interval there will be a 3rd order polynomial
ai xi3 + bi xi2 + ci x + di for i = 1 to n
• Totally there are 4n unknowns. They can be solved using the following equations
• The first and last functions must pass through the end points (2 equations).
• The function values must be equal at interior points (2n-2 equations).
• First derivatives must be equal at the interior points (n-1 equations).
• Second derivatives must be equal at the interior points (n-1 equations).
• This makes a total of 4n-2 equations. Two extra equations are (other choices are possible)
• Second derivatives at the end points are zero (2 equations).
• Setting up and solving 4n equations is costly. There is another way of constructing cubic splines that
results in only n-1 equations in n-1 unknowns. See pages 502-503 of the book.
18
Example 32:
Develop quadratic splines for these data points and predict f(3.4) and f(2.2)
x f(x)
1 1 ai x2 + bi x + ci
f(x)
2 5
2.5 7
3 8
4 2 x
x0=1 2 2.5 3 4
• There are 5 points and n=4 splines. Totally there are 3n=12 unknowns. Equations are
• End points: a1 12+ b1 1 + c1 = 1 , a4 42 + b4 4 + c4 = 2
• Interior points: a1 22 + b1 2 + c1 = 5 , a2 22 + b2 2 + c2 = 5
a2 2.52 + b2 2.5 + c2 = 7, a3 2.52 + b3 2.5 + c3 = 7
a3 32 + b3 3 + c3 = 8 , a4 32 + b4 3 + c4 = 8
• Derivatives at the interior points: 2a12 + b1 = 2a2 2 + b2
2a2 2.5 + b2 = 2a3 2.5 + b3
2a3 3 + b3 = 2a4 3 + b4
• Arbitrary choice for the missing equation: a1 = 0 19
Example 32 (cont’d):
1 1 0 0 0 0 0 0 0 0 0 b1 1 b1 4
0
0 0 0 0 0 0 0 16 4 1 c
1
2
c
1
-3
2 1 0 0 0 0 0 0 0 0 0 a2 5 a2 0
0 0 4 2 1 0 0 0 0 0 0 b2 5 b2 4
0 0 6.25 2.5 1 0 0 0 0 0 0 c2 7 c2 -3
0 0 0 0 0 6.25 2.5 1 0 0 0 a3 7 a3 - 4
0 0 0 0 0 9 3 1 0 0 0 b 8 b 24
3 3
0 0 0 0 0 0 0 0 9 3 1 c3 8 c3 - 28
1
0 4 1 0 0 0 0 0 0 0 a
0 a
- 6
4 4
0 0 5 1 0 5 1 0 0 0 0 b 4 0 b 4 36
0 0 0 0 0 6 1 0 6 1 0 c 4 0 c 4 46
• Equations for the splines are
1st spline: f(x) = 4x – 3 (Straight line.)
2nd spline: f(x) = 4x – 3 (Same as the 1st. Coincidence)
3rd spline: f(x) = -4x2 + 24x – 28
4th spline: f(x) = -6x2 + 36x – 46
• To predict f(3.4) use the 4th spline. f(3.4) = -6 (3.4)2 + 36 (3.4) – 46 = 7.04
To predict f(2.2) use the 2nd spline. f(2.2) = 4 (2.2) – 3 = 5.8 20