Cubic Spline Interpolation: J. R. Shrestha
Cubic Spline Interpolation: J. R. Shrestha
Cubic Spline Interpolation: J. R. Shrestha
J. R. Shrestha
Institute of Engineering
January 2018
Linear Interpolation
Given by:
(x − xi+1 )3
Mi
fi,i+1 (x) = hi (x − xi+1 ) −
6 hi
(x − xi )3
Mi+1
− 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 4 / 10
To find the second derivatives (for i = 1 to n − 1):
Mi−1 (xi − xi−1 ) + 2Mi (xi+1 − xi−1 ) + Mi+1 (xi+1 − xi )
yi+1 − yi yi − yi−1
=6 −
xi+1 − xi xi − xi−1
or,
∆yi ∆yi−1
Mi−1 (hi−1 ) + 2Mi (hi−1 + hi ) + Mi+1 (hi ) = 6 −
hi hi−1
If n = 4:
∆y1 ∆y0
For i = 1 : M0 (h0 ) + 2M1 (h0 + h1 ) + M2 (h1 ) = 6 −
h1 h0
∆y2 ∆y1
For i = 2 : M1 (h1 ) + 2M2 (h1 + h2 ) + M3 (h2 ) = 6 −
h2 h1
∆y3 ∆y2
For i = 3 : M2 (h2 ) + 2M3 (h2 + h3 ) + M4 (h3 ) = 6 −
h3 h2
5 / 10
In matrix form:
M0
∆y1 ∆y0
−
h0 2(h0 +h1 ) h1 0 0 M1 h1 h0
∆y2 ∆y1
0 h1 2(h1 +h2 ) h2 0 M2 = 6 −
h2 h1
0 0 h2 2(h2 +h3 ) h3 M3 ∆y3 ∆y2
h3 − h2
M4
If x is equally spaced:
M0
∆y1 −∆y0
h 2(2h) h 0 0 M1
h
∆y2 −∆y1
0 h 2(2h) h 0 M2 = 6
h
0 0 h 2(2h) h M3 ∆y3 −∆y2
h
M4
M0
2
1 4 1 0
0 M1
∆ y0
6 ∆2 y 1
or, 0 1 4 1 M2
0 =
h2
0 0 1 1 M3
4 ∆2 y 2
M4
In Natural Cubic Spline, M0 = Mn = 0
2
4 1 0 M1 ∆ y
1 4 1 M2 = 6 2 0
∆ y1
h2 6 / 10
Example
Using Cubic Spline Interpolation Technique, compute y(3), y(5), y(7), and
y(9) from the following data:
x 2 4 6 8 10
y 7 6 9 11 8
Solution:
Here, n = 4
h = 2 (Equally spaced interval)
Let M0 , M1 , ..., M4 be the 2nd derivatives at x = x0 , x1 , ..., x4
Thus, we have,
M0 2
1 4 1 0 0 M 1
∆ y0
0 1 4 1 0 M 2 = 6 ∆ 2 y1
h2
0 0 1 4 1 M3 ∆ 2 y2
M4
7 / 10
In Natural Cubic Spline, M0 = Mn = 0
So, the system reduces to:
∆2 y
2
x y ∆y
4 1 0 M1 ∆ y0
1 4 1 M2 = 6 ∆2 y1 2 7
h2
0 1 4 M3 ∆2 y2 -1
4 6 4
3
4 1 0 M1 4 6 9 -1
6
or, 1 4 1 M2 = −1 2
4
0 1 4 M3 −5 8 11 -5
-3
10 8
4 1 0 M1 6.0
or, 1 4 1 M2 = −1.5
0 1 4 M3 −7.5
(x − x2 )3
M1
f1,2 (x) = h(x − x2 ) −
6 h
(x − x1 )3
M2 y2 (x − x1 ) − y1 (x − x2 )
− h(x − x1 ) − +
6 h h
(5 − 6)3
1.5804
∴ f (5) = 2(5 − 6) −
6 2
(5 − 4)3
−0.3214 9(5 − 4) − 6(5 − 6)
− 2(5 − 4) − +
6 2 2
= 7.1839 9 / 10
Assignments
10 / 10