Professional Documents
Culture Documents
Cubic Spline Interpolation: MATH 375, Numerical Analysis
Cubic Spline Interpolation: MATH 375, Numerical Analysis
Cubic Spline Interpolation: MATH 375, Numerical Analysis
J. Robert Buchanan
Department of Mathematics
Fall 2013
x
4 5 6 7 8 9 10
5 = S0 (5) = a0
2 = S0 (7) = a0 + 2b0 + 4c0 + 8d0
2 = S1 (7) = a1
4 = S1 (9) = a1 + 2b1 + 4c1 + 8d1
5 = a0
2 = a0 + 2b0 + 4c0 + 8d0
2 = a1
4 = a1 + 2b1 + 4c1 + 8d1
0 = b0 + 4c0 + 12d0 − b1
0 = 2c0 + 12d0 − 2c1
0 = 2c0
0 = 2c1 + 12d1
17 5
0 5 − 0
8 32
1 15 5
1 2 − −
4 16 32
x
4 5 6 7 8 9 10
1.5
1.5
1.0
0.5
1.0
x
6 7 8 9
-0.5
-1.0 0.5
-1.5
-2.0 x
6 7 8 9
Sj (x) = aj + bj (x − xj ) + cj (x − xj )2 + dj (x − xj )3 .
Sj (xj ) = aj = f (xj )
Sj+1 (xj+1 ) = aj+1 = Sj (xj+1 ) = aj + bj hj + cj hj2 + dj hj3 .
a1 = a0 + b0 h0 + c0 h02 + d0 h03
..
.
aj+1 = aj + bj hj + cj hj2 + dj hj3
..
.
2 3
an = an−1 + bn−1 hn−1 + cn−1 hn−1 + dn−1 hn−1
Thus
Sj0 (xj ) = bj
0
Sj+1 (xj+1 ) = bj+1 = Sj0 (xj+1 ) = bj + 2cj hj + 3dj hj2
Thus
For j = 0, 1, . . . , n − 1 we have
For j = 0, 1, . . . , n − 1 we have
cj+1 − cj
aj+1 = aj + bj hj + cj hj2 + hj3
3hj
hj2
= aj + bj hj + (2cj + cj+1 )
3
cj+1 − cj
bj+1 = bj + 2cj hj + 3 hj2
3hj
= bj + hj (cj + cj+1 )
cj+1 − cj
aj+1 = aj + bj hj + cj hj2 + hj3
3hj
hj2
= aj + bj hj + (2cj + cj+1 )
3
cj+1 − cj
bj+1 = bj + 2cj hj + 3 hj2
3hj
= bj + hj (cj + cj+1 )
1 hj
bj = (aj+1 − aj ) − (2cj + cj+1 )
hj 3
1 hj−1
bj−1 = (aj − aj−1 ) − (2cj−1 + cj ).
hj−1 3
1 hj−1
bj−1 = (aj − aj−1 ) − (2cj−1 + cj ).
hj−1 3
to obtain
bj = bj−1 + hj−1 (cj−1 + cj ).
Substitute the equations for bj−1 and bj into the remaining
equation. This step eliminate n equations of the first type.
1 hj
(aj+1 − aj ) − (2cj + cj+1 )
hj 3
1 hj−1
= (aj − aj−1 ) − (2cj−1 + cj ) + hj−1 (cj−1 + cj )
hj−1 3
3 3
hj−1 cj−1 +2cj (hj−1 +hj )+hj cj+1 = (aj+1 −aj )− (aj −aj−1 )
hj hj−1
for j = 1, 2, . . . , n − 1.
1 hj
(aj+1 − aj ) − (2cj + cj+1 )
hj 3
1 hj−1
= (aj − aj−1 ) − (2cj−1 + cj ) + hj−1 (cj−1 + cj )
hj−1 3
3 3
hj−1 cj−1 +2cj (hj−1 +hj )+hj cj+1 = (aj+1 −aj )− (aj −aj−1 )
hj hj−1
for j = 1, 2, . . . , n − 1.
Remark: we have n − 1 equations and n + 1 unknowns.
Theorem
If f is defined at a = x0 < x1 < · · · < xn = b then f has a unique
natural cubic spline interpolant.
c0
0
3 3
c1 h1 (a2 − a1 ) − h0 (a1 − a0 )
3 3
c2 h2 (a3 − a2 ) − h1 (a2 − a1 )
A =
.. ..
. .
cn−1 3 3
− a − hn−2 (an−1 − an−2 )
hn−1 (a n n−1 )
cn 0
x f (x)
−1.0 0.86199480
−0.5 0.95802009
0.0 1.0986123
0.5 1.2943767
h0 = h1 = h2 = 0.5
with
a0 = 0.86199480, a1 = 0.95802009,
a2 = 1.0986123, a3 = 1.2943767.
y
1.3
1.2
1.1
1.0
x
-1.0 -0.8 -0.6 -0.4 -0.2 0.2 0.4
1 h0
f 0 (a) = (a1 − a0 ) − (2c0 + c1 )
h0 3
which is equivalent to
3
h0 (2c0 + c1 ) = (a1 − a0 ) − 3f 0 (a).
h0
which is equivalent to
3
hn−1 (cn−1 + 2cn ) = 3f 0 (b) − (an − an−1 ).
hn−1
Theorem
If f is defined at a = x0 < x1 < · · · < xn = b and differentiable at
x = a and at x = b, then f has a unique clamped cubic spline
interpolant.
3
c0
− a0 ) − 3f 0 (a)
h0 (a1
3 3
h1 (a2 − a1 ) − h0 (a1 − a0 )
c1
3 3
c2 h2 (a3 − a2 ) − h1 (a2 − a1 )
A =
.. ..
.
.
cn−1 3 3
hn−1 (an − an−1 ) − hn−2 (an−1 − an−2 )
cn 3
3f 0 (b) − hn−1 (an − an−1 )
1 hj
bj = (aj+1 − aj ) − (cj+1 + 2cj )
hj 3
1
dj = (cj+1 − cj )
3hj
for j = 0, 1, . . . , n − 1.
INPUT {(x0 , f (x0 )), (x1 , f (x1 )), . . . , (xn , f (xn ))}, f 0 (x0 ), and
f 0 (xn ).
STEP 1 For i = 0, 1, . . . , n − 1 set ai = f (xi ); set
hi = xi+1 − xi .
3(a1 − a0 )
STEP 2 Set α0 = − 3f 0 (x0 );
h0
3(an − an−1 )
αn = 3f 0 (xn ) − .
hn−1
STEP 3 For i = 1, 2, . . . , n − 1 set
3 3
αi = (ai+1 − ai ) − (ai − ai−1 ).
hi hi−1
α0
STEP 4 Set l0 = 2h0 ; µ0 = 0.5; z0 = .
l0
x f (x)
−1.0 0.86199480
−0.5 0.95802009
0.0 1.0986123
0.5 1.2943767
h0 = h1 = h2 = 0.5
with
a0 = 0.86199480, a1 = 0.95802009,
a2 = 1.0986123, a3 = 1.2943767.
0.861995 + 0.155362(x + 1)
+ 0.0653748(x + 1)2
if −1 ≤ x ≤ −0.5
3
+ 0.0160031(x + 1)
0.95802 + 0.23274(x + 0.5)
S(x) =
+ 0.0893795(x + 0.5)2 if −0.5 ≤ x ≤ 0
+ 0.0150207(x + 0.5) 3
+ 0.333384x + 0.11191x 2 if 0 ≤ x ≤ 0.5
1.09861
+ 0.00875717x 3
y
1.3
1.2
1.1
1.0
x
-1.0 -0.8 -0.6 -0.4 -0.2 0.2 0.4
Theorem
(4)
Let f ∈ C 4 [a, b] with max f (x) = M. If S is the unique
a≤x≤b
clamped cubic spline interpolant to f with respect to nodes
a = x0 < x1 < · · · < xn = b, then for all x ∈ [a, b],
5M
|f (x) − S(x)| ≤ max (xj+1 − xj )4 .
384 0≤j≤n−1
x f (x)
−0.5 −0.02475
−0.25 0.334938
0.0 1.101
Ac = y
1.00 0.00 0.00 c0 0.00
0.25 1.00 0.25 c1 = 4.8765
0.00 0.00 1.00 c2 0.00
fHxL
0.8
0.6
0.4
0.2
x
-0.5 -0.4 -0.3 -0.2 -0.1
x f (x)
0.0 1.0
5.0 0.0904053
10.0 −0.310045
.. ..
. .
50.0 0.299655
ai bi ci di
1 −0.25 0.0154655 −0.00036986
0.09040533 −0.1230843 0.009917643 −0.0002637577
−0.3100448 −0.0436897 0.005961278 −0.0001836499
−0.4024176 0.00214934 0.003206529 −0.0001229411
−0.3268753 0.02499404 0.001362412 −0.0000780158
−0.1775968 0.03276697 0.000192174 −0.0000454083
−0.0146336 0.03128308 −0.00048895 −0.0000224102
0.12675676 0.02471281 −0.00082510 −6.79522 × 10−6
0.22884382 0.01595213 −0.00092703 3.265389 × 10−6
0.28583684 0.00692671 −0.00087805 9.088463 × 10−6
y
1.0
0.8
0.6
0.4
0.2
x
10 20 30 40 50
-0.2
-0.4