0% found this document useful (0 votes)
33 views63 pages

Week 7 - Cubic Splines

NOTES

Uploaded by

poswaxolile23456
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views63 pages

Week 7 - Cubic Splines

NOTES

Uploaded by

poswaxolile23456
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 63

Hermite Interpolation Cubic Spline interpolation

Applied Mathematics 2B : Cubic spline


interpolation

Prof F. Chirove
1 Department of Mathematics and Applied Mathematics, University of
Johannesburg, South Africa

26 August 2024

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation

O UTLINE

1 H ERMITE I NTERPOLATION
Hermite polynomials: Using lagrange polynomials
Hermite interpolation examples
Hermite polynomials: Using Divided differences

2 C UBIC S PLINE INTERPOLATION


Natural Cubic Spline
Clamped cubic spline
Cubic spline interpolation examples
Comparison: Hermite and Cubic spline interpolation

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation

H ERMITE POLYNOMIAL : BACKGROUND


Charles Hermite (1822-1901) - poor test-taker, not able to
pass the exams for his bachelor’s degree until the age of
nearly 26 but best-known mathematician for proving that e
is a transcendental number and his name attached
mathematical ideas and concepts such as the Hermite
differential equation, Hermite polynomials, and Hermitian
matrices
Generalizes both the Taylor polynomials and the Lagrange
polynomials by forming an interpolating polynomial that
agrees with the function both at several distinct points and
at a given number of derivatives of the function at those
distinct points.
Interpolation involving knowledge of function values and
derivatives.

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Hermite interpolation examples

T HE H ERMITE INTERPOALTION PROBLEM

Can we find a polynomial P(x) that interpolates the function


f (x) such that

P(xi ) = f (xi ), P0 (xi ) = f 0 (xi ), 0 ≤ i ≤ n?

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Hermite interpolation examples

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

H ERMITE POLYNOMIALS : U SING L AGRANGE


POLYNOMIALS

T HEOREM (H ERMITE INTERPOLATION THEOREM )


If f ∈ C1 [a, b] and x0 , x1 , · · · , xn ∈ [a, b] are distinct, the unique
polynomial of least degree agreeing with f and f 0 at x0 , · · · xn is
the Hermite polynomial of degree at most 2n + 1 given by
n
X n
X
H2n+1 (x) = f (xj )Hn,j (x) + f 0 (xj )Ĥn,j (x)
j=0 j=0

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

H ERMITE POLYNOMIALS : E RROR B OUND


T HEOREM (H ERMITE INTERPOLATION ERROR THEOREM )
If f ∈ C2n+1 [a, b] and x0 , x1 , · · · , xn ∈ [a, b] are distinct, then for
each x ∈ [a, b], there is ξx ∈ [a, b] such that
n
Y
(x − xj )2
j=0
f (x) − H2n+1 (x) = f (2n+2) (ξx ).
(2n + 2)!

To find the error bound (or maximum error)

 
n  
1 Y
2 (2n+2)
|E(x)| ≤  max (x − xj ) max f (x)
(2n + 2)! x0 ≤x≤xn x0 ≤x≤xn
j=0

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Hermite interpolation examples

H ERMITE INTERPOLATION : E XAMPLE 1: L ANGRANGE


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, using Lagrange
polynomials, 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
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

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Hermite interpolation examples

H ERMITE INTERPOLATION : E XAMPLE 1: L AGRANGE


S OLUTION
2 4 1 4 8 1 4
H0 = [1−2(x−0)( (0)− )][ x2 − x+1]2 = (1+ x)[ x2 − x+1]2 .
3 3 3 3 3 3 3
3 1 2 3 2 1 2 3 2
H1 = [1 − 2(x − 1)(−1 + )][− x + x] = (2 − x)[− x + x] .
2 2 2 2 2
1 1 1 2 1 2 5 1 2 1 2
H2 = [1 − 2(x − 3)( (3) − )][ x − x] = (6 − x)[ x − x] .
3 6 6 6 3 6 6
1 2 4 2 1 2 3 2
Ĥ0 = (x − 0)[ x − x + 1] , Ĥ1 = (x − 1)[− x + x] .
3 3 2 2
1 2 1 2
Ĥ2 = (x − 3)[ x − x] .
6 6
So
H5 (x) = f (x0 )H0 + f 0 (x0 )Ĥ0 + f (x1 )H1 + f 0 (x1 )Ĥ1 + f (x2 )H2 +
5 71 40 37
f 0 (x2 )Ĥ2 = − x5 + x4 − x3 + x2 + x + 2
6 12 3 4
7
f (2) ≈ H5 (2) = .
3
Prof F. Chirove APM2B10
Hermite Interpolation Cubic Spline interpolation Hermite interpolation examples

HE RMITE POLYNOMIAL ERROR BOUND : E XERCISE

1 Use the data in the table to construct the Hermite


interpolating polynomial to approximate sin(0.34).
2 Determine an error bound for the approximation above and
compare it to the actual error.

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Hermite interpolation examples

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

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Hermite interpolation examples

H ERMITE POLYNOMIALS : U SING D IVIDED DIFFERENCES


Zeroth divided difference wrt xi : f [xi ] = f (xi ).
First divided difference wrt xi and xi+1 :
f [xi+1 ] − f [xi ] f (xi+1 ) − f (xi )
f [xi , xi+1 ] = = .
xi+1 − xi xi+1 − xi
Second divided difference wrt xi , xi+1 and xi+2 :
f [xi+1 , xi+2 ] − f [xi , xi+1 ]
f [xi , xi+1 , xi+2 ] = .
xi+2 − xi
··········································
nth divided difference wrt x0 , x1 , · · · xn−1 and xn :
f [x1 , x2 , · · · xn ] − f [x0 , x1 , · · · xn−1 ]
f [x0 , x1 , · · · xn ] = .
xn − x0

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Hermite interpolation examples

H ERMITE POLYNOMIALS : U SING D IVIDED DIFFERENCES


Suppose that distinct x0 , x1 , · · · xn , f (xi ) and
f 0 (xi ), i = 0, 1, 2, · · · n are given we define a sequence
z0 , z1 , · · · zn such that z2i = z2i+1 = xi , that is
z0 = x0 , z1 = x0 , z2 = x1 , z3 = x1 , z4 = x2 , z5 = x2 · · · . We
construct a divided difference table

z f (z) 1st D.D 2nd D.D


z0 f [z0 ] = f (x0 )
f [z0 , z1 ] = f 0 (x0 )
f [z1 , z2 ] − f [z0 , z1 ]
z1 f [z1 ] = f (x0 ) f [z0 , z1 , z2 ] =
z2 − z0
f [z2 ] − f [z1 ]
f [z1 , z2 ] =
z2 − z1
f [z2 , z3 ] − f [z1 , z2 ]
z2 f [z2 ] = f (x1 ) f [z1 , z2 , z3 ] =
z3 − z1
f [z2 , z3 ] = f 0 (x1 )
z3 f [z3 ] = f (x1 )

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Hermite interpolation examples

H ERMITE POLYNOMIALS : U SING D IVIDED DIFFERENCES


The Hermite polynomial is given by
2n+1
X
H2n+1 (x) = f [z0 ] + f [z0 , z1 , · · · , zk ](x − z0 )(x − z1 ) · · · (x − zk−1 ).
k=1

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Hermite interpolation examples

H ERMITE INTERPOLATION : E XAMPLE 1: D IVIDED


DIFFERENCES

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.

H5 (x) = f [z0 ] + f [z0 , z1 ](x − z0 ) + f [z0 , z1 , z2 ](x − z0 )(x − z1 ) + f [z0 , z1 , z


+f [z0 , z1 , z2 , z3 , z4 ](x − z0 )(x − z1 )(x − z2 )(x − z3 )
+f [z0 , z1 , z2 , z3 , z4 , z5 ](x − z0 )(x − z1 )(x − z2 )(x − z3 )(x − z4 )

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Hermite interpolation examples

H ERMITE INTERPOLATION : E XAMPLE 1: D IVIDED


D IFFERENCES TABLE
z f (z) 1st D.D 2nd D.D 3rd D.D 4th D.D 5th D.D
0 2
1
0 2 1
2 -4
7
1 4 -3
4
5 5
−1 −
4 6
3 3
1 4 −
4 4
1
-1
2
5
3 5 −
4
-2
3 5
Prof F. Chirove APM2B10
Hermite Interpolation Cubic Spline interpolation Hermite interpolation examples

H ERMITE INTERPOLATION : E XAMPLE 1: D IVIDED


DIFFERENCES

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,

H5 (x) = 2 + (x − 0) + (x − 0)(x − 0) − 4(x − 0)(x − 0)(x − 1)


7
+ (x − 0)(x − 0)(x − 1)(x − 1)
4
5
− (x − 0)(x − 0)(x − 1)(x − 1)(x − 3),
6
5x5 71x4 40x3 37x2
= − + − + +x+2
6 12 3 4
f (2) ≈ H5 (2) = 7/3
Prof F. Chirove APM2B10
Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

C UBIC SPLINE INTERPOLATION : T HE PROBLEM


"spline" the same as "splint":- originally a small strip of
wood that could be used to join two boards. Later:- refer to
a long, flexible metal strip, used to draw continuous,
smooth curves by forcing the strip to pass through
specified points and tracing along the curve.
Isaac Jacob Schoenberg (1903-1990) developed his work
on splines during World War II involving numerical
procedures for solving differential equations.
Splines application (1960s): - data fitting, computer-aided
geometric design due to availability of computers.
A cubic spline is a piecewise cubic function that
interpolates a set of data points and guarantees
smoothness at the data points.
Spline interpolants can give accurate and smooth
interpolating functions when many points of the function
are known.
Prof F. Chirove APM2B10
Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

W EIERSTRASS APPROXIMATION THEOREM


T HEOREM
For any function f (x) defined on the interval a ≤ x ≤ b, there
exists a degree n polynomial with n finite where

|Pn (x) − f (x)| ≤ 


for all x ∈ [a, b] and any  > 0.
Any function can be approximated with a polynomial inside
a given interval.
At degrees higher than 3, polynomial interpolation can be
ill-behaved between the interpolation data.
The interpolating polynomial can have large oscillations.

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

RUNGE K UTTA P HENOMENON

1
F IGURE : Intepolation of f (x) =
1 + 25x2

The polynomial interpolants are very inaccurate near the


edges of the domain.
Prof F. Chirove APM2B10
Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

A BSOLUTE ERROR COMPARISON

1
F IGURE : Intepolation of f (x) =
1 + 25x2

Higher degree polynomial has a larger maximum error


than the lower degree polynomial.

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

RUNGE K UTTA P HENOMENON


With equally spaced points a polynomial interpolant can
have large oscillations going both high and below the
actual function.
In general, performing high degree polynomial
interpolation is a bad idea. In general it is better to fit
low-degree polynomials to subsets of the data and
then connect those polynomials

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

T HE P ROBLEM : C UBIC S PLINE I NTERPOLATION


Suppose that we are given a set of nodes {xi , 0 < i < n} at
which we wish to interpolate a given function f (x) with a spline
of degree 3. The problem is then to find a piecewise polynomial
function, S(x), which satisfies the following conditions:
1 interpolates the function f (x) at all the nodes.
2 has continuous first and second derivatives at the nodes
3 is a polynomial of degree 3 on each sub-interval [xj , xj+1 ].

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

C UBIC SPLINE INTERPOLATION


D EFINITION ( DEFINITION 1)
A function S(x) ∈ C2 [a, b] is called a cubic spline on [a, b] if S(x)
is a cubic polynomial Sj (xj ) in each interval [xj , xj+1 ].

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

C UBIC SPLINE INTERPOLATION


D EFINITION ( DEFINITION 2- CONSTRUCTING A CUBIC SPLINE )
Given a function f defined on [a, b] and a set of nodes
a = x0 < x1 < · · · < xn = b, cubic spline interpolant S(x) for f is a
function that satisfies the following conditions:
(A1) S(x) is a cubic polynomial, defined by
Sj (x) = aj + bj (x − xj ) + cj (x − xj )2 + dj (x − xj )3 on the
subinterval [xj , xj+1 ] for j = 0, 1, · · · , n − 1.
(A2) Sj (xj ) = f (xj ) and Sj (xj+1 ) = f (xj+1 ) for each
j = 0, 1, · · · n − 1. (S must interpolate f at each of the nodes)
(A3) Sj (xj+1 ) = Sj+1 (xj+1 ) for each j = 0, 1, · · · n − 2.

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

C UBIC SPLINE INTERPOLATION


D EFINITION ( DEFINITION 2- CONSTRUCTING A CUBIC SPLINE )
(A4) Sj0 (xj+1 ) = Sj+1
0 (x 0
j+1 ) for each j = 0, 1, · · · n − 2. (S must be
continuous at each of the internal nodes)
00 (x
(A5) Sj00 (xj+1 ) = Sj+1 00
j+1 ) for each j = 0, 1, · · · n − 2. (S must be
continuous at each of the internal nodes)
(A6) One of the following sets of boundary conditions is
satisfied
( I ) S00 (x0 ) = S00 (xn ) = 0 (The natural spline)
( II ) S0 (x0 ) = f 0 (x0 ) and S0 (xn ) = f 0 (xn ).( Clamped cubic spline)

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

A PPLYING THE CONDITIONS : NATURAL SPLINE


1. Sj (x) = aj + bj (x − xj ) + cj (x − xj )2 + dj (x − xj )3 .
Apply (A2) at xj :
Sj (xj ) = aj + bj (xj − xj ) + cj (xj − xj )2 + dj (xj − xj )3 = aj .
Since Sj (xj ) = f (xj ), then aj = f (xj ).
2. Apply (A3):Let aj+1 = Sj (xj+1 ) = Sj+1 (xj+1 ). Evaluating Sj (x)
at xj+1 and replacing Sj (xj+1 ) by aj+1 we get
aj+1 = aj + bj (xj+1 − xj ) + cj (xj+1 − xj )2 + dj (xj+1 − xj )3 .
Introduce hj = xj+1 − xj , j = 0, 1, 2, · · · , n − 1 and define at
the xn node an = f (xn ) to get

aj+1 = aj + bj hj + cj h2j + dj h3j (4)

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

A PPLYING THE CONDITIONS : NATURAL SPLINE


3. Differentiating Sj (x) with respect to x yields
Sj0 (x) = bj + 2cj (x − xj ) + 3dj (x − xj )2 .
Apply A4 (replace x with xj ):
Sj0 (xj ) = bj + 2cj (xj − xj ) + 3dj (xj − xj )2 = bj
and at the xn node define bn = S0 (xn ).
Let bj+1 = Sj0 (xj+1 ) = Sj+1 0 (x 0
j+1 ). Evaluating Sj (x) at xj+1 and
0
replacing Sj (xj+1 ) with bj+1 yields
Sj0 (xj+1 ) = bj + 2cj (xj+1 − xj ) + 3dj (xj+1 − xj )2 and
introducing hj = xj+1 − xj we get

bj+1 = bj + 2cj hj + 3dj h2j . (5)

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

A PPLYING THE CONDITIONS : NATURAL SPLINE


4. Computing the second derivative of S( x) :
Sj00 (x) = 2cj + 6dj (x − xj ).
Dividing by 2
Sj00 (x)/2 = cj + 3dj (x − xj ).
00 (x
Apply A5 Let cj+1 = Sj00 (xj+1 )/2 = Sj+1 j+1 )/2 we get
00
Sj (xj+1 )/2 = cj + 3dj (xj+1 − xj ).
Defining at the xn node cn = S00 (xn )/2 and introducing
hj = xj+1 − xj yields

cj+1 = cj + 3dj hj . (6)

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

A PPLYING THE CONDITIONS : NATURAL SPLINE


5. From equation (6) we make dj subject of the formula to get
cj+1 − cj
dj = (7)
3hj

Substituting (7) into (4) and (5) yields

h2j
aj+1 = aj + bj hj + (2cj + cj+1 ), (8)
3
bj+1 = bj + hj (cj + cj+1 ). (9)

From (8) we make bj subject of the formula

1 hj
bj = (aj+1 − aj ) − (2cj + cj+1 ). (10)
hj 3

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

A PPLYING THE CONDITIONS : NATURAL SPLINE


Re-indexing eqution (10) by replacing j with j − 1 you get

1 hj−1
bj−1 = (aj − aj−1 ) − (2cj−1 + cj ). (11)
hj−1 3

Re-indexing eqution (9) by replacing j + 1 with j you get

bj = bj−1 + hj−1 (cj−1 + cj ). (12)

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

A PPLYING THE CONDITIONS : NATURAL S PLINE


6. Consequently
3 3
hj−1 cj−1 + 2(hj−1 + hj )cj + hj cj+1 = (aj+1 − aj ) − (aj − aj−1 ),
hj hj−1

for each j = 1, 2, · · · , n − 1. In expanded form


3 3
h0 c0 + 2(h0 + h1 )c1 + h1 c2 = (a2 − a1 ) − (a1 − a0 ),
h1 h0
3 3
h1 c1 + 2(h1 + h2 )c2 + h2 c3 = (a3 − a2 ) − (a2 − a1 ),
h2 h1
··· = ··· ,
··· = ··· ,
3
hn−2 cn−2 + 2(hn−2 + hn−1 )cn−1 + hn−1 cn = (an − an−1 )
hn−1
3
− (an−1 − an−2−1 ).
hn−2

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

A PPLYING THE CONDITIONS : NATURAL S PLINE


Note that h0j s are known from the spacing of nodes and a0j s
are known from the values of f at the nodes so this
systems solves for the uknown c0j s.
The b0j s are subsequently solved by equation

1 hj
bj = (aj+1 − aj ) − (2cj + cj+1 ) (13)
hj 3

and dj0 s are solved by

cj+1 − cj
dj = . (14)
3hj

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

A PPLYING THE BOUNDARY CONDITIONS ; NATURAL


SPLINE

7. Applying Natural spline conditions S00 (a) = S00 (b) = 0


implies that cn = S00 (xn )/2 = 0 and that
0 = S00 (x0 ) = 2c0 + 6d0 (x0 − x0 ) which gives c0 = 0. These
two conditions together with the system
3 3
hj−1 cj−1 +2(hj−1 +hj )cj +hj cj+1 = (aj+1 −aj )− (aj −aj−1 ).
hj hj−1
produce a (n + 1) × (n + 1) linear system Ax = b where
 1 0 0 ··· · · 0 
h0 2(h0 +h1 ) h1 0 ··· · 0
0 h1 2(h1 +h2 ) h2 0 ··· 0 
A=  ·
 · 0 · · ··· · 0  (15)
· · · ··· · 0 
0 · · · hn−2 2(hn−2 +hn−1 ) hn−1
0 · · · 0 0 1

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

A PPLYING THE CONDITIONS : NATURAL SPLINE


and
 
0
3 3 
c0

(a2 − a1 ) − (a1 − a0 )
 
 
 h1 h0   c1 
 3 3   
 (a3 − a2 ) − (a2 − a1 )   c2 
h2 h1
   
b =  , x =  · 
 
·  
   · 

 · 
  
 3 cn−1 
3 
 h (an − an−1 ) − h (an−1 − an−2 )
 
cn
n−1 n−2
0

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

T HE NATURAL CUBIC SPLINE



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 [

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

A PPLYING THE CONDITIONS : C LAMPED C UBIC S PLINE


6. We have ( as in Natural spline) for the internal nodes
3 3
hj−1 cj−1 +2(hj−1 +hj )cj +hj cj+1 = (aj+1 −aj )− (aj −aj−1 ).
hj hj−1
for each j = 0, 1, 2, · · · , n − 1.
hj are known from the spacing of nodes and aj are known
from the values of f at the nodes so this systems solves for
the uknown c0j s.
The b0j s are solved by equation
1 hj
bj = (aj+1 − aj ) − (2cj + cj+1 )
hj 3
0 cj+1 − cj
dj s are solved by dj =
3hj

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

A PPLYING THE BOUNDARY CONDITIONS ; C LAMPED


C UBIC SPLINE
7. Applying Clamped cubic spline boundary condition
S0 (x0 ) = f 0 (x0 ).
Check that S0 (x0 ) = S00 (x0 ) = b0 . So f 0 (x0 ) = b0 .
1 hj
From the formula bj = (aj+1 − aj ) − (2cj + cj+1 ), we have
hj 3
1 h0
f 0 (x0 ) = b0 = (a1 − a0 ) − (2c0 + c1 ) which simplifies to
h0 3
3
2h0 c0 + h0 c1 = (a1 − a0 ) − 3f 0 (x0 ).
h0
This equation for the boundary condition and x0 replaces
the first row of the matric A in the natural spline section.

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

A PPLYING THE BOUNDARY CONDITIONS ; C LAMPED


C UBIC SPLINE
Applying Clapmed cubic spline boundary condition
S0 (xn ) = f 0 (xn ).
Check that S0 (xn ) = Sn−1
0
(x0 ) = bn . So f 0 (xn ) = bn .
From the formula bj = bj−1 + hj−1 (cj−1 + cj ), we have
f 0 (xn ) = bn = bn−1 + hn−1 (cn−1 + cn ).
1 hj
From the formula bj = (aj+1 − aj ) − (2cj + cj+1 ), we have
hj 3
1 hn−1
bn−1 = (an − an−1 ) − (2cn−1 + cn ),
hn−1 3
So
1 hn−1
f 0 (xn ) = (an − an−1 ) − (2cn−1 + cn ) + hn−1 (cn−1 + cn ).
hn−1 3
which simplifies to
3
hn−1 cn−1 + 2hn−1 cn = 3f 0 (xn ) − (an − an−1 ),
hn−1
which replaces the last row of the matric A in the natural
spline section.
Prof F. Chirove APM2B10
Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

A PPLYING THE BOUNDARY CONDITIONS ; C LAMPED


C UBIC SPLINE
On the internal nodes we use the system
3 3
hj−1 cj−1 +2(hj−1 +hj )cj +hj cj+1 = (aj+1 −aj )− (aj −aj−1 ).
hj hj−1
and together with the boundary conditions we produce
produce a (n + 1) × (n + 1) linear system Ax = b where
··· · ·
 2h h 0 0

0 0
h0 2(h0 +h1 ) h1 0 ··· · 0
0 h1 2(h1 +h2 ) h2 0 ··· 0 
 
A= (16)

· 0 · · ··· · 0 
 · · · · ··· · 0 
0 · · · hn−2 2(hn−2 +hn−1 ) hn−1
0 · · · 0 hn−1 2hn−1

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

A PPLYING THE CONDITIONS :C LAMPED CUBIC SPLINE


and
 3 
(a1 − a0 ) − 3f 0 (x0 )
 h0 
 3 3  
c0

 (a2 − a1 ) − (a1 − a0 ) 

 h1 h0 
  c1 
 3 3   
 (a 3 − a 2 ) − (a2 − a1 )   c2 
 h2 h1  
, x =  · 

b = 
 ·   
 · 
·
 
   
cn−1 
 3 3
 
(a − an−1 ) − (an−1 − an−2 )

 hn−1 n cn

hn−2 
 3 
3f 0 (xn ) − (an − an−1 )
hn−1

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

T HE C LAMPED CUBIC SPLINE



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

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

C LAMPED C UBIC SPLINE ERROR


0000
Let f ∈ C4 [a, ] with maxa≤x≤b |f (x)| = M. If S is the unique
clamped cubic spline interpolant to f with respect to the nodes
a = x0 < x1 < · · · < xn = b, then, ∀x ∈ [a, b]

5M
|f (x) − S(x)| ≤ max0≤j≤n−1 (xj+1 − xj )4 .
384

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

C LAMPED C UBIC SPLINE INTERPOLATION : E XAMPLE 1


E XAMPLE (1)

Let f (x) = x + 1. Given (0, 1), (3, 2), (8, 3), construct a
clamped cubic spline to interpolate the function f .. Use the
cubic splines constructed to estimate f (1) and f 0 (1). Calculate
the actual absolute error.
S OLUTION

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

C LAMPED C UBIC SPLINE INTERPOLATION : E XAMPLE 1


S OLUTION
Four conditions come from the fact that the splines must
agree with the data at the nodes.

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)

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

C UBIC SPLINE INTERPOLATION : E XAMPLE 1


S OLUTION
Two conditions come from the fact that S00 (3) = S10 (3) and
S000 (3) = S100 (3).

S00 (3) = S10 (3) =⇒ b0 + 6c0 + 27d0 = b1


S000 (3) = S100 (3) =⇒ 2c0 + 18d0 = 2c1

so that

b0 + 6c0 + 27d0 − b1 = 0, (19)


2c0 + 18d0 − 2c1 = 0. (20)

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

C UBIC SPLINE INTERPOLATION : E XAMPLE 1


S OLUTION
Two final conditions come from the boundary conditions.
1
For clampled cubic spline f 0 (x) = √ and
2 x+1
1 1
S00 (0) = f 0 (0) = , S10 (8) = f 0 (8) =
2 6
0 1 1
S0 (0) = =⇒ b0 = and
2 2
0 1 1
S1 (8) = =⇒ b1 + 10c1 + 75d1 =
6 6
So
1
b0 = ,
2
1
b1 + 10c1 + 75d1 = . (21)
6

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

C UBIC SPLINE INTERPOLATION : E XAMPLE 1


S OLUTION
Exercise: Solve the equations (17) to (21)

3b0 + 9c0 + 27d0 = 1,


5b1 + 25c1 + 125d1 = 1,
b0 + 6c0 + 27d0 − b1 = 0,
2c0 + 18d0 − 2c1 = 0,
1
b1 + 10c1 + 75d1 = ,
6
simultaneously to get

a0 b0 c0 d0 a1 b1 c1 d1
1 0.5 -0.0792 0.0079 2 0.2375 -0.0083 0.0002

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

C UBIC SPLINE INTERPOLATION : E XAMPLE 1


S OLUTION

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]

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

C UBIC SPLINE INTERPOLATION : E XAMPLE 1



E STIMATION OF 2.

f (1) ≈ S(1) = S0 (1) = 1.4287,


f 0 (1) ≈ S0 (1) = S00 (x) = 0.3653,
E1 = |f (1) − S(1)| = |1.41421 − 1.4287| = 0.0145

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

NATURAL C UBIC SPLINE INTERPOLATION : E XERCISE


E XERCISE (1)

Let f (x) = x + 1. Given (0, 1), (3, 2), (8, 3), construct a natural
cubic spline to interpolate the function f . Use the cubic splines
constructed to estimate f (1) and f 0 (1). Calculate the actual
absolute error.

S OLUTION
Follow the procedure used in example 1 that uses the eight
conditions to compute the values of the coefficients.

Hint: Everything is the same for the first 6 conditions. The


difference only comes when you apply the boundary
conditions for the Natural spline.

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

C UBIC SPLINE INTERPOLATION : E XAMPLE 1 G RAPHS


S OLUTION

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

C LAMPED C UBIC SPLINE INTERPOLATION (M ATRIX


METHOD ): E XAMPLE 1

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

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

C LAMPED C UBIC SPLINE INTERPOLATION (M ATRIX


METHOD ): E XAMPLE 2

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

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

C LAMPED C UBIC SPLINE INTERPOLATION ( MATRIX


METHOD ): E XAMPLE 2

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

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

NATURAL C UBIC SPLINE INTERPOLATION (M ATRIX


METHOD ): E XAMPLE 2

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

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

NATURAL C UBIC SPLINE INTERPOLATION ( MATRIX


M ETHOD ): E XAMPLE 2
S OLUTION

    
1 0 0 0 c0
A =  3 16 5 , b = −2/5 , c = c1 
    (25)
1 0 0 0 c2

So from Ax = b, we have 16c1 = −2/5 implying c1 = −1/40;


and the rest of the parameters are given in the table below

a0 b0 c0 d0 a1 b1 c1 d1
1 0.3583 0 -0.0028 2 0.2833 -0.0250 0.0017

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

NATURAL C UBIC SPLINE INTERPOLATION ( MATRIX


METHOD ): E XAMPLE 2

S OLUTION

S0 (x) = 1 + 0.3583x − 0.0028x3 on [0, 3],


S1 (x) = 2 + 0.2833(x − 3) − 0.0250(x − 3)2 + 0.0017(x − 3)3 , on [3, 8]

(
S0 (x), on [0, 3]
S(x) = (26)
S1 (x), on [3, 8]

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

NATURAL C UBIC SPLINE INTERPOLATION : E XAMPLE 1



E STIMATION OF 2.

f (1) ≈ S(1) = S0 (1) = 1.3555,


f 0 (1) ≈ S0 (1) = S00 (x) = 0.3499,
E1 = |f (1) − S(1)| = |1.41421 − 0.3499| = 0.0587136

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

CLAMPED C UBIC SPLINE VS H ERMITE INTERPOLATION :


E XAMPLE 1 G RAPHS
S OLUTION

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

CLAMPED C UBIC SPLINE VS H ERMITE INTERPOLATION :



E XAMPLE 1 E STIMATION OF 2.

37x5 449x4 8389x3 1169x2 x


H5 (x) = − + − + + 1,
432000 216000 432000 12000 2
f (1) ≈ H5 (1) = 1.4200,
f 0 (1) ≈ H50 (1) = 0.3555,
E1 = |f (1) − H5 (1)| = |1.41421 − 1.42000| = 0.0057957.

Prof F. Chirove APM2B10


Hermite Interpolation Cubic Spline interpolation Natural Cubic Spline Clamped cubic spline Cubic spline in

CLAMPED C UBIC SPLINE VS H ERMITE INTERPOLATION :


E XAMPLE 1 E RROR GRAPHS G RAPHS
S OLUTION

Prof F. Chirove APM2B10

You might also like