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

Chapter 18

Interpolation

1
Introduction
Estimation of intermediate values between
precise data points. The most common method is
polynomial interpolation:
f ( x) = a0 + a1 x + a2 x 2 +  + an x n

⚫ Polynomial interpolation is used when the point


determined are very precise. The curve
representing the behavior has to pass through
every point.
⚫ There is one and only one nth-order polynomial
that fits n+1 points
2
Introduction

n=3 n=4
n=2

First order (linear) 2nd order (quadratic) 3rd order (cubic)

n = number of data
3
Introduction

There are a variety of mathematical formats in which this


polynomial can be expressed:

➢The Newton polynomial (sec. 18.1)


➢The Lagrange polynomial (sec. 18.2)

4
Newton’s Divided-Difference
Interpolating Polynomials
Linear Interpolation
• Is the simplest form of interpolation, connecting two
data points with a straight line.
Slope and a
finite divided
f1 ( x) − f ( x0 ) f ( x1 ) − f ( x0 )
= difference
x − x0 x − x0 approximation to
1st derivative
f ( x1 ) − f ( x0 )
f1 ( x) = f ( x0 ) + ( x − x0 ) Linear-interpolation
x − x0 formula

• f1(x) designates that this is a first-order interpolating


polynomial.

5
Linear Interpolation

6
Quadratic Interpolation
• If three data points are available, the estimate is
improved by introducing some curvature into the
line connecting the points.
f 2 ( x) = b0 + b1 ( x − x0 ) + b2 ( x − x0 )( x − x1 )
• A simple procedure can be used to determine
the values of the coefficients.
x = x0 b0 = f ( x0 )
f ( x1 ) − f ( x0 )
x = x1 b1 =
x1 − x0
f ( x2 ) − f ( x1 ) f ( x1 ) − f ( x0 )

x2 − x1 x1 − x0
x = x2 b2 =
x2 − x0
7
Linear vs Quadratic Interpolation

8
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

9
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 ]

10
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

11
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]

12
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.

13
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.
14
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

15
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

16
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
17
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)


18
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?

19
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 −1
2 = x2 −1

Ordering the points should not affect the interpolating


polynomial.

20
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 ]

21
Example

x f(x)
• Find a polynomial to
interpolate the data.
2 3

4 5

5 1

6 6

7 9

22
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)

23
Errors of Newton’s Interpolating Polynomials
• Structure of interpolating polynomials is similar to the
Taylor series expansion in the sense that finite divided
differences are added sequentially to capture the higher
order derivatives.
• For an nth-order interpolating polynomial, an analogous
relationship for the error is:
 is somewhere
f ( n+1) ( )
Rn = ( x − x0 )( x − x1 ) ( x − xn ) containing the
(n + 1)! unknown and the data

• For non differentiable functions, if an additional point


f(xn+1) is available, an alternative formula can be used
that does not require prior knowledge of the function:
Rn  f [ xn +1 , xn , xn −1 , , x0 ]( x − x0 )( x − x1 )  ( x − xn )

24
Problem 18.6

25
Lagrange Interpolating Polynomials

• The general form for n+1 data points is:


n
f n ( x) =  Li ( x) f ( xi )
i =0
n x − xj
Li ( x) = 
j =0 xi − x j
j i

designates the “product of”

26
Lagrange Interpolating Polynomials

• Linear version (n = 1):


Used for 2 points of data: (xo,f(xo)) and (x1,f(x1)),

x − x1 x − x0
f1 ( x ) = f ( x0 ) + f ( x1 )
x0 − x1 x1 − x0

Lo (x ) L1 ( x )

27
Lagrange Interpolating Polynomials

• Second order version (n = 2):

f 2 ( x) =
( x − x1 )( x − x2 )
f ( x0 ) Lo ( x) , j  0
(x0 − x1 )(x0 − x 2 )
+
( x − x0 )( x − x2 )
f ( x1 ) L1 ( x) , j  1
(x1 − x0 )(x1 − x 2 )
+
( x − x0 )(x − x1 )
f ( x2 ) L2 ( x) , j  2
(x2 − x0 )(x2 − x1 )
28
Lagrange Interpolating Polynomials -
Example

Use a Lagrange interpolating polynomial of the first and


second order to evaluate ln(2) on the basis of the data:

x0 = 1 f ( x0) = ln(1) = 0
x1 = 4 f ( x1) = ln( 4) = 1.386294
x2 = 6 f ( x 2) = ln( 6) = 1.791760

29
Lagrange Interpolating Polynomials –
Example (cont’d)

• First order polynomial:

x − x1 x − x0
f 1( x) = f ( x 0) + f ( x1)
x 0 − x1 x1 − x 0
2−4 2 −1
f 1(2) = 0 + 1.386294 = 0.4620981
1− 4 4 −1

30
Lagrange Interpolating Polynomials –
Example (cont’d)

• Second order polynomial:

x − x1 x − x2 x−4 x−6
Lo ( x ) =  = 
xo − x1 xo − x2 0 − 4 0 − 6
x − xo x − x 2 x − 0 x − 6
L1 ( x ) =  = 
x1 − xo x1 − x2 4 − 0 4 − 6
x − xo x − x1 x − 0 x − 4
L2 ( x ) =  = 
x2 − xo x2 − x1 6 − 0 6 − 4

31
Lagrange Interpolating Polynomials –
Example (cont’d)

n n
x − xj
f n ( x ) =  Li ( x ) f ( xi ) Li ( x ) =  ( j  i)
i =0 j =0 xi − x j
(2 − 4)(2 − 6)
f 2 ( 2) = 0
(1 − 4)(1 − 6)
(2 − 1)(2 − 6)
+ 1.386294
(4 − 1)(4 − 6)
(2 − 1)(2 − 4)
+ 1.791760 = 0.5658444
(6 − 1)(6 − 4)

32
Lagrange Interpolating Polynomials –
Example (cont’d)

33
Pseudocode – Lagrange interpolation

34
Summary

Interpolat ing Condition : f ( xi ) = f n ( xi ) for i = 0, 1, 2, ..., n


* The interpolat ing Polynomial is unique.
* Different methods can be used to obtain it
- Newton Divided Difference [Section 18.1 ]
- Lagrange Interpolat ion [Section 18. 2]
- Other methods

Ordering the points should not affect the interpolat ing polynomial .

35
Spline Interpolation

• Polynomials are the most common choice of


interpolants.
• There are cases where polynomials can lead to
erroneous results because of round off error and
overshoot.
• Alternative approach is to apply lower-order
polynomials to subsets of data points. Such
connecting polynomials are called spline
functions.

40
Spline Interpolation
The concept of spline is using a thin, flexible strip
(called a spline) to draw smooth curves through a
set of points….natural spline (cubic)

41
42
Why Spline Interpolation?

Apply lower-order polynomials to subsets of data points. Spline


provides a superior approximation of the behavior of functions
that have local, abrupt changes.

43
Why Splines ?

1
f ( x) =
1 + 25 x 2
Table : Six equidistantly spaced points in [-1, 1]
1
x y=
1 + 25 x 2

-1.0 0.038461

-0.6 0.1

-0.2 0.5

0.2 0.5

0.6 0.1

1.0 0.038461 Figure : 5th order polynomial vs. exact function

44
Why Splines ?

17th Order
Polynomial

Original
Function

5th Order
Polynomial

9th Order
Polynomial

Figure : Higher order polynomial interpolation is a bad idea

45
Linear Spline
The first order splines for a group of ordered data
points can be defined as a set of linear functions:

f ( x) = f ( x0 ) + m0 ( x − x0 ) x0  x  x1
f ( x) = f ( x1 ) + m1 ( x − x1 ) x1  x  x2

f ( x) = f ( xn −1 ) + mn −1 ( x − xn −1 ) xn −1  x  xn

f ( xi +1 ) − f ( xi )
mi =
xi +1 − xi
46
Linear spline - Example
Fit the following data with first order splines. Evaluate
the function at x = 5.

2.5 − 1
x f(x) m= = 0.6
7 − 4.5
3.0 2.5 f (5) = f (4.5) + m(5 − 4.5)
4.5 1.0 = 1.0 + 0.6  0.5
7.0 2.5
9.0 0.5 = 1.3

47
Linear Spline

• The main disadvantage of linear spline is that


they are not smooth. The data points where 2
splines meets called (a knot), the changes
abruptly.

• The first derivative of the function is discontinuous


at these points.

• Using higher order polynomial splines ensure


smoothness at the knots by equating derivatives at
these points.
48
Quadric Splines
• Objective: to derive a second order polynomial for each
interval between data points.
• Terms: Interior knots and end points

f i ( x) = ai x 2 + bi x + ci

For n+1 data


points:
• i = (0, 1, 2, …n),
• n intervals,
• 3n unknown
constants (a’s, b’s
and c’s)

49
Software: MATLAB / Octave (GNU)

70

You might also like