You are on page 1of 12

Cubic Spline Interpolation

B. D. Mulmi
Institute of Engineering

Feb, 2016

Linear Interpolation

Polynomial Interpolation

Cubic Spline Interpolation

Polynomial Interpolation is not always bad!

Given n+1 data points (xi , yi ) for i = 0 to n, develop n cubic


equations between (xi , yi ) and (xi+1 , yi+1 ) for i = 0 to n 1, such
that the 1st and 2nd derivatives at common points are continuous.

f0,1 (x)
for
x0 x x1

f1,2 (x)
for
x1 x x2
f (x) =
...
...
...

fn1,n (x) for xn1 x xn


Given by:


Mi
(x xi+1 )3
fi,i+1 (x) =
hi (x xi+1 )
6
hi


Mi+1
(x xi )3

hi (x xi )
6
hi
yi+1 (x xi ) yi (x xi+1 )
+
hi
Where, Mi = yi00

00
Mi+1 = yi+1

hi = xi+1 xi

To find the second derivatives (for i = 1 to n 1):


Mi1 (xi xi1 ) + 2Mi (xi+1 xi1 ) + Mi+1 (xi+1 xi )


yi+1 yi
yi yi1
=6

xi+1 xi xi xi1
or,


yi yi1

Mi1 (hi1 ) + 2Mi (hi1 + hi ) + Mi+1 (hi ) = 6


hi
hi1

If n = 4:
For i = 1 :

For i = 2 :

For i = 3 :

y1 y0
M0 (h0 ) + 2M1 (h0 + h1 ) + M2 (h1 ) = 6

h1
h0
y2 y1
M1 (h1 ) + 2M2 (h1 + h2 ) + M3 (h2 ) = 6

h2
h1
y3 y2
M2 (h2 ) + 2M3 (h2 + h3 ) + M4 (h3 ) = 6

h3
h2

h0
0
0

2(h0 + h1 )
h1
0
0

h1
2(h1 + h2 )
h2
0

0
h2
2(h2 + h3 ) h3

M0
M1
M2
M3
M4

y1 /h1 y0 /h0
[x1 , x2 ] [x0 , x1 ]
= 6 y2 /h2 y1 /h1 = 6 [x2 , x3 ] [x1 , x2 ]
y3 /h3 y2 /h2
[x3 , x4 ] [x2 , x3 ]
If x is equally spaced:
Mi1 + 4Mi + Mi+1 =

6 2
yi1
h2

If n = 4,
6 2
y0
h2
6
M1 + 4M2 + M3 = 2 2 y1
h
6
M2 + 4M3 + M4 = 2 2 y2
h
M0 + 4M1 + M2 =

or,

1 4 1 0 0

0 1 4 1 0

0 0 1 4 1
In Natural Cubic

4
1
0

M0
M1
M2
M3
M4

y0

6
=
2 y1
h2

2 y2

Spline, M0 = Mn = 0

2
1 0
M1
y0
6
4 1 M2 = 2 2 y 1
h
M3
1 4
2 y2

Example
Using Cubic Spline Interpolation Technique, compute y(3), y(5),
and y(7) from the following data:
x
y

2
7

4
6

6
9

8
11

10
8

Solution:
Here, n = 4
and x is in equally-spaced interval i.e., h = 2
Let, M0 , M1 , ..., Mn be the 2nd derivatives at x = x0 , x1 , ..., xn
Thus, we have,

M0

y0
1 4 1 0 0
M
1

0 1 4 1 0 M2 = 6 2 y 1

h2
2 y2
0 0 1 4 1 M3
M4

In Natural Cubic Spline, M0 = Mn = 0


So, the system of equations reduces to:
2

y0
4 1 0
M1
1 4 1 M2 = 6 2 y 1
h2
2 y2
0 1 4
M3
or,

4 1 0
M1
4
6
1 4 1 M2 = 1
4
0 1 4
M3
5

or,

x
2

y
7

2 y

-1
4
3

6.0
4 1 0
M1
1 4 1 M2 = 1.5
M3
7.5
0 1 4

11

-5
-3

10
On solving, we get,
M1 = 1.5804
M2 = 0.3214

-1
2

M3 = 1.7946

i
x
y
M

0
2
7
0

Thus We now have,


1
2
3
4
6
8
6
9
11
1.5804 -0.3214 -1.7946

4
10
8
0

To compute y(5), i.e., to compute y at x=5:


Since x = 5 lies between x1 and x2 , we compute y(5) using:


(x x2 )3
M1
h(x x2 )
f1,2 (x) =
6
h


M2
(x x1 )3
y2 (x x1 ) y1 (x x2 )

h(x x1 )
+
6
h
h


1.5804
(5 6)3
f (5) =
2(5 6)
6
2


0.3214
(5 4)3
9(5 4) 6(5 6)

2(5 4)
+
6
2
2
= 7.1839

You might also like