0% found this document useful (0 votes)
57 views

Cubic Spline Interpolation: J. R. Shrestha

The document discusses cubic spline interpolation, which uses piecewise cubic functions to interpolate data points. Cubic spline interpolation produces a smooth curve with good numerical accuracy between data points. It involves developing cubic equations between each pair of data points such that the first and second derivatives are continuous at the points. The second derivatives at each point can be determined by solving a tridiagonal system of equations. This allows the cubic spline to be evaluated to obtain interpolated values within the intervals between given data points.

Uploaded by

Sashank Gaudel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views

Cubic Spline Interpolation: J. R. Shrestha

The document discusses cubic spline interpolation, which uses piecewise cubic functions to interpolate data points. Cubic spline interpolation produces a smooth curve with good numerical accuracy between data points. It involves developing cubic equations between each pair of data points such that the first and second derivatives are continuous at the points. The second derivatives at each point can be determined by solving a tridiagonal system of equations. This allows the cubic spline to be evaluated to obtain interpolated values within the intervals between given data points.

Uploaded by

Sashank Gaudel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Cubic Spline Interpolation

J. R. Shrestha

Institute of Engineering

January 2018
Linear Interpolation

Good numerical approximation.


But the curve doesn’t look smooth
(discontinuous at the data points).
1 / 10
Polynomial Interpolation

The curve looks smooth.


But very bad numerical approximation between some of the intervals
(Usually end points ⇒ not necessarily always).
2 / 10
Cubic Spline Interpolation

Piece-wise cubic equations with continuous 1st & 2nd derivatives at


the knots (data points).
Smooth-looking graph with very good numerical results.
3 / 10
Given n+ 1 data points (xi , yi ) for i = 0 . . . n
Develop n cubic equations between (xi , yi ) and (xi+1 , yi+1 ) for
i = 0 . . . 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) =

 ... ... ...
fn−1,n (x) for xn−1 ≤ x ≤ xn

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

On solving, we get, M1 = 1.5804 M2 = −0.3214 M3 = −1.7946


8 / 10
Thus We now have,
i 0 1 2 3 4
x 2 4 6 8 10
y 7 6 9 11 8
M 0 1.5804 -0.3214 -1.7946 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
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

1 Continue with the example: find y(3), y(7), and y(9).

2 Using Cubic Spline Interpolation, compute y(12), y(15), y(25), and


y(27) from the following data:
x 10 14 20 26 30
y 32 31 25 30 29
[Note that the values of x are not equally spaced.]

3 Fit the following data to a set of Natural Cublic Splines.


x 5 10 15 20
y 30 35 40 32

10 / 10

You might also like