You are on page 1of 47

MAT3005 - Applied Numerical Methods

Dr. B.S.R.V. Prasad


Department of Mathematics
School of Advanced Sciences
VIT, Vellore

srvprasad.bh@gmail.com
srvprasad.bh@vit.ac.in
Interpolation of Non Equi-space Data Points
1

Introduction
I Till now we have discussed the interpolation techniques for estimating
the missing data when the data points are equi-spaced.
I But, in many cases the data points are not equi-spaced.
I In this case, we can not use the Newton’s forward/backward or
Striling’s interpolation techniques.
I We should go for other techniques for solving these non-equispaced
data sets.

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Interpolation of Non Equi-space Data Points
2

Introduction
I In next few classes we will discuss various methods of interpolation.
They include:
1. Lagrange interpolation
2. Newton’s divided difference interpolation
3. Spline interpolation

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Lagrange Interpolation
3

Polynomials
I A polynomial is an expression of finite length constructed from
variables (also called indeterminates) and constants, using only the
operations of addition, subtraction, multiplication, and non-negative
integer exponents.
I The most common form of an nth order polynomial is:

pn (x) = an xn + an−1 xn−1 + · · · + a2 x2 + a1 x + a0 ,

where n is a non-negative integer and a0 , a1 , a2 , . . . , an are constant


coefficients.

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Lagrange Interpolation
4

Lagrange Interpolating Polynomials


I The basic problem of polynomial interpolation is as follows: Given a set
of (n + 1) distinct data points (xi , yi ), i = 0, 1, 2, . . . , n, we have to find
the curve y = f(x) passing through these points.
I We make the following assumptions on the unknown function f(x).
I First, we assume that f(x) is sufficiently smooth. i.e., the function f(x)
is continuously differentiable (n + 1)−times in the interval [a, b].
I We further assume that the class of approximating functions be
polynomials of degree ≤ n and of the form

y = Pn (x) = a0 + a1 x + a2 x2 + . . . + an xn .

I Now, we should determine the constants ai , i = 0, 1, 2, . . . , n.

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Lagrange Interpolation
5

Lagrange Interpolating Polynomials


I Since the polynomial Pn (x) passes through the points
(xi , yi ), i = 0, 1, 2, . . . , n, it follows that

y0 = a0 + a1 x0 + a2 x02 + . . . + an x0n .
y1 = a0 + a1 x1 + a2 x12 + . . . + an x1n .
..
.
yn = a0 + a1 xn + a2 xn2 + . . . + an xnn .

I The above is a system of (n + 1) linear algebraic equations for the


(n + 1) unknowns, ai , i = 0, 1, 2, . . . , n.

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Lagrange Interpolation
6

Lagrange Interpolating Polynomials


I The above system can be written in the matrix form AX = b where

1 x0 x02 . . . x0n
     
2 n
a0 y0
1 x1 x1 . . . x1   a1   y1 
A = . ..  , X = 
. . . and b = . . .
 
..   
 .. . .
1 xn x 2 . . . x n an yn
n n

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Lagrange Interpolation
7

Lagrange Interpolating Polynomials


I The determinant of the coefficient matrix of the above system is:

1 x0 x02 . . . x0n

1 x1 x12 . . . x1n

Y n
D= . = (xi − xj ) 6= 0

.. ..
..

. . i,j=0,
1 xn x 2 . . . x n i6=j
n n

I This determinant is called Van der Monde determinant and is clearly


different from zero (as the given points are distinct).
I Thus the above system possess a unique solution.
I Solving the above system analytically is difficult and therefore we
employ the numerical techniques.

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Lagrange Interpolation
8

Lagrange Interpolating Polynomials


I Let us define the auxiliary functions
n
Y
Pk (x) = (x − x0 ) . . . (x − xk−1 )(x − xk+1 ) . . . (x − xn ) = (x − xi )
i=0
i6=k

I Note that Pk (x) = 0 for any x = xi , i 6= k, i = 0, 1, 2 . . . , n.


I Since there are n factors, Pk (x) are polynomials of degree n.
I Now, let
n
X
y = φ(x) = Ak Pk (x),
k=0

where Ak , k = 0, 1, 2, . . . , n are constants to be determined.

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Lagrange Interpolation
9

Lagrange Interpolating Polynomials


I Clearly, φ(x) is a polynomial of degree n (or less). Further, we have that at
x = xi , y = yi . Therefore,
n
X
yi = φ(xi ) = Ak Pk (xi ) = Ai Pi (xi ).
k=0

I Therefore,
yi
Ai = .
Pi (xi )
I Hence,
n
X Pk (x)
Ln (x) = y = φ(x) = yk
Pk (xk )
k=0
n Y
n
X (x − xi )
= yk (1)
(xk − xi )
k=0 i=0
i6=k

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Lagrange Interpolation
10

Lagrange Interpolating Polynomials


I The polynomials
n
Y (x − xi )
lk (x) =
(xk − xi )
i=0
i6=k

are called Lagrange Basis Polynomials.


I (
0 for k 6= i
lk (xi ) =
1 for k = i

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Inverse Lagrange Interpolation
11

Inverse Lagrange Interpolation


Interchanging x and y in the equation (1), we obtain
n Y
n
X (y − yi )
Ln (y) = x = ψ(y) = xk (2)
(yk − yi )
k=0 i=0
i6=k

This is called inverse interpolation formula.

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Lagrange Interpolation
12

Algorithm for Lagrange Interpolation


Step 1: Initialise sum=0, prod = 1;
Step 2: Accept the x value
Step 3: for k=0 to n do
for i=0 to n and i != k do
prod = prod*(x - x(i))/(x(k) - x(i))
end
sum = sum + prod
end
Step 3: Output sum

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Lagrange Interpolation
13

Problem
Certain corresponding values of x and log10 x are
(300, 2.4771), (304, 2.4829), (305, 2.4843) and (307, 2.4871). Find
log10 301.

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Lagrange Interpolation
14

Solution.
(301 − 304)(301 − 305)(301 − 307)
log10 301 = (2.4771)
(300 − 304)(300 − 305)(300 − 307)
(301 − 300)(301 − 305)(301 − 307)
+ (2.4829)
(304 − 300)(304 − 305)(304 − 307)
(301 − 300)(301 − 304)(301 − 307)
+ (2.4843)
(305 − 300)(305 − 304)(305 − 307)
(301 − 300)(301 − 304)(301 − 305)
+ (2.4871)
(307 − 300)(307 − 304)(307 − 305)
= 1.2739 + 4.9658 − 4.4717 + 0.7106
= 2.4786.

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Lagrange Interpolation
15

Problem
For the given table of values of y = f(x), construct a Lagrange Polynomial of
degree 3 and hence find the value of y when x = 3.
x 0 1 2 4
y 1 3 9 81

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Lagrange Interpolation
16

Solution. We have
(x − 1)(x − 2)(x − 4) 1
l0 (x) = = − (x3 − 7x2 + 14x − 8)
(0 − 1)(0 − 2)(0 − 4) 8
(x − 0)(x − 2)(x − 4) 1
l1 (x) = = (x3 − 6x2 + 8x)
(1 − 0)(1 − 2)(1 − 4) 3
(x − 0)(x − 1)(x − 4) 1
l2 (x) = = − (x3 − 5x2 + 4x)
(2 − 0)(2 − 1)(2 − 4) 4
(x − 0)(x − 1)(x − 2) 1 3
l3 (x) = = (x − 3x2 + 2x)
(4 − 0)(4 − 1)(4 − 2) 24
So,
1 1
L3 (x) = − (x3 − 7x2 + 14x − 8)(1) + (x3 − 6x2 + 8x)(3)
8 3
1 1
− (x3 − 5x2 + 4x)(9) + (x3 − 3x2 + 2x)(81)
4 24
Now, L3 (3) = 31.
Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods
Lagrange Interpolation
17

Problem
If y1 = 4, y3 = 12, y4 = 19 and yx = 17, find x.

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Lagrange Interpolation
18

Solution. Using the inverse interpolation formula:

(y − 12)(y − 19) (y − 4)(y − 19) (y − 4)(y − 12)


x= (1) + (3) + (4)
(4 − 12)(4 − 19) (12 − 4)(12 − 19) (19 − 4)(19 − 12)

So, for yx = 7, we have

(7 − 12)(7 − 19) (7 − 4)(7 − 19) (7 − 4)(7 − 12)


x= (1) + (3) + (4)
(4 − 12)(4 − 19) (12 − 4)(12 − 19) (19 − 4)(19 − 12)
(−5)(−12) (3)(−12) (3)(−5)
= (1) + (3) + (4)
(−8)(−15) (8)(−7) (15)(7)
= 1.86

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Lagrange Interpolation
19

Problem
√ √
From the given table of square-roots, calculate 151 and 155, by Lagrange
interpolation formula:
x√ 150 152 154 156
y= x 12.247 12.329 12.410 12.490

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Lagrange Interpolation
20

Problem
From the given table of values, calculate f(0.35) and f(0.65) by Lagrange
Interpolation formula
x 0.30 0.40 0.50
f(x) −1.203973 −0.916291 −0.693147
0.60 0.70
−0.510826 −0.356675

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Lagrange Interpolation
21

Few Observations
I The arguments xi , i = 0, 1, . . . , n, need not be equispaced points in a
table; i.e., it is valid and useful for unequal intervals.
I The degree n of the approximating polynomial should be small,
preferably 5 or 6 (not higher), otherwise the polynomials may give rise
to oscillations.
I If we want to add one more data point, we have to compute the
polynomial from the beginning. It does not use the polynomial already
computed. That is, yk+1 (x) does not use yk (x) which is already
available.

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Newton’s Divided Difference Interpolation
22

Newton Divided Difference Formula


I We have seen that, in Lagrange interpolation, we cannot use the work
that has already been done if we want to incorporate another data
point in order to improve the accuracy of estimation.
I Therefore, it is necessary to look for some other form of
representation to overcome this drawback.
I Let us consider another form of polynomial known as Newton form,
given by

Pn (x) = a0 + a1 (x − x0 ) + a2 (x − x0 )(x − x1 )
+ . . . + an (x − x0 )(x − x1 ) . . . (x − xn−1 )

I We now need to determine the coefficients a0 , a1 , . . . , an .

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Newton’s Divided Difference Interpolation
23

Newton Divided Difference Formula


I Let us assume that (x0 , y0 ), (x1 , y1 ), . . . , (xn , yn ) are the interpolating
points.
I Then we have

Pn (xk ) = yk , k = 0, 1, 2, . . . , (n − 1).

I Now, at x = x0 , we have

Pn (x0 ) = a0 = y0 .

I Similarly, at x = x1 , we have

Pn (x1 ) = a0 + a1 (x1 − x0 ) = y1 .

I Therefore,
y1 − y0
a1 = .
x1 − x0
Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods
Newton’s Divided Difference Interpolation
24

Newton Divided Difference Formula


I At x = x2 , we have

Pn (x2 ) = a0 + a1 (x2 − x0 ) + a2 (x2 − x0 )(x2 − x1 ) = y2

I Substituting for a0 and a1 and rearranging the terms, we get


y2 −y1 y1 −y0
x2 −x1 − x1 −x0
a2 =
x2 − x0

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Newton’s Divided Difference Interpolation
25

Newton Divided Difference Formula


I Let us define a notation

y[xk ] = yk
y[xk+1 ] − y[xk ]
y[xk , xk+1 ] =
xk+1 − xk
y[xk+1 , xk+2 ] − y[xk , xk+1 ]
y[xk , xk+1 , xk+2 ] =
xk+2 − xk
y[xk+1 , . . . , xi+1 ] − y[xk , . . . , xi ]
y[xk , xk+1 , . . . , xi , xi+1 ] =
xi+1 − xk
I These quantities are called divided differences.

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Newton’s Divided Difference Interpolation
26

Newton Divided Difference Formula


I Now, we can express the coefficients ai in terms of these divided
differences.

a0 = y0 = y[x0 ]
y1 − y0
a1 = = y[x0 , x1 ]
x1 − x0
y2 −y1
− yx11 −y 0

a2 = x2 −x1 −x0
x2 − x0
y[x1 , x2 ] − y[x0 , x1 ]
=
x2 − x0
= y[x0 , x1 , x2 ]

I Thus,
an = y[x0 , x1 , . . . , xn ].

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Newton’s Divided Difference Interpolation
27

Newton Divided Difference Formula


I Here a1 represents the first divided difference and a2 the second
divided difference and so on.
I Substituting for ai in the first equation ,we get

Pn (x) = y[x0 ] + y[x0 , x1 ](x − x0 ) + y[x0 , x1 , x2 ](x − x0 )(x − x1 )


+ ...
+ y[x0 , x1 , . . . , xn ](x − x0 )(x − x1 ) . . . (x − xn−1 )

I The above can be written in a compact form as

n (i−1)
X Y
Pn (x) = y[x0 , x1 , . . . , xi ] (x − xj )
i=0 j=0

I The above equation is called Newton’s Divided Difference Interpolation


Polynomial.
Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods
Newton’s Divided Difference Interpolation
28

Divided Difference Table


I We can obtain recursively a higher-order divided difference, starting from the
first-order difference.
I Below we present this in a tabular format which is known as divided difference
table.

i xi yi = f[xi ] First Second Third Fourth


Difference Difference Difference Difference
0 x0 y0 = f[x0 ]
f[x0 , x1 ]
1 x1 y1 = f[x1 ] f[x0 , x1 , x2 ]
f[x1 , x2 ] f[x0 , x1 , x2 , x3 ]
2 x2 y2 = f[x2 ] f[x1 , x2 , x3 ] f[x0 , x1 , x2 , x3 , x4 ]
f[x2 , x3 ] f[x1 , x2 , x3 , x4 ]
3 x3 y3 = f[x3 ] f[x2 , x3 , x4 ]
f[x3 , x4 ]
4 x4 y4 = f[x4 ]

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Newton’s Divided Difference Interpolation
29

Problem
Given below is a table of data for log x. Estimate log 2.5 using second order
Newton interpolation polynomial.
i 0 1 2 3
xi 1 2 3 4
log xi 0 0.3010 0.4771 0.6021
Hint: Second order polynomial require only three data points. Use the first
three points and find a0 , a1 and a2 .

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Cubic Spline Interpolation
30

Splines
I So far we have discussed how an interpolation polynomial of degree n
can be constructed and used if a set of values of function are given.
I There are situations in which this approach is likely to face problems
and produced incorrect estimates.
I This is because the interpolation takes a global rather than a local view
of data.
I It has been proved that when n is large compared to the order of the
“true" function, the interpolation polynomial of degree n does not
provide accurate results at the end of the range.
I Thus, increasing the order of polynomials does not necessarily increase
the accuracy.

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Cubic Spline Interpolation
31

Splines
I To overcome this problem, one can divide the entire range into
subintervals and use local low-order polynomials to interpolate each
subinterval.
I These local polynomials are called piecewise polynomials, which are
continuous in the subinterval and discontinuous at the interpolating
points.
I We can construct piecewise polynomials such that they are continuous
at the interpolating points also.
I This type of polynomials are called Spline polynomials.
I The concept of splines originated from the mechanical drafting tool
called “spline" used by designers for drawing smooth curves.
I The connection points are called knots or nodes.

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Cubic Spline Interpolation
32

Definition
Spline function A spline function of degree n over the interval [x0 , xn ] with
knots (nodes) xi , i = 0, 1, 2, . . . , n is a function S(x) with the properties:
(i) si (x) is a polynomial of degree at most n in each of the subintervals
[xi−1 , xi ], 1 ≤ i ≤ n.
(ii) si (x) and its derivatives of orders 1, 2, . . . , n − 1 are continuous on
[x0 , xn ].
The set of all polynomials form a spline interpolating polynomial if
si (xi ) = f(xi ), for i = 0, 1, 2, . . . , n. The process of constructing such
polynomials for a given set of function points is known as spline
interpolation.

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Cubic Spline Interpolation
33

Definition
Cubic Splines A Cubic spline interpolating polynomial over the interval
[x0 , xn ] with knots (nodes) xi , i = 0, 1, 2, . . . , n is a function S(x) with the
properties:
(i) si (x) is almost a cubic in each of the subintervals [xi−1 , xi ], 1 ≤ i ≤ n.
(ii) si (xi ) = yi = f(xi ), i = 0, 1, 2, . . . , n.
(iii) si (x), s0i (x) and s00i (x) are continuous on [x0 , xn ], and
(iv) s00i (x0 ) = s00i (xn ) = 0.

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Cubic Spline Interpolation
34

To derive the governing equations of the cubic spline, we observe that the
spline second derivatives must be linear. Hence we have in [xi−1 , xi ]:
1
s00i (x) = [(xi − x)Mi−1 + (x − xi−1 )Mi ]
hi

where hi = xi − xi−1 and s00i (xi ) = Mi for all i.


Now, integrating the above twice with respect to x, we obtain

1 (xi − x)3 (x − xi−1 )3


 
si (x) = Mi−1 + Mi + ci (xi − x) + di (x − xi−1 )
hi 6 6

The constants ci and di can be determined by using the conditions


si (xi−1 ) = f(xi−1 ) = yi−1 and si (xi ) = f(xi ) = yi . Mi ’s can obtained by using
continuity condition of s0i (x).

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Cubic Spline Interpolation
35

Cubic Splines
The cubic spline interpolating polynomial si (x) in the interval [xi−1 , xi ] is
given by
1
si (x) = [(xi − x)3 Mi−1 + (x − xi−1 )3 Mi ]
6hi
h2
 
1
+ fi−1 − i Mi−1 (xi − x)
hi 6
h2i
 
1
+ fi − Mi (x − xi−1 )
hi 6

The Mi ’s can be found from the following relations:


 
fi+1 − fi fi − fi−1
hi Mi−1 + 2(hi + hi+1 )Mi + hi+1 Mi+1 = 6 −
hi+1 hi

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Cubic Spline Interpolation
36

Cubic Splines
For equal intervals, hi = hi+1 = h and hence the above equations reduces
to:
1
si (x) = [(xi − x)3 Mi−1 + (x − xi−1 )3 Mi ]
6h 
h2

1
+ fi−1 − Mi−1 (xi − x)
h 6
h2
 
1
+ fi − Mi (x − xi−1 ) (3)
h 6

and
6
Mi−1 + 4Mi + Mi+1 = (fi+1 − 2fi + fi−1 ) (4)
h2
(Here Mi = s00 (xi )).

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Cubic Spline Interpolation
37

Determining Mi ’s
Finally, we have a system of n − 1 linear equations in n + 1 unknowns
M0 , M1 , M2 , . . . , Mn . Therefore to solve this system, we require two
additive conditions, which may be taken in one of the following forms:
(i) M0 = Mn = 0 (A spline satisfying these conditions is called a natural
spline).
(ii) M0 = Mn , M1 = Mn+1 , f0 = fn+1 , h1 = hn+1 (A spline satisfying these
conditions is called a periodic spline).
(iii) For a non-periodic spline, we take the conditions:
s0i (a) = f 0 (a) = f00 ; s0i (b) = f 0 (b) = fn0

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Cubic Spline Interpolation
38

Problem
Obtain the cubic spline approximation for the function given in the tabular
form:
x 0 1 2 3
f(x) 1 2 33 244
and M0 = M3 = 0.

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Cubic Spline Interpolation
39

Solution. Since n = 4, we have three intervals and three cubics and,


therefore only M1 , M2 are to be determined.
Case (i):

i = 1, h = 1 =⇒ M0 + 4M1 + M2 = 6(f2 − 2f1 + f0 ) (1)

Case (ii):

i = 2, h = 1 =⇒ M1 + 4M2 + M3 = 6(f3 − 2f2 + f1 ) (2)

Since M0 = M3 = 0, from (5) and (6) we have

4M1 + M2 = 6(33 − 2 × 2 + 1) = 180 (3)


M1 + 4M2 = 6(244 − 2 × 33 + 2) = 1080 (4)

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Cubic Spline Interpolation
40

Solving the above two equations we obtain M1 = −24 and M2 = 276.


Now in the interval [0, 1] we have i = 1, h = 1 and required cubic spline is:
1  1 
s1 (x) = [(x1 − x)3 M0 + (x − x0 )3 M1 ] + 1 × (x1 − x) f0 − M0
6 6
 1 
+ 1 × (x − x0 ) f1 − M1
6
1 3
 24 
= [(x − 0) (−24)] + (1 − x)(1 − 0) + (x − 0) 2 +
6 6
= −4x3 + 5x + 1.

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Cubic Spline Interpolation
41

Now in the interval [1, 2] we have i = 2, h = 1 and required cubic spline is:
1  1 
s2 (x) = [(x2 − x)3 M1 + (x − x1 )3 M2 ] + 1 × (x2 − x) f1 − M1
6 6
 1 
+ 1 × (x − x1 ) f2 − M2
6
1  24 
= [(2 − x) (−24) + (x − 1)3 (276)] + (2 − x) 2 +
3
6   6
276
+ (x − 1) 33 −
6
= 50x3 − 162x2 + 167x − 53.

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Cubic Spline Interpolation
42

Finally, in the interval [2, 3] we have i = 3, h = 1 and required cubic spline is:
1  1 
s3 (x) = [(x3 − x)3 M2 + (x − x2 )3 M3 ] + 1 × (x3 − x) f2 − M2
6 6
 1 
+ 1 × (x − x2 ) f3 − M3
6  
1 3 276
= [(3 − x) (276)] + (3 − x) 33 − + (x − 2)(244)
6 6
= −46x3 + 414x2 − 985x + 715.

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Cubic Spline Interpolation
43

Problem
Given the table of values
i 0 1 2 3
xi 1 2 3 4
f(x) 0.5 0.3333 0.25 0.20

estimate the value of f(2.5) and f(3.5) using cubic spline interpolation.

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Cubic Spline Interpolation
44

Solution. The points are equally spaced and hence h = 1. Since n = 4, we


have three intervals and three cubics and, therefore only M1 , M2 are to be
determined.
Case (i):

i = 1, h = 1 =⇒ M0 + 4M1 + M2 = 6(f2 − 2f1 + f0 ) (5)

Case (ii):

i = 2, h = 1 =⇒ M1 + 4M2 + M3 = 6(f3 − 2f2 + f1 ) (6)

Since M0 = M3 = 0, from (5) and (6) we have

4M1 + M2 = 6(0.25 − 2 × 0.3333 + 0.5) = 0.5004 (7)


M1 + 4M2 = 6(0.2 − 2 × 0.25 + 0.3333) = 0.1998 (8)

Solving the above two equations we obtain M1 = 0.1201 and M2 = 0.0199.

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Cubic Spline Interpolation
45

Now the target point x = 2.5 lies in the domain of s2 (x).


1
s2 (x) = [(x2 − x)3 M1 + (x − x1 )3 M2 ]
6  1   1 
+ 1(x2 − x) f1 − M1 + 1(x − x1 ) f2 − M2
6 6
1 3 3
= [(3 − x) (0.1201) + (x − 2) (0.0199)]
6  0.1201 
+ (3 − x) 0.3333 −
6
 0.0199 
+ (x − 2) 0.25 −
6
Now s2 (2.5) = 0.2829.

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods


Cubic Spline Interpolation
46

Now the target point x = 3.5 lies in the domain of s3 (x).


1
s3 (x) = [(x3 − x)3 M2 + (x − x2 )3 M3 ]
6  1   1 
+ 1(x3 − x) f2 − M2 + 1(x − x2 ) f3 − M3
6 6
1 3
= [(4 − x) (0.0199)]
6  0.0199 
+ (4 − x) 0.25 − + (x − 3)(0.20)
6
Now s3 (3.5) = 0.2238.

Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods

You might also like