You are on page 1of 14

INTERPOLATION

Many times, data is given only at discrete points such as


......, xn 1 , yn 1

value of
the

n 1

xn , yn
,

x0 , y0 , x1 , y1

So, how then does one find the value of

? Well, a continuous function

data values with

f x

may be used to represent

passing through the


y

Then one can find the value of


interpolation.

f x

at any other

n 1

points (Figure 1).


x
at any other value of . This is called

x3 , y3

x1, y1
x2 , y2

x0 , y0

f x

Figure 1: Interpolation of discrete data

x
x
Of course, if
falls outside the range of
for which the data is given, it is
no longer interpolation but instead is called extrapolation. So what kind of

f x

function
should one choose? A polynomial is a common choice for an
interpolating function because polynomials are easy to

evaluate,
differentiate, and
integrate.

relative to other choices such as a trigonometric and exponential series.


Polynomial interpolation involves finding a polynomial of order
passes through the

n 1

that

points. This can be done through:

(i) Newtons divided difference polynomial method


1

(ii)
(iii)

Lagrangian interpolation method


Spline interpolation

NEWTONS
METHOD

DIVIDED

DIFFERENCE

POLYNOMIAL

LINEAR INTERPOLATION
-simplest form of interpolation is to connect two data points with a
straight line.
Eg 1: Using linear interpolation, estimate ln 2 given
(a) ln 1=0 and ln 6=1.791759.
(b) ln 1=0 and ln 4=1.386294.
For each of the interpolations, compute the percentage error based on
the true value of ln 2, where ln 2= 0.6931472.
Sol:
(a)
(b)

y0 1.386294
=
21
41

y=0.462098

y 0 1.7917590
=
21
61

( 0.69314720.462098
) x 100
0.6931472

Error , =
33.3

y=0.3583518

( 0.69314720.3583518
) x 100
0.6931472

Error , =
48.3

Thus, using shorter interval reduces the error.

QUADRATIC INTERPOLATION
The error in the above example, resulted from a curve with a straight line.
Consequently, a strategy for improving the estimate is to introduce some
curvature into the line connecting the points. If three data points are
available, this can be accomplished with a second order polynomial
(quadratic polynomial or parabola). A particularly convenient form for this
purpose is
f 2 ( x )=b o+ b1 ( xx o ) +b2 ( xx o ) ( xx 1 )

where

b0 , b1 ,

and

b2

are the first, second, and third finite divided

differences, respectively and is given by


bo =f [ x o ] =f ( x o ) , b1=f [ x 1 , x o ] =

b2=f [ x 2 , x 1 , x o ] =

f ( x1 ) f ( x o )
x 1x o

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

Eg 2: Fit a second order polynomial; to the three points:


x o=1, f ( x o ) =0
x 1=4, f ( x 1 )=1.386294
x 2=6, f ( x 2 )=1.791759
Use the polynomial to evaluate ln 2.
Sol:

(4, 1.386294)
(6, 1.791759)

y
x

1,0

1st divided dif


f [ x o ] =f ( x o )=0 bo
2nd divided dif
f ( x 1 )f ( x o ) 1.3862940
f [ x 1 , x o ]=
=
=0.4620981 b1
x1x o
41
f [ x 2 , x 1 ]=

f ( x 2 )f ( x1 ) 1.7917591.386294
=
=0.2027
x 2x 1
64

3rd

divided dif
f [ x 2 , x 1 ]f [ x 1 , x o ] 0.20270.4620981
f [ x 2 , x 1 , x o ]=
=
=0.052 b2
x 2x o
61

The quadratic polynomial is


f 2 ( x )=0.4620981 ( x1 )0.052 ( x1 )( x4 )
and at x=2,
4

2= 0.4620981 ( 21 )0.0518731 ( 21 ) ( 24 )=0.565844


ln
2
( 0.565844ln
) x 100
ln 2

Error , =

18.36

GENERAL FORM OF NEWTONS INTERPOLATING POLYNOMIALS


The preceding analysis can be generalized to fit an n thorder polynomial to
n+1 data points. The nth order polynomial is
f n ( x )=b o +b1 ( xx o ) +b 2 ( xx o ) ( xx 1 ) ++ bn ( xx o )( xx 1) (xx n)
f ( x o ) + f [ x 1 , x 0 ] ( xx o ) + f [ x 2 , x 1 , x o ] ( xx o ) ( xx 1 ) ++
f [ x n , x n1 , , x o ] ( xx o ) ( xx 1 ) ( x xn 1 )

Eg 3: Use Newton interpolation to construct the third-degree polynomial


that fits the data
x
f(x)

-1
3

0
-4

1
5

2
-6

Sol:

1st divided-diferences are:

3rd divided-diferences are:


f [ x 2 , x 1 ] f [ x 1 , x o ]
f [ x 2 , x 1 , x o ]=
x 2x o

2nd divided-diferences are:


f ( x 1 )f ( x o )
f [ x 1 , x o ]=
x1x o

43
=7 b1
0(1)

f [ x 2 , x 1 ]=

f [ x 3 , x 2 ]=

f ( x 2 )f ( x1 )
x 2x 1

9+7
=8 b2
1+ 1

f [ x 3 , x 2 , x 1 ]=

f [ x 3 , x 2 ]f [ x 2 , x 1 ] 119
=
=10
x 3x 1
20

4th divided-diference is:


f [ x 3 , x 2 , x 1 ]f [ x2 , x1 , x0 ] 108
f [ x 3 , x 2 , x 1 , x 0 ]=
=
=6
x 3x 0
2+1
=

5+4
=9
10

Thus,

f ( x 3 )f ( x 2 ) 65
=
=11
x 3x 2
21

Eg 4: E stimate ln 2 witha third order

Newto n' s interpolating polynomial for the

data given as below:


x o=1, f ( x o ) =0
x 1=4, f ( x 1 )=1.386294
x 2=5, f ( x 2) =1.609438
x 3=6, f ( x 3 )=1.791759
Calculate also the error produced based on ln 2= 0.6931472.

LAGRANGE INTERPOLATING POLYNOMIALS


The Lagrange interpolating polynomial is simply a reformulation of the
Newton polynomial that avoids the computation of divided differences. It
can be represented concisely as
n

f n ( x ) = Li ( x ) f ( x i )
i=0

where Li ( x )=
j=0
j i

xx j
designated the product of .
x ix j

For example, the linear version (n=1) is


xx 1
xx o
f 1 ( x )=
f ( xo ) +
f ( x1 )
xo x 1
x1 x o
and the second-order version is
(xx 1 )( xx 2)
(xx o)(x x2 )
(xx o)( xx1 )
f 2 ( x )=
f ( xo )+
f ( x1)+
f ( x2 )
( x ox 1 )( x ox 2)
( x 1x o)(x 1x 2 )
(x 2x o)( x2x 1 )
Eg 5: Use Lagrange interpolating polynomial of the first and second-order
to evaluate ln 2.
x o=1, f ( x o ) =0
x 1=4, f ( x 1 )=1.386294
x 2=6, f ( x 2 )=1.791759
Sol:
Firstorder polynomial , f ( 2 )=

24
21
( 0 )+
( 1.386294 )=0.4620981.
14
41

Second order polynomial , f ( 2 )=

( 21 )( 26 )
( 21 )( 24 )
( 1.386294 ) +
( 1.791760 )
( 41 )( 46 )
( 61 )( 64 )
= 0.5658444.

Eg 6: Use the nodes x0 = 2, x1 = 2.75 and x2 = 4 to find the second-order


Lagrange interpolating
1
polynomial for f ( x )= . Hence , approximate f ( 3 ) .
x
[Ans:
f(3)=0.32955]

SPLINE INTERPOLATION
In Mathematics, a spline is a special function defined piecewise by
polynomials. Therefore, spline interpolation is a form of interpolation
where the interpolant is a special type of piecewise polynomial. In the
previous sections, nth order-polynomials were used to interpolate between
n+1 data points. For example, for 4 points, we can derive a perfect thirdorder polynomial. This would capture all the meanderings suggested by
the points. However, there are cases where these functions can lead to
erroneous results because of round-off error and overshoot. An alternative
approach is to apply lower order polynomials to subset of data points.
Such connecting polynomials are called spline function. The main
advantages of spline interpolation are its stability and calculation
simplicity.
First-order spline/linear interpolation
Eg 7: Fit the data below with first-order splines. Hence, evaluate the
function at x=5.
X
3.0
4.5
7.0
9.0
f(x)
2.5
1.0
2.5
0.5

y
(7, 2.5)

(3, 2.5)

(4.5, 1)

(9, 0.5)
x

The slopes of the linear spline are


2.51.0
2.51.0
2.50.5
m 1=
=1, m2 =
=0.6, m3=
=1
34.5
74.5
79

x+5.5 ,3 x 4.5
f ( x ) = 0.6 x 1.7 , 4.5 x 7
x +9.5
,7 x 9

Therefore,

f ( 5 ) =0.6 ( 5 )1.7=1.3 .

QUADRATIC SPLINES
The objective of the quadratic splines is to derive a second-order
polynomial for each interval between data points. The polynomial for each
interval can be represented generally as
f i ( x )=a i x 2+ bi x+ ci
the a' s , b' sc ' s are arbitrary constants .

where

Eg 8: Fit quadratic splines to the same data used in the Eg 7. Hence,


evaluate the function at x=5.
X
f(x)

3.0
7.0
2.5
2.5

4.5
9.0
1.0
0.5

Sol:
Step 1: State the piecewise function

a1 x 2+ b1 x +c 1 ,3.0 x 4.5
f ( x )= a2 x 2+ b2 x +c 2 , 4.5 x 7.0
a3 x 2+ b3 x +c 3 ,7.0 x 9.0
There should be 9 equations to find the values of as, bs and cs.
Step 2: Substitute the boundary values into f(x).
f ( 3 ) =9 a1 +3 b1 +c 1=2.5
f ( 4.5 )=20.25 a1 + 4.5b 1+ c 1=1.0
20.25 a2 +4.5 b 2+ c2 =1.0
f (7)=49 a 2+7 b2+ c 2=2.5
49 a3 +7 b 3+ c 3=2.5

f (9)=81 a3 +9 b 3+ c 3=0.5

Step 3: Derivatives are continuous at interior data points.


At x=4.5,
d
d
(a x 2+ b1 x +c 1)|x=4.5 = (a2 x2 +b 2 x +c 2)|x=4.5
dx 1
dx
9 a1 +b 1=9 a2 +b 2
9 a1 +b 19 a2b2=0

and at x=7,

d
d
(a2 x 2+ b2 x +c 2 )|x=7= (a3 x 2 +b 3 x +c 3)|x=7
dx
dx
14

a2 +b 2=14 a3 + b3

14 a2 +b 214 a 3b3 =0
Step 4: Assume that the second derivative is zero at the first point via
setting a1=0 and write down all the 8 equations.
3 b1 +c 1=2.5
4.5 b 1+ c1=1.0
20.25 a2 +4.5 b 2+c2 =1.0
49 a 2+7 b 2+ c 2=2.5
49 a 3+7 b3 +c 3=2.5
81 a3 +9 b3 + c3 =0.5
9 a2b1 +b2=0
14 a2 14 a3 +b 2b3 =0

Step 5: Solve the system

[][ ]

b1
1
c1
5.5
a2
0.641
b2 6.76
The values of the unknows are
=
witha 1=0.
c2
18.46
1.6
a3
24.6
b3
91.3
c3

Step 6: The quadratic splines are


x +5.5
,3.0 x 4.5
2
(
)
f x = 0.64 x 6.76 x +18.46 , 4.5 x 7.0
1.6 x2 +24.6 x91.3 ,7.0 x 9.0

At x=5,

f ( 5 ) =0.64 ( 5 ) 6.76 ( 5 ) +18.46=0.66

The total spline fit is depicted in Figure (a) below. Notice that there are two
shortcomings that detract from the fit:
(i)
the straight line connecting the first two points, and
(ii)
the spline for the last interval seems to swing too high.
To overcome these shortcomings, the cubic splines (Figure b) are more
preferable and as a consequence, are better method for spline
interpolation.

Eg 9: Fit quadratic splines to the points: f(1)=2, f(2)=3, f(3)=5.


Ans : f ( x ) =

x+1,
1x 2
x 3 x +5, 2 x 3
2

Eg 10: Fit cubic splines to the points: f(1)=2, f(2)=3, f(3)=5.

1 3 3 2 3
x x + x +1, 1 x 2
4
4
2
Ans : f ( x ) =
1 3 9 2 9
x + x x +5, 2 x 3
4
4
2

You might also like