Week 7 - Cubic Splines
Week 7 - Cubic Splines
Prof F. Chirove
1 Department of Mathematics and Applied Mathematics, University of
Johannesburg, South Africa
26 August 2024
O UTLINE
1 H ERMITE I NTERPOLATION
Hermite polynomials: Using lagrange polynomials
Hermite interpolation examples
Hermite polynomials: Using Divided differences
O SCULATING POLYNOMIALS
D EFINITION
Osculating polynomial - Let x0 , x1 , · · · , xn be n + 1 distinct
numbers in [a, b]. Also, assume m0 , m1 , · · · , mn are nonnegative
integers where each integer, mi , corresponds with xi . Further
assume f ∈ Cm [a, b] where m = max{mi : 0 ≤ i ≤ n}. The
osculating polynomial that approximates f is the polynomial
P(x) of least degree such that
dk P(xi ) dk f (xi )
= , i = 0, 1, 2, · · · , n and k = 0, 1, 2, · · · , mi .
dxk dxk
The definition says
f (x0 ) = P(x0 ), f 0 (x0 ) = P0 (x0 ), f 00 (x0 ) = P00 (x0 ), .., f (m0 ) (x0 ) = P(m0 ) (x0 ),
f (x1 ) = P(x1 ), f 0 (x1 ) = P0 (x1 ), f 00 (x1 ) = P00 (x1 ), .., f (m1 ) (x1 ) = P(m1 ) (x1 ),
··· = ······ ,
f (xn ) = P(xn ), f 0 (xn ) = P0 (xn ), f 00 (xn ) = P00 (xn ), .., f (mn ) (xn ) = P(mn ) (xn ).
Prof F. Chirove APM2B10
Hermite Interpolation Cubic Spline interpolation Hermite interpolation examples
H ERMITE POLYNOMIALS
D EFINITION
Hermite polynomial - The osculating polynomial of f formed
when m0 = m1 = · · · = mn = 1
- The first derivatives of the hermite polynomials agree with
those of f , and have the same shape as the function at
(xi , f (xi )) in the sense that the tangent lines to the polynomial
and the function agree.
When there is a single point, x0 , the osculating polynomial
approximating f is the Taylor polynomial of mth 0 degree.
When m = 0, for each i, the osculating polynomial is the nth
Lagrange polynomial interpolating f on x0 , x1 , · · · , xn .
The graph of the Hermite polynomial of f agrees with f at
n + 1 distinct points and has the same tangent lines as f at
those n + 1 distinct points.
Prof F. Chirove APM2B10
Hermite Interpolation Cubic Spline interpolation Hermite interpolation examples
where h i
0 (x ) L2 (x),
Hn,j = 1 − 2(x − xj )Ln,j j n,j
2 (x)
Ĥn,j = (x − xj )Ln,j
and Ln,j (x) denoting the jth Lagrange coefficient polynomial of
degree n.
Prof F. Chirove APM2B10
Hermite Interpolation Cubic Spline interpolation Hermite interpolation examples
n
1 Y
2 (2n+2)
|E(x)| ≤ max (x − xj ) max f (x)
(2n + 2)! x0 ≤x≤xn x0 ≤x≤xn
j=0
S OLUTION
Note that we have three points x0 = 0, x1 = 1, x2 = 3 so n = 2
and
(x − 1)(x − 3) 1 4 2 4
L0 = = x2 − x + 1, L00 = x − .
(0 − 1)(0 − 3) 3 3 3 3
x(x − 3) 1 2 3 3
L1 = = − x + x, L10 = −x + .
(1 − 0)(1 − 3) 2 2 2
x(x − 1) 1 2 1 1 1
L2 = = x − x, L20 = x − .
(3 − 0)(3 − 1) 6 6 3 6
H ERMITE POLYNOMIALS
R EMARK
Like the Lagrange form in ordinary interpolation, this form of the
Hermite polynomial is not conducive to efficient computation. A
variation of the Newton approach, including the use of divided
difference tables, can be constructed using Newton
interpolatory divided-difference formula.
n
X
Pn (x) = f [x0 ] + f [x0 , x1 , · · · , xn ](x − x0 ) · · · (x − xk−1 ).
k=1
E XAMPLE
Suppose that
f (0) = 2, f 0 (0) = 1, f (1) = 4, f 0 (1) = −1, f (3) = 5, f 0 (3) = −2.
Find the Hermite interpolating polynomial, Newton’s divided
differences, and use it to approximate the value of f (2).
S OLUTION
Note that we have three points x0 = 0, x1 = 1, x2 = 3 so n = 2.
Thus, z0 = z1 = 0, z2 = z3 = 1, z4 = z5 = 3.
S OLUTION
Observe that
f [z0 ], f [z0 , z1 ], f [z0 , z1 , z2 ], f [z0 , z1 , z2 , z3 ], f [z0 , z1 , z2 , z3 , z4 ] and
f [z0 , z1 , z2 , z3 , z4 , z5 ] correspond to the top diagonal elements of
the table of differences. Hence,
1
F IGURE : Intepolation of f (x) =
1 + 25x2
1
F IGURE : Intepolation of f (x) =
1 + 25x2
h2j
aj+1 = aj + bj hj + (2cj + cj+1 ), (8)
3
bj+1 = bj + hj (cj + cj+1 ). (9)
1 hj
bj = (aj+1 − aj ) − (2cj + cj+1 ). (10)
hj 3
1 hj−1
bj−1 = (aj − aj−1 ) − (2cj−1 + cj ). (11)
hj−1 3
1 hj
bj = (aj+1 − aj ) − (2cj + cj+1 ) (13)
hj 3
cj+1 − cj
dj = . (14)
3hj
a0 + b0 (x − x0 ) + d0 (x − x0 )3 , on [x0 , x1 ],
2
a1 + b1 (x − x1 ) + c1 (x − x1 ) + d1 (x − x1 ) , on [x1 , x2 ], 3
2 3
a2 + b2 (x − x2 ) + c2 (x − x2 ) + d2 (x − x2 ) , on [x2 , x3 ]
S(x) = · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
···················································
···················································
an−1 + bn−1 (x − xn−1 ) + cn−1 (x − xn−1 )2 + dn−1 (x − xn−1 )3 , on [
a0 + b0 (x − x0 ) + c0 (x − x0 )2 + d0 (x − x0 )3 , on [x0 , x1 ],
a1 + b1 (x − x1 ) + c1 (x − x1 )2 + d1 (x − x1 )3 , on [x1 , x2 ],
2 3
a2 + b2 (x − x2 ) + c2 (x − x2 ) + d2 (x − x2 ) , on [x2 , x3 ]
S(x) = ···················································
···················································
···················································
an−1 + bn−1 (x − xn−1 ) + cn−1 (x − xn−1 )2 + dn−1 (x − xn−1 )3 , o
5M
|f (x) − S(x)| ≤ max0≤j≤n−1 (xj+1 − xj )4 .
384
S0 (x) = a0 + b0 x + c0 x2 + d0 x3 ,
S00 (x) = b0 + 2c0 x + 3d0 x2
S000 (x) = 2c0 + 6d0 x,
S1 (x) = a1 + b1 (x − 3) + c1 (x − 3)2 + d1 (x − 3)3 ,
S10 (x) = b1 + 2c1 (x − 3) + 3d1 (x − 3)2 ,
S100 (x) = 2c1 + 6d1 (x − 3),
Prof F. Chirove APM2B10
Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in
S0 (0) = a0 = f (0) = 1,
S0 (3) = 3b0 + 9c0 + 27d0 + 1 = 2 = f (3),
S1 (1) = a1 = 2 = f (3),
S1 (8) = 5b1 + 25c1 + 125d1 + 2 = 3 = f (8).
Hence
a0 = 1, a1 = 2,
3b0 + 9c0 + 27d0 = 1, (17)
5b1 + 25c1 + 125d1 = 1. (18)
so that
a0 b0 c0 d0 a1 b1 c1 d1
1 0.5 -0.0792 0.0079 2 0.2375 -0.0083 0.0002
17x3 19x2 x
S0 (x) = − + + 1 on [0, 3],
2160 240 2
(x − 3)3 1 19(x − 3)
S1 (x) = − (x − 3)2 + + 2,
6000 120 80
on [3, 8]
(
S0 (x), on [0, 3]
S(x) = (22)
S1 (x), on [3, 8]
S OLUTION
Follow the procedure used in example 1 that uses the eight
conditions to compute the values of the coefficients.
E XAMPLE (1)
√
Let f (x) = x + 1. Given (0, 1), (3, 2), (8, 3), construct a natural
cubic spline and a clamped cubic spline. Use the cubic splines
constructed to extimate f (1) and f 0 (1). Calculate the actual
error.
S OLUTION
S0 (x) = a0 + b0 x + c0 x2 + d0 x3 ,
S1 (x) = a1 + b1 (x − 3) + c1 (x − 3)2 + d1 (x − 3)3 ,
h0 = 3, h1 = 5, a0 = 1, a1 = 2, a2 = 3
S OLUTION
− 12
6 3 0 c0
A = 3 16 5 , b = − 25 , X = c1 (23)
1
0 5 10 − 10 c2
So from Ax = b, we have
a0 b0 c0 d0 a1 b1 c1 d1
1 19 17 19 1 1
1 2 − 240 2160 2 80 − 120 6000
S OLUTION
17x3 19x2 x
2160 −
240 + 2 + 1, 0 ≤ x ≤ 3,
S(x) = (24)
(x−3)3
1 19(x−3)
6000 − 120 (x − 3)2 + 80 + 2, 3≤x≤8
E XAMPLE (1)
√
Let f (x) = x + 1. Given (0, 1), (3, 2), (8, 3), construct a natural
cubic spline and a clamped cubic spline. Use the cubic splines
constructed to extimate f (1) and f 0 (1). Calculate the actual
error.
S OLUTION
S0 (x) = a0 + b0 x + c0 x2 + d0 x3 ,
S1 (x) = a1 + b1 (x − 3) + c1 (x − 3)2 + d1 (x − 3)3 ,
h0 = 3, h1 = 5, a0 = 1, a1 = 2, a2 = 3, c0 = c2 = 0
1 0 0 0 c0
A = 3 16 5 , b = −2/5 , c = c1
(25)
1 0 0 0 c2
a0 b0 c0 d0 a1 b1 c1 d1
1 0.3583 0 -0.0028 2 0.2833 -0.0250 0.0017
S OLUTION
(
S0 (x), on [0, 3]
S(x) = (26)
S1 (x), on [3, 8]