You are on page 1of 14

MATH174 Numerical Analysis I

Cubic Splines

First Semester, AY 2023-2024

MATH174 Numerical Analysis I First Semester, AY 2023-2024 1 / 14


A cubic spline through the points {(xk , yk )}nk=0 is a function S(x) and a
n−1
set of n − 1 equations {Sk (x)}k=0 with coefficients sk,0 , sk,1 , sk,2 and sk,3
that satisfy the following properties:
Sk (x) = sk,0 + sk,1 (x − xk ) + sk,2 (x − xk )2 + sk,3 (x − xk )3 for
x ∈ [xk , xk+1 ] and k = 0, 1, . . . , n − 1.
S(xk ) = yk for k = 0, 1, . . . , n.
Sk (xk+1 ) = Sk+1 (xk+1 ) for k = 0, 1, . . . , n − 2.
Sk′ (xk+1 ) = Sk+1
′ (xk+1 ) for k = 0, 1, . . . , n − 2.
′′ ′′
Sk (xk+1 ) = Sk+1 (xk+1 ) for k = 0, 1, . . . , n − 2.

MATH174 Numerical Analysis I First Semester, AY 2023-2024 2 / 14


Since S(x) is piecewise cubic, its second derivative S ′′ (x) is piecewise
linear on [x0 , xn ]. Using the Lagrange interpolation formula:
x − xk+1 x − xk
Sk′′ (x) = Sk′′ (xk ) + Sk′′ (xk+1 ) . (1)
xk − xk+1 xk+1 − xk

Let mk = S ′′ (xk ), mk+1 = S ′′ (xk+1 ), and hk = xk+1 − xk in (1) to get


mk mk+1
Sk′′ (x) = (xk+1 − x) + (x − xk ) (2)
hk hk

for x ∈ [xk , xk+1 ] and k = 0, 1, . . . , n − 1.

MATH174 Numerical Analysis I First Semester, AY 2023-2024 3 / 14


Integrating (2) twice, we have
mk mk+1
Sk (x) = (xk+1 −x)3 + (x −xk )3 +pk (xk+1 −x)+qk (x −xk ). (3)
6hk 6hk

Using the property that yk = Sk (xk ) and yk+1 = Sk (xk+1 ), yields the
following equations:
mk 2 mk+1 2
yk = hk + pk hk and yk+1 = hk + qk hk . (4)
6 6
Solving for pk and qk and substituting these values to (3),
mk mk+1
Sk (x) = − (xk+1 − x)3 + (x − xk )3
6hk 6hk
   
yk mk hk yk+1 mk+1 hk
+ − (xk+1 − x) + − (x − xk ).
hk 6 hk 6
(5)

MATH174 Numerical Analysis I First Semester, AY 2023-2024 4 / 14


Notice that (5) is an equation that only involves mk . To solve for mk , we
use the derivative of (5),
mk mk+1
Sk′ (x) = − (xk+1 − x)2 + (x − xk )2
2hk 2hk

yk m k hk

yk+1 mk+1 hk (6)
− − + − .
hk 6 hk hk

Evaluating (6) at xk , we have


mk mk+1 yk+1 − yk
Sk′ (xk ) = − hk − hk + dk , where dk = . (7)
3 6 h+k

MATH174 Numerical Analysis I First Semester, AY 2023-2024 5 / 14


Similarly,
′ mk mk−1
Sk−1 (xk ) = hk−1 + hk−1 + dk−1 . (8)
3 6
Using property 4 and equations (7) and (8) to obtain:

hk−1 mk−1 + 2(hk−1 + hk )mk + hk mk+1 = uk , (9)

where uk = 6(dk − dk−1 ) for k = 1, . . . , n − 1. If m0 is given, then h0 m0


can be computed, and the first equation (when k = 1) of (9) is

2(h0 + h1 )m1 + h1 m2 = u1 − h0 m0 . (10)

MATH174 Numerical Analysis I First Semester, AY 2023-2024 6 / 14


If mn is given, then hn−1 mn can be computed, and the last equation (when
k = n − 1) of (9) is

hn−2 mn−2 + 2(hn−2 + hn−1 )mn−1 = un−1 − hn−1 mn . (11)

Equations (10) and (11) with (9) for k = 2, . . . , n − 2 form n − 1 equations


involving m1 , . . . , mn−1 .

MATH174 Numerical Analysis I First Semester, AY 2023-2024 7 / 14


Endpoint Constraints for a Cubic Spline

Clamped Cubic Spline


Specify S ′ (a) = d0 & S ′ (b) = dn with additional equations:
 
3
h0 + 2h1 m1 + h1 m2 = u1 − 3(d0 − S ′ (x0 ))
2
 
3
hn−2 mn−2 + 2hn−2 + hn−1 mn−1 = un−1 − 3(S ′ (xn ) − dn−1 )
2

MATH174 Numerical Analysis I First Semester, AY 2023-2024 8 / 14


Natural Spline
Specify S ′′ (a) = 0 and S ′′ (b) = 0 with additional equations:

2(h0 + h1 )m1 + h1 m2 = u1
hn−2 mn−2 + 2(hn−2 + hn−1 )mn−1 = un−1

MATH174 Numerical Analysis I First Semester, AY 2023-2024 9 / 14


Extrapolated Spline
Extrapolate S ′′ (a) from x1 and x2 and S ′′ (b) from xn−1 and xn−2 with
additional equations:

h02 h02
   
3h0 + 2h1 + m1 + h1 − m2 = u1
h1 h1
! !
2
hn−1 2
hn−1
hn−2 − mn−2 + 2hn−2 + 3hn−1 + mn−1 = un−1
hn−2 hn−2

MATH174 Numerical Analysis I First Semester, AY 2023-2024 10 / 14


Parabolically Terminated Spline
S ′′′ (x) ≡ 0 on [x0 , x1 ] and S ′′′ (x) ≡ 0 on [xn−1 , xn ] with additional equa-
tions:

(3h0 + 2h1 )m1 + h1 m2 = u1


hn−2 mn−2 + (2hn−2 + 3hn−1 )mn−1 = un−1

MATH174 Numerical Analysis I First Semester, AY 2023-2024 11 / 14


Endpoint Curvature-Adjusted Spline
S ′′ (a) and S ′′ (b) are specified to some value with additional equations:

2(h0 + h1 )m1 + h1 m2 = u1 − h0 S ′′ (x0 )


hn−2 mn−2 + 2(hn−2 + hn−1 )mn−1 = un−1 − hn−1 S ′′ (xn )

MATH174 Numerical Analysis I First Semester, AY 2023-2024 12 / 14


The coefficients of the cubic splines can now be determined using the for-
mulas
hk (2mk + mk+1 )
sk,0 = yk , sk,1 = dk − ,
6 (12)
mk mk+1 − mk
sk,2 = , sk,3 = .
2 6hk

MATH174 Numerical Analysis I First Semester, AY 2023-2024 13 / 14


Theorem (Minimum Property of Cubic Splines):
Assume that f ∈ C 2 [a, b] and S(x) is the unique cubic spline interpolant for
f (x) that passes through the points {(xk , yk )}nk=0 and satisfies the clamped
end conditions S ′ (a) = f ′ (a) and S ′ (b) = f ′ (b). Then
Z b Z b
(S ′′ (x))2 dx ≤ (f ′′ (x))2 dx.
a a

MATH174 Numerical Analysis I First Semester, AY 2023-2024 14 / 14

You might also like