You are on page 1of 30

PART 2:

Hermite & Cubic Spline Interpolations


Recall
𝑁𝑁
 Definition. Let 𝑆𝑆 = 𝑝𝑝𝑘𝑘 where 𝑝𝑝𝑘𝑘 = 𝑥𝑥𝑘𝑘 , 𝑦𝑦𝑘𝑘 .Then, the Nth degree Lagrange
𝑘𝑘=0
polynomial 𝑃𝑃 𝑥𝑥 passing thought 𝑆𝑆 is:

𝑁𝑁 𝑦𝑦𝑘𝑘
𝑃𝑃 𝑥𝑥 = � 𝑓𝑓 𝑥𝑥𝑘𝑘 � 𝐿𝐿𝑵𝑵,𝑘𝑘 𝑥𝑥
𝑘𝑘=0
wherein
𝑥𝑥 − 𝑥𝑥0 𝑥𝑥 − 𝑥𝑥1 ⋯ 𝑥𝑥 − 𝑥𝑥𝒌𝒌−𝟏𝟏 𝑥𝑥 − 𝑥𝑥𝒌𝒌+𝟏𝟏 ⋯ 𝑥𝑥 − 𝑥𝑥𝑁𝑁
𝐿𝐿𝑁𝑁,𝒌𝒌 𝑥𝑥 =
𝑥𝑥𝑘𝑘 − 𝑥𝑥0 𝑥𝑥𝑘𝑘 − 𝑥𝑥1 ⋯ 𝑥𝑥𝑘𝑘 − 𝑥𝑥𝒌𝒌−𝟏𝟏 𝑥𝑥𝑘𝑘 − 𝑥𝑥𝒌𝒌+𝟏𝟏 ⋯ 𝑥𝑥𝑘𝑘 − 𝑥𝑥𝑁𝑁

 Remarks. 𝐿𝐿𝑁𝑁,𝑖𝑖 𝑥𝑥𝑗𝑗 = 𝛿𝛿𝑖𝑖𝑖𝑖 .


Hermite Interpolation
Introduction
 Recall. For a given function 𝑓𝑓, Lagrange polynomial of degree N
 necessarily agree with 𝑓𝑓 at 𝑥𝑥𝑖𝑖 𝑁𝑁
𝑖𝑖=0 .
 Not necessarily agree with 𝑓𝑓 ′ at 𝑥𝑥𝑖𝑖 𝑁𝑁
𝑖𝑖=0 .

 Remark. For a function 𝑓𝑓, Hermite polynomial agrees with 𝑓𝑓 and 𝑓𝑓 ′ at


𝑁𝑁
𝑥𝑥𝑖𝑖 𝑖𝑖=0 .

 Consequence. Hermite polynomials have the same “shape” as the


function at (𝑥𝑥𝑖𝑖 , 𝑓𝑓(𝑥𝑥𝑖𝑖 )) in the sense that the tangent lines to the polynomial
and the function agree.
Hermite Interpolation
 Theorem. If 𝑓𝑓 ∈ 𝐶𝐶 1 [𝑎𝑎, 𝑏𝑏] and 𝑥𝑥0 , 𝑥𝑥1 , . . . , 𝑥𝑥𝑁𝑁 ∈ [𝑎𝑎, 𝑏𝑏] are distinct, the unique
𝑁𝑁
polynomial of least degree agreeing with 𝑓𝑓 and 𝑓𝑓 ′ at 𝑥𝑥𝑖𝑖 𝑖𝑖=0 is the Hermite
polynomial of degree at most 2𝑁𝑁 + 1 given by

𝑁𝑁 𝑁𝑁
𝐻𝐻2𝑁𝑁+1 𝑥𝑥 = � 𝑓𝑓 𝑥𝑥𝑗𝑗 𝐻𝐻𝑁𝑁,𝑗𝑗 𝑥𝑥 + � �𝑁𝑁,𝑗𝑗 𝑥𝑥 ,
𝑓𝑓 ′ 𝑥𝑥𝑗𝑗 𝐻𝐻
𝑗𝑗=0 𝑗𝑗=0

where, for 𝐿𝐿𝑁𝑁,𝑗𝑗 (𝑥𝑥) denoting the 𝑗𝑗th Lagrange coefficient polynomial of degree 𝑁𝑁,
𝐻𝐻𝑁𝑁,𝑗𝑗 𝑥𝑥 = 1 − 2 𝑥𝑥 − 𝑥𝑥𝑗𝑗 𝐿𝐿′ 𝑁𝑁,𝑗𝑗 𝑥𝑥𝑗𝑗 𝐿𝐿2𝑁𝑁,𝑗𝑗 𝑥𝑥

�𝑁𝑁,𝑗𝑗 𝑥𝑥 = 𝑥𝑥 − 𝑥𝑥𝑗𝑗 𝐿𝐿2𝑁𝑁,𝑗𝑗 𝑥𝑥
𝐻𝐻
Hermite Interpolation
 Theorem (cont.). Moreover, if 𝑓𝑓 ∈ 𝐶𝐶 2𝑛𝑛+2 [𝑎𝑎, 𝑏𝑏], then

𝑥𝑥 − 𝑥𝑥0 2 ⋯ 𝑥𝑥 − 𝑥𝑥𝑁𝑁 2
2𝑁𝑁+2
𝑓𝑓 𝑥𝑥 = 𝐻𝐻2𝑁𝑁+1 𝑥𝑥 + 𝑓𝑓 𝜉𝜉(𝑥𝑥)
2𝑁𝑁 + 2 !

for some (generally unknown) 𝜉𝜉(𝑥𝑥) in the interval (𝑎𝑎, 𝑏𝑏).


Hermite Interpolation
 Example. Use the Hermite polynomial that agrees with the data listed in
the below table to find an approximation of 𝑓𝑓(1.5).

 Solution.
 Step 1. Construct 𝐿𝐿2,0 𝑥𝑥 , 𝐿𝐿2,1 𝑥𝑥 , 𝐿𝐿2,2 𝑥𝑥 .
 Step 2. Construct 𝐿𝐿′2,0 𝑥𝑥 , 𝐿𝐿′2,1 𝑥𝑥 , 𝐿𝐿′2,2 𝑥𝑥 .
 Step 3. Construct 𝐻𝐻2×2+1 𝑥𝑥 .
 Step 4. Estimate 𝑓𝑓(1.5) ≈ 𝐻𝐻5 𝑥𝑥 .
Hermite Interpolation
 Solution (cont.).
𝑥𝑥 − 𝑥𝑥1 𝑥𝑥 − 𝑥𝑥2 50 2 175 152 100 175
𝐿𝐿2,0 𝑥𝑥 = = 𝑥𝑥 − 𝑥𝑥 + ′
𝐿𝐿2,0 𝑥𝑥 = 𝑥𝑥 −
𝑥𝑥0 − 𝑥𝑥1 𝑥𝑥0 − 𝑥𝑥2 9 9 9 9 9
𝑥𝑥 − 𝑥𝑥0 𝑥𝑥 − 𝑥𝑥2 −100 2 320 247 −200 320
𝐿𝐿2,1 𝑥𝑥 = = 𝑥𝑥 + 𝑥𝑥 − ⟹ 𝐿𝐿′2,1 𝑥𝑥 = 𝑥𝑥 +
𝑥𝑥1 − 𝑥𝑥0 𝑥𝑥1 − 𝑥𝑥2 9 9 9 9 9
𝑥𝑥 − 𝑥𝑥0 𝑥𝑥 − 𝑥𝑥1 50 2 145 104 ′
100 145
𝐿𝐿2,2 𝑥𝑥 = = 𝑥𝑥 − 𝑥𝑥 + 𝐿𝐿2,2 𝑥𝑥 = 𝑥𝑥 −
𝑥𝑥2 − 𝑥𝑥0 𝑥𝑥2 − 𝑥𝑥1 9 9 9 9 9

𝐻𝐻2,0 𝑥𝑥 = 1 − 2 𝑥𝑥 − 𝑥𝑥0 𝐿𝐿′ 2,0 𝑥𝑥0 𝐿𝐿22,0 𝑥𝑥 = 10𝑥𝑥 − 12 50⁄9 𝑥𝑥 2 − 175⁄9 𝑥𝑥 + 152⁄9 2

�2,0 𝑥𝑥 = 𝑥𝑥 − 𝑥𝑥0 𝐿𝐿22,0 𝑥𝑥 = 𝑥𝑥 − 1.3 50⁄9 𝑥𝑥 2 − 175⁄9 𝑥𝑥 + 152⁄9 2
𝐻𝐻
𝐻𝐻2,1 𝑥𝑥 = 1 − 2 𝑥𝑥 − 𝑥𝑥1 𝐿𝐿′ 2,1 𝑥𝑥1 𝐿𝐿22,1 𝑥𝑥 = −100⁄9 𝑥𝑥 2 + 320⁄9 𝑥𝑥 − 247⁄9 2

�2,1 𝑥𝑥 = 𝑥𝑥 − 𝑥𝑥1 𝐿𝐿22,1 𝑥𝑥 = 𝑥𝑥 − 1.6 −100⁄9 𝑥𝑥 2 + 320⁄9 𝑥𝑥 − 247⁄9 2
𝐻𝐻
𝐻𝐻2,2 𝑥𝑥 = 1 − 2 𝑥𝑥 − 𝑥𝑥2 𝐿𝐿′ 2,2 𝑥𝑥2 𝐿𝐿22,2 𝑥𝑥 = −10 𝑥𝑥 − 2 50⁄9 𝑥𝑥 2 − 145⁄9 𝑥𝑥 + 104⁄9 2

�2,2 𝑥𝑥 = 𝑥𝑥 − 𝑥𝑥2 𝐿𝐿22,2 𝑥𝑥 = 𝑥𝑥 − 1.9 50⁄9 𝑥𝑥 2 − 145⁄9 𝑥𝑥 + 104⁄9 2
𝐻𝐻
Hermite Interpolation
 Solution (cont.).

⟹ 𝐻𝐻5 𝑥𝑥 = 𝐻𝐻2×2+1 𝑥𝑥
2 2
=� 𝑓𝑓 𝑥𝑥𝑗𝑗 𝐻𝐻2,𝑗𝑗 𝑥𝑥 + � �2,𝑗𝑗 𝑥𝑥
𝑓𝑓 ′ 𝑥𝑥𝑗𝑗 𝐻𝐻
𝑗𝑗=0 𝑗𝑗=0
= 0.6200860𝐻𝐻2,0 𝑥𝑥 + 0.4554022𝐻𝐻2,1 𝑥𝑥 +
�2,0 𝑥𝑥 −
0.2818186𝐻𝐻2,2 𝑥𝑥 − 0.5220232𝐻𝐻
�2,1 𝑥𝑥 − 0.5811571 𝐻𝐻
0.5698959𝐻𝐻 �2,1 𝑥𝑥

⟹ 𝑓𝑓 1.5 ≈ 𝐻𝐻5 1.5 ≈ 0.5118277.


Hermite Interpolation
& Divided Differences
 Remarks.
 The need to determine and evaluate the Lagrange polynomials
and their derivatives makes the procedure tedious even for small
values of N.

 There is an alternative method for generating Hermite


approximations that has as its basis the Newton interpolatory
divided-difference formula at 𝑥𝑥𝑖𝑖 𝑁𝑁
𝑖𝑖=0 .
Hermite Interpolation
& Divided Differences
 Recall. Newton interpolatory divided-difference formula:

𝑁𝑁
𝑃𝑃𝑁𝑁 (𝑥𝑥) = 𝑓𝑓 [𝑥𝑥0 ] + � 𝑓𝑓[𝑥𝑥0 , 𝑥𝑥1 , . . . , 𝑥𝑥𝑘𝑘 ](𝑥𝑥 − 𝑥𝑥0 ) · · · (𝑥𝑥 − 𝑥𝑥𝑘𝑘−1 )
𝑘𝑘=1

 Theorem. Suppose that 𝑓𝑓 ∈ 𝐶𝐶 𝑁𝑁 [𝑎𝑎, 𝑏𝑏] and 𝑥𝑥0 , 𝑥𝑥1 , . . . , 𝑥𝑥𝑁𝑁 ∈ [𝑎𝑎, 𝑏𝑏] are
distinct numbers in [𝑎𝑎, 𝑏𝑏]. Then a number 𝜉𝜉 exists in (𝑎𝑎, 𝑏𝑏) with

𝑁𝑁
𝑓𝑓 (𝜉𝜉 )
𝑓𝑓 [𝑥𝑥0 , 𝑥𝑥1 , . . . , 𝑥𝑥𝑁𝑁 ] = .
𝑁𝑁!
Hermite Interpolation
& Divided Differences
𝑁𝑁
 Method. Suppose that the distinct numbers 𝑥𝑥𝑖𝑖 𝑖𝑖=0 are given together with the
values of 𝑓𝑓 and 𝑓𝑓 ′ at these numbers.

 Step 1. Define a new sequence 𝑧𝑧𝑖𝑖 2𝑁𝑁+1


𝑖𝑖=0 by

𝑧𝑧2𝑖𝑖 = 𝑧𝑧2𝑖𝑖+1 = 𝑥𝑥𝑖𝑖 , for each 𝑖𝑖 = 0, 1, . . . , 𝑛𝑛.

 Step 2. Construct the divided difference table in the form of Table using 𝑧𝑧𝑖𝑖 2𝑁𝑁+1
𝑖𝑖=0 .
Hermite Interpolation
& Divided Differences
 Method (cont.).
 Recall. Divided difference table:
Hermite Interpolation
& Divided Differences
 Method (cont.).
 Caution. Since 𝑧𝑧2𝑖𝑖 = 𝑧𝑧2𝑖𝑖+1 = 𝑥𝑥𝑖𝑖 for each 𝑖𝑖, we cannot define 𝑓𝑓[𝑧𝑧2𝑖𝑖 , 𝑧𝑧2𝑖𝑖+1 ] by the
divided difference formula, since

𝑓𝑓 𝑧𝑧2𝑖𝑖+1 − 𝑓𝑓 𝑧𝑧2𝑖𝑖 𝑓𝑓 𝑧𝑧2𝑖𝑖+1 − 𝑓𝑓 𝑧𝑧2𝑖𝑖


𝑓𝑓 𝑧𝑧2𝑖𝑖 , 𝑧𝑧2𝑖𝑖+1 = =
𝑧𝑧2𝑖𝑖+1 − 𝑧𝑧2𝑖𝑖 0

 Remark. Based on the aforementioned theorem, the reasonable substitution in


this situation is
𝑓𝑓 𝑧𝑧2𝑖𝑖 , 𝑧𝑧2𝑖𝑖+1 = 𝑓𝑓 ′ (𝑧𝑧2𝑖𝑖 ) = 𝑓𝑓 ′ (𝑥𝑥𝑖𝑖 )
Hermite Interpolation
& Divided Differences
 Method (cont.).
 Result.
Hermite Interpolation
& Divided Differences
 Method (cont.).
 Step 3. The Hermite polynomial is then given by

2𝑁𝑁+1
𝐻𝐻2𝑁𝑁+1 (𝑥𝑥) = 𝑓𝑓 [𝑧𝑧0 ] + � 𝑓𝑓[𝑧𝑧0 , 𝑧𝑧1 , . . . , 𝑧𝑧𝑘𝑘 ](𝑥𝑥 − 𝑧𝑧0 ) · · · (𝑥𝑥 − 𝑧𝑧𝑘𝑘−1 )
𝑘𝑘=1

 Exercise. Prove the above claim.


Cubic Spline Interpolation
Introduction
 Remarks.
 The previous sections concerned the
approximation of arbitrary functions on
closed intervals using a single
polynomial.

 High-degree polynomials can oscillate


erratically.
 A minor fluctuation over a small portion of the
interval can induce large fluctuations over the
entire range.
Introduction
 Remarks (cont.).
 An alternative approach is to divide the
approximation interval into a collection of
subintervals and construct a (generally)
different approximating polynomial on
each subinterval.

This is called piecewise-polynomial


approximation.
Piecewise-Polynomial Approximation
 Remarks (cont.).
 The simplest piecewise-polynomial
approximation is piecewise-linear
interpolation, which consists of
joining a set of data points

{(𝑥𝑥0 , 𝑓𝑓(𝑥𝑥0 )), (𝑥𝑥1 , 𝑓𝑓(𝑥𝑥1 )), . . . , (𝑥𝑥𝑁𝑁 , 𝑓𝑓(𝑥𝑥𝑁𝑁 ))}

by a series of straight lines.


Piecewise-Polynomial Approximation
 Remarks (cont.).
 A disadvantage of linear function approximation is that there is likely
no differentiability at the endpoints of the subintervals
 In a geometrical context, means that the interpolating function is not “smooth.”
 Often it is clear from physical conditions that smoothness is required, so

the approximating function must be continuously differentiable.

 An alternative procedure is to use a piecewise polynomial of Hermite


type.
 If the values of 𝑓𝑓 and 𝑓𝑓 ′ are known at each node, a cubic Hermite polynomial can
be used on each of the subintervals [𝑥𝑥0 , 𝑥𝑥1 ], [𝑥𝑥1 , 𝑥𝑥2 ], . . . , [𝑥𝑥𝑁𝑁−1 , 𝑥𝑥𝑁𝑁 ] to obtain a
function that has a continuous derivative on the interval [𝑥𝑥0 , 𝑥𝑥𝑁𝑁 ].
Piecewise-Polynomial Approximation
 Remarks (cont.).
 To determine the appropriate Hermite cubic polynomial on a given interval is
simply a matter of computing 𝐻𝐻3 (𝑥𝑥) for that interval.
 The Lagrange interpolating polynomials needed to determine 𝐻𝐻3 are of first degree, so
this can be accomplished without great difficulty.

To use Hermite piecewise polynomials for general interpolation, we need to


know the derivative of the function being approximated, and
this is frequently unavailable.
Piecewise-Polynomial Approximation
 Consequence. Hermite interpolation is often impractical.

 Remark. The simplest type of differentiable piecewise-polynomial function


on an entire interval [𝑥𝑥0 , 𝑥𝑥𝑁𝑁 ] is the function obtained by fitting one quadratic
polynomial between each successive pair of nodes [𝑥𝑥𝑖𝑖 , 𝑥𝑥𝑖𝑖+1 ]. However,
 Derivatives of the interpolant do not necessarily agree with those of the function
it is approximating, even at the nodes.
 There is not a sufficient number of constants to ensure that the conditions at the
end-points will be satisfied.
 At least at one end-point, the derivative of the interpolant is imposed (out of control).
Piecewise-Polynomial Approximation:
Cubic Splines
 Remarks (cont.).
 The most common piecewise-polynomial approximation uses cubic polynomials
between each successive pair of nodes and is called cubic spline interpolation.
 A general cubic polynomial involves four constants
 There is sufficient flexibility in the cubic spline procedure to ensure that the interpolant is
not only continuously differentiable on the interval, but also has a continuous second
derivative.
 As in the quadratic spline, the construction of the cubic spline does not assume
that the derivatives of the interpolant agree with those of the function it is
approximating, even at the nodes.
 In contrast to the quadratic spline, there is sufficient control on the interpolant
at the end-points.
Cubic Splines
 Definition. Given a function 𝑓𝑓 defined on [𝑎𝑎, 𝑏𝑏] and a set of nodes 𝑎𝑎 = 𝑥𝑥0 <
𝑥𝑥1 < ⋯ < 𝑥𝑥𝑁𝑁 = 𝑏𝑏, a cubic spline interpolant 𝑆𝑆 for 𝑓𝑓 is a function that
satisfies:

 𝑆𝑆(𝑥𝑥) is a cubic polynomial, denoted 𝑆𝑆𝑗𝑗 (𝑥𝑥), on [𝑥𝑥𝑗𝑗 , 𝑥𝑥𝑗𝑗+1 ] for 𝑗𝑗 = 0, 1, . . . , 𝑁𝑁 − 1;


 𝑆𝑆𝑗𝑗 𝑥𝑥𝑗𝑗 = 𝑓𝑓 𝑥𝑥𝑗𝑗 and 𝑆𝑆𝑗𝑗 𝑥𝑥𝑗𝑗+1 = 𝑓𝑓 𝑥𝑥𝑗𝑗+1 for 𝑗𝑗 = 0, 1, . . . , 𝑁𝑁 − 2;

 𝑆𝑆𝑗𝑗+1 𝑥𝑥𝑗𝑗+1 = 𝑆𝑆𝑗𝑗′ 𝑥𝑥𝑗𝑗+1 for 𝑗𝑗 = 0, 1, . . . , 𝑁𝑁 − 2 implied by the previouse ;
′′
 𝑆𝑆𝑗𝑗+1 𝑥𝑥𝑗𝑗+1 = 𝑆𝑆𝑗𝑗′′ 𝑥𝑥𝑗𝑗+1 for 𝑗𝑗 = 0, 1, . . . , 𝑁𝑁 − 2
 One of the following boundary conditions is satisfied:
 𝑆𝑆 ′′ 𝑥𝑥0 = 𝑆𝑆 ′′ 𝑥𝑥𝑁𝑁 = 0 𝑛𝑛𝑛𝑛𝑛𝑛𝑛𝑛𝑛𝑛𝑛𝑛𝑛𝑛 or 𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓 boundary
 𝑆𝑆 ′ 𝑥𝑥0 = 𝑓𝑓 ′ 𝑥𝑥0 and 𝑆𝑆 ′ 𝑥𝑥𝑁𝑁 = 𝑓𝑓 ′ 𝑥𝑥𝑁𝑁 𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐 boundary
Cubic Splines (cont.)
Cubic Splines (cont.)
 Remarks.
 Cubic splines can be defined with other BCs.

 When the free BC occur, the spline is called a natural spline, and its
graph approximates the shape that a long flexible rod would assume
if forced to go through the data points.

 In general, clamped BCs lead to more accurate approximations


because they include more information about the function.
 For this type of BC to hold, it is necessary to have either the values of the
derivative at the endpoints or an accurate approximation to those values.
Construction of Natural Cubic Spline:
Pseudocode
Construction of Natural Cubic Spline:
Pseudocode
Cubic Spline:
Uniqueness
 Theorem. If 𝑓𝑓 is defined at 𝑎𝑎 = 𝑥𝑥0 < 𝑥𝑥1 < ⋯ < 𝑥𝑥𝑁𝑁 = 𝑏𝑏, then 𝑓𝑓 has a
unique natural spline interpolant 𝑆𝑆 on the nodes 𝑥𝑥0 , 𝑥𝑥1 , ⋯ , 𝑥𝑥𝑁𝑁 .

 Theorem. If 𝑓𝑓 is defined at 𝑎𝑎 = 𝑥𝑥0 < 𝑥𝑥1 < ⋯ < 𝑥𝑥𝑁𝑁 = 𝑏𝑏 and differentiable
at 𝑎𝑎 and 𝑏𝑏, then 𝑓𝑓 has a unique clamped spline interpolant 𝑆𝑆 on the
nodes 𝑥𝑥0 , 𝑥𝑥1 , ⋯ , 𝑥𝑥𝑁𝑁 .

You might also like