You are on page 1of 12

Lecture notes on Variational and Approximate Methods in Applied Mathematics - A Peirce UBC 1

Lecture 4: Piecewise Cubic Interpolation

(Compiled 15 September 2012)

In this lecture we consider piecewise cubic interpolation in which a cubic polynomial approximation is assumed over
each subinterval. In order to obtain sufficient information to determine these coefficients, we require continuity of the
interpolating polynomials in neighboring intervals as well as the continuity of a number of derivatives. Depending on
the number of derivatives that we require to be continuous at the ”stitching points” we obtain different approximation
schemes in which additional data about the function f (x) being approximated might have to be furnished in order that
there is sufficient data to determine the coefficients of the cubic polynomials.

Key Concepts: Piecewise cubic interpolation, Cubic Splines, Cubic Hermite Interpolation.

4 Piecewise Cubic Interpolation


4.1 Degree of freedom analysis of piecewise cubic interpolants

Consider the domain [a, b] that is partitioned into N intervals having N + 1 nodes and N − 1 internal nodes. In each
of these subintervals assume that different a cubic polynomial is to be constructed. Let p3,N (x) be the combination
of all these cubic polynomials. We now discuss the alternative approximation schemes that one obtains depending
on the different schemes of constraint.
Schemes of constraint:

(1) Piecewise Cubic Hermite polynomials: p3,N (x) and p03,N (x) are continuous at interior nodes.
There are four unknown coefficients for each of the N intervals and 2(N − 1) constraints due to the continuity
requirements on p3,N (x) and p03,N (x).

⇒ DOF : 4N − 2(N − 1) = 2(N + 1)


⇒ specify function value and its derivative at all N + 1 nodes

• Have to specify f & f 0 at all N + 1 nodes!

(2) Cubic Spline: p3,N (x), p03,N (x), and p003,N (x) are all continuous at interior points.

⇒ DOF : 4N − 3(N − 1) = N + 3 = N + 1 +2
| {z }
⇒ specify f at all N + 1 nodes
and impose 2 EXTRA CONDITIONS

The extra conditions are up to the user to prescribe depending on the application, e.g. p003 (x0 ) = 0 = p003 (xN )
which is called the natural spline.
2
4.2 Piecewise Cubic Hermite polynomials

x0 x1 xN
=a =L

DOF: 4N − 2(N − 1) = 2(N + 1) ⇒ prescribe f (xi ) and f 0 (xi ) at i = 0, . . . , N .


(0) (1)
Representation of f in terms of Hermite basis functions hi (x) and hi (x):
N
X N
X
(0) (1)
f (x) ≈ h(x) = f (xi )hi (x) + f 0 (xi )hi (x)
i=0 i=0

where )
(0) d (1)
hi (xj ) = δij and dx hi (xj ) = δij
d (0) (1) (1)
dx hi (xj ) = 0 hi (xj ) =0
Constructing basis functions on the canonical interval [−1, 1]:

(0) (0)
h1 h2
We use the linear Lagrange basis func-
tions
1
Na1 (ξ) = (1+ξa ξ) : Na1 (ξb ) = δab , ξa,b = ±1 (1)
h1
2

Let -1 0 1
ξ
(1)
(0) (0) h2
h1 (ξ) = (α1 ξ + β1 )[N11 (ξ)]2 ; h2 (ξ) = (α2 ξ + β)[N21 (ξ)]2
(1) (1)
h1 (ξ) = (γ1 ξ + δ1 )[N11 (ξ)]2 ; h2 (ξ) = (γ2 ξ + δ2 )[N21 (ξ)]2

To find αi , βi , γi and δi we impose the conditions (1):


(0) (0)0 2 (−1)
1= h1 (−1) = β1 − α1 0 = h1 (−1) = α1 1 + (β1 − α1 ) (1 − (−1)) = 2α1 − β1
2 2
∴ α1 = 1 and β1 = 2
(0)
⇒ h1 (ξ) = 14 (2 + ξ)(1 − ξ)2
(0)
Similarly h2 (ξ) = 14 (2 − ξ)(1 + ξ)2

For the derivative basis functions


)
(1)
0 = h1 (−1) = (δ1 − γ1 ) (1)
(1) ⇒ δ1 = γ1 = 1 ⇒ h1 (ξ) = 41 (1 + ξ)(1 − ξ)2
1 = h1 (−1) = 2γ1 − δ1 )
(1)
Similarly h2 (ξ) = 14 (ξ − 1)(1 + ξ)2
Interpolation 3
Expressions for basis functions on an arbitrary interval [xi , xi+1 ].

(1) (1)
Use the linear transformation x(ξ) = xi N1 (ξ) + xi+1 N2 (ξ)
1 1
= xi (1 − ξ) + xi+1 (1 + ξ)
µ 2 ¶ 2
xi + xi+1 (xi+1 − xi )
= + ξ
2 2
2x − (xi + xi+1 ) 2x − (xi + xi+1 )
The inverse transformation is: ξ(x) = =
(xi+1 − xi ) ∆xi

xi+1 − xi + 2x − xi − xi+1 2(x − xi ) ∆xi + 2(x − xi )


1+ξ = = ⇒2+ξ =
xi+1 − xi (xi+1 − xi ) ∆xi
2(xi+1 − x) ∆xi + 2(xi+1 − x)
1−ξ = ⇒ (2 − ξ) =
xi+1 − xi ∆xi

(0) [∆xi + 2 (x − xi )] (xi+1 − x)2


∴ hi (x) = (4.1)
(∆xi )3
(0) [∆xi + 2 (xi+1 − x)] (x − xi )2
hi+1 (x) = (4.2)
(∆xi )3
(1) (x − xi )(xi+1 − x)2
hi (x) = (4.3)
(∆xi )2
(1) (xi+1 − x)(x − xi )2
hi+1 (x) = − (4.4)
(∆xi )2
Here ∆xi = xi+1 − xi and observe that
d hi d hi dx
(ξ) = (ξ(x)) ·
dξ dx dξ
d hi ∆xi
= (ξ(x)) ·
dx 2

Error involved:
For function values the error is given by:
4
|f (x) − h(x)| ≤ ||f (4) ||∞ ∆x
384
while for derivatives the error is :

3∆x3
|f 0 (x) − h0 (x)| ≤ ||f (4) ||∞ 216
4
4.3 Piecewise Cubic Spline interpolation

NDOF: 4N − 3(N − 1) = N + 1 + 2 ⇒ specify f (xi ) at x0 , . . . , xN .


+ 2 extra conditions

4.3.1 Derivation using Cubic Hermie interpolation

Since we have similar piecewise cubic polynomials to the Piecewise Cubic Hermite polynomials on each subinterval
but with additional continuity required at the N − 1 interior nodes, our starting point is the Hermite cubic basis
expansion. We then impose additional conditions to make up for the derivatives f 0 (xi ) which are not known (or
required) in the case of splines.

On [xk , xk+1 ] xk−1 xk xk+1

[∆xk + 2 (x − xk )] (xk+1 − x)2 [∆xk + 2 (xk+1 − x)] (x − xk )2


s(x) = fk + f k+1
(∆xk )3 (∆xk )3
2 2
(x − xk )(xk+1 − x) (x − xk+1 )(x − xk )
+s0k + s0k+1
(∆xk )2 (∆xk )2
where the fk0 and fk+1
0
from the Hermite expansion have been replaced by the unknown quantities s0k and s0k+1 which
are to be determined by a system of equations which ensure that s00 (x) is continuous at internal nodes.
The first and second derivatives of s(x) must be continuous at the interieor points xj , j = 1 . . . N − 1. Continuity
of the first derivative is already obtained by our choice of basis functions. So we apply continuity of s00 (x) to get
equations for the coefficients s0k . That is, we calculate s00 (x) on the two intervals [xk−1 , xk ] and [xk , xk+1 ] and require
continuity at xk . After some algebra.

∆xk s0k−1 + 2(∆xk + ∆xk−1 )s0k + ∆xk−1 s0k+1 = 3(f [xk , xk+1 ]∆xk−1 + f [xk−1 , xk ]∆xk )

We have N − 1 equations and (N + 1) unknowns s00 , s01 , . . . , s0N so we need 2 more conditions. Say we specify

(I.) f00 = s00 and s0N = fN 0


then on a uniform mesh ∆xk = ∆x:
      
4 1 0 ... 0 s01 f [x1 , x2 ] + f [x0 , x1 ] s00
 1 −
 4 1 0 ... 0 
 s0 
2 

 f [x2 , x3 ] + f [x1 , x2 ] 





 0 1 4 1      .. 
      . 
 .. ..   .   ..   
 .   .     
 0 .  .   .   
 .   = 3    
 . ..      
 . .      
   ..   ..   .. 
 0   .   .   . 
      
 1      

0 ... 0 1 4 s0N −1 f [xN −1 , xN ] + f [xN −2 , xN −1 ] s0N

A tridiagonal system of equations – easy to solve!


Interpolation 5
4.3.2 Alternative cubic spline derivation for derivative primary variables
yi
yi+1

Yi (x)

xi xi+1

Let Yi (x) = ai (x − xi )3 + bi (x − xi )2 + ci (x − xi ) + di
Yi0 (x) = 3ai (x − xi )2 + 2bi (x − xi ) + ci
Yi00 (x) = 6ai (x − xi ) + 2bi
yi = Yi (xi ) = di yi+1 = Yi (xi+1 ) = ai h3i + bi h2i + ci hi + yi where hi = xi+1 − xi .

Let s0i = Yi0 (xi ) = ci s0i+1 = Yi0 (xi+1 ) = 3ai h2i + 2bi hi + s0i
Yi00 (xi ) = 2bi = Yi−100
(xi ) = 6ai−1 hi−1 + 2bi−1
· 3 2
¸· ¸ · ¸
hi hi ai yi+1 − yi − s0i hi
=
3h2i 2hi bi s0i+1 − s0i
Á Á
ai = 2hi (yi+1 − yi − si hi ) (−hi ) − (si+1 − si )hi (−h4i )
0 4 0 0 2

n oÁ
3 0 0 2 0
bi = hi (si+1 − si ) − 3hi (yi+1 − yi − si hi ) (−h4i )
µ ¶
yi+1 − yi s0i+1 + s0i
∴ ai = −2 +
h3i h2
µ ¶ µ 0 i ¶
yi+1 − yi si+1 + 2s0i
bi = 3 −
h2i hi
µ 0 ¶
6 ∆yi 2 ¡ 0 ¢ −12 ∆yi−1 s + s0i−1 6 ∆yi−1 (s0 + 2s0i−1 )
∴ − si+1 + 2s0i = +6 i + −2 i
hi hi hi hi−1 hi−1 hi−1 hi−1 hi−1 hi−1

∆yi ∆yi−1
∴ 6( hi−1+ hi ) = 2hi−1 s0i+1 + 4hi−1 s0i + 4hi s0i + 2hi s0i−1
hi hi−1

∴ hi−1 s0i+1 + 2(hi−1 + hi )s0i + hi s0i−1 = 3(f [xi−1 , xi ]hi + f [xi , xi+1 ]hi−1 ).
6
4.3.3 Another spline derivation with s00i as primary variables
yi−1 yi+1
yi

Yi−1 (x) Yi (x)


Yi+1 (x)

hi

xi−1 xi xi+1

Let Yi (x) = ai (x − xi )3 + bi (x − xi )2 + ci (x − xi ) + di
Yi0 (x) = 3ai (x − xi )2 + 2bi (x − xi ) + ci
Yi00 (x) = 6ai (x − xi ) + 2bi
at xi : yi = Yi (xi ) = di ← interpolates the function at xi (4.5)
yi+1 = Yi (xi+1 ) = ai h3i + bi h2i + ci hi + yi ← enforce continuity (4.6)

Introduce primary variable : s00i = Yi00 (xi ) = 2bi ⇒ bi = s00i /2 (4.7)

s00
i+1 −si
00
Build in continuity of Y 00 ⇒ s00i+1 = Yi00 (xi+1 ) = 6ai hi + s00i ⇒ ai = 6hi (4.8)
µ ¶
s00i+1 − s00i s00
∴ Yi (x) = (x − xi )3 + (x − xi )2 + ci (x − xi ) + yi
6hi 2
µ 00 00 ¶ 00
si+1 − si s
(2) ⇒ yi+1 = h3i + i h2i + ci hi + yi
6hi 2
µ ¶ µ 00 ¶
yi+1 − yi si+1 − s00i s00
ci = − hi − i hi
hi 6 2
µ 00 00 ¶
∆yi si+1 + 2si
= − hi
hi 6
Impose continuity of first derivatives:

Yi0 (xi ) = 3ai (xi − xi )2 + 2bi (xi − xi ) + ci = ci


0
Yi−1 (xi ) = 3ai−1 h2i−1 + 2bi−1 hi−1 + ci−1
µ ¶ µ 00 ¶ ½ µ 00 ¶ ¾
∆yi s00i+1 + 2si00 si − s00i−1 2 00 ∆yi−1 si + 2s00i−1
∴ ci = − hi = 3 hi−1 + si−1 hi−1 + − hi−1
hi 6 6hi−1 hi−1 6

³ ´
∆yi ∆yi−1
hi−1 s00i−1 (−3 + 6 − 2) + (2hi + 2hi−1 )s00i + hi s00i+1 =6 hi − hi−1

or
³ ´
∆yi ∆yi−1
hi−1 s00i−1 + (2hi + 2hi−1 )s00i + hi s00i+1 =6 hi − hi−1

i = 1, . . . N − 1 N − 1 EQ
2 EXTRA CONDITIONS
Interpolation 7
4.3.4 Extra Conditions
yn−1 (x)
y0 y1
h0 hn−1
x0 x1 xN −1 XN

(1) Natural Spline: s000 = 0 = s00N two extra condtions

  s001

 
(2h0 + 2h1 ) h1 y2 −y1
− y1 −y0
 h1  s002  h1 h0
 (2h 1 + 2h2 ) h2    y3 −y2
− y2 −y1 
    h2 h1 
    
  ..   
  .
  .. 
 .   
 = 6 .

 . .. ..  
 . . .    .. 
  ..
  
    . 
  .   
 hN −2 



 
yN −yN −1 yN −1 −yN −2
hN −2 (2hN −2 + 2hN −1 ) −
s00N −1 hN −1 hN −2

(2) Clamped Spline: Specified first derivatives

Given f 0 (x0 ) = A and f 0 (xn ) = B.


y1 − y0
00
2h0 s0 + h0 s1
00 ³ ´
A = Y00 (x0 ) = c0 = − = A ⇒ 2h0 s000 + h0 s001 = 6 y1h−y 0
− A
h0 6 0

B = YN0 −1 (xn ) = 3an−1 h2n−1 + 2bn−1 hn−1 + cn−1


µ ¶ µ ¶
sn − sn−1 yn − yn−1 2hn−1 s00n−1 + hn−1 s00n
=3 h2n−1 + sn−1 hn−1 + −
6hn−1 hn−1 6
µ ¶
yn − yn−1
6 B− = 3hn−1 s00n − 3hn−1 s00n−1 + 6hn−1 s00n−1 − 2hn−1 s00n−1 − hn−1 s00n
hn−1
³ ´
6 B − ynh−y
n−1
n−1
= 2hn−1 s00n−1 + 2hn−1 s00n

But h0 s000 + (2h0 + 2h1 )s001 + h1 s002 = 6 {[f [x1 , x2 ] − f [x0 , x1 ]}

    
2h0 h0 s000 (y1 − y0 )/h0 − A
 h0 (2h0 + 2h1 ) h1  s001   (y2 − y1 )/h1 − y1h−y 0 
    0 
    
    
    .. 
    
   = 6 . 
    .. 
    
    . 
   00   
 hn−2 (2hn−2 + 2hn−1 ) hn−1   sN −1   (yn − yn−1 )/hn−1 − (yn−1 − yn−2 )/hn−2 
hn−1 2hn−1 s00N B − yny −y n−1
hn−1
8
3. Quadratic boundary interval representation

s000 = s001 s00N −1 = s00N

³ ´
s00
1 −s0
00 s00 00
N −sN −1
a0 = 6h0 =0 an−1 = 6hN −1
∴ a quadratic a quadratic

   s00   
(3h0 + 2h1 ) h1 0 1 f [x1 , x2 ] − f [x0 , x1 ]
 h1 (2h + 2h ) h 0 0   s002   
 1 2 2 
 .   
  . 
  .  = 6



 
(2hN −3 + 2hN −2 )hN −2     
hN −2 (2hN −2 + 3hN −1 ) s00N −1 f [xN −1 , xN ) − f [xN −2 , xN −1 ]
4. Linear extrapolation

S 00 (x)

S 00 2

S 00 1

S 00 0

x0 x1 x2

s001 − s000 s00 − s001 h0 (h1 + h0 ) h0


= 2 ⇒ s000 = s001 − (s002 − s001 ) = s001 − s002
h0 h1 h1 h1 h1
00 00 00
h0 s0 + (2h0 + 2h1 )s1 + h1 s1 = 6(f [x1 , x2 ] − f [x0 , x1 ])
(h0 + h1 ) 00 h2 h1
h0 s1 − s002 0 + 2(h0 + h1 )s100 + h1 s002 = RHS
h1 h1 h
µ1 2 ¶
(h0 + h1 ) 00 h1 − h20
∴ (h0 + 2h1 )s1 + s002 = RHS
h1 h1
  
(h0 +h1 )
(h0 + 2h1 )
(h20 −h20 )
0 ... s001
 h1 h1   s00 
 h1 (2h1 + 2h2 ) h2 0  2 
..
0 .
Interpolation 9
5. Not-a-knot condition

Y0 (x) ≡ Y1 (x) YN −2 (x) ≡ YN −1 (x)

Unknowns = 4(N − 2)
Constraints = 3(N − 3)

4(N − 2) − 3(N − 3) = N + 1 unknowns ←→ the values at x0 , . . . , xN .

s00i−1 hi−1 + 2(hi−1 + hi )s00i + hi s00i+1 = 6(f [x1 , x2 ] − f [x0 , x1 ])


Y1 (x) = a1 (x − x1 )3 + b1 (x − x1 )2 + c1 (x − x1 ) + d1
Y10 (x) = 3a1 (x − x1 )2 + b1 (x − x1 ) + c1
Y100 (x) = 6a1 (x − x1 ) + 2b1 , x 1 − x 0 = h0
µ 00 00

s − s
s000 = Y100 (x0 ) = 6 2 1
(x0 − x1 ) + 2(s001 /2)
6h1
h0
= −(s002 − s001 ) + s001
h1
(h1 + h0 ) h0
∴ s000 = s001 − s002
h1 h1
But h0 s000 + 2(h0 + h1 )s001 + h1 s002 = 6(f [x1 , x2 ] − f [x0 , x1 ])
µ ¶ µ ¶
h0 00 h0
∴ 2+ (h0 + h1 )s1 + 1 − (h0 + h1 )s002 = 6(f [x1 , x2 ] − f [x0 , x1 ])
h1 h1
µ ¶ µ ¶
hN −1 00 hN −1
Also 2 + (hN −2 + hN −1 )sN −1 + 1 − (hN −2 + hN −1 )s00N −2 = 6(f [xN −1 , xN ] − f [xN −2 , xN −1 ])
hN −2 hN −2

 h0 
(2 + h1 )(h0 + h1 ) (1 − hh10 )(h1 + h0 ) 0 ... 0 
s001

 h1 2(h1 + h2 ) h2 0 ... 
0   s00
 
 0  2 
   .. 
  . 
  
   s00 
 hN −2  N −2
(1 − hN −1 hN −1 s00N −1
hN −2 )(hN −2 + hN −1 ) (2 + hN −2 )(hN −2 + hN −1 )
6. A periodic spline:

s00 (x0+ ) = s00 (xN − )


s00 (x0+ ) = s00 (xN − ).
10
(III) Smoothness property of a natural spline s00 (x0 ) = 0 = s00 (xN )

In order to impose this condition it is convenient to consider the s00k as unknowns in which case the equations become:

∆xk s00k−1 + 2(∆xk + ∆xk+1 )s00k + ∆xk+1 s00k+1 = 6(f [xk , xk+1 ] − f [xk−1 , xk ]) k = 1, . . . , N − 1.

Important identity: (y 00 − s00 )[(y 00 − s00 ) + 2s00 ] = (y 00 − s00 )(y 00 + s00 ) = (y 00 )2 − (s00 )2

NOTE:

(1) Let y(x) be any other interpolant of f (x) at (x0 , . . . , xN ) then


Zb Zb Zb Zb
00
(y 00 )2 dx − (s 2 )dx = (y 00 − s00 )2 dx + 2 s00 (y 00 − s00 )dx.
a a a a
Zb ¯b N Zxk
¯ X
00 00 00 00 0 0 ¯
Now s (y − s )dx = s (y − s )¯ − s000 (y 0 − s0 )dx s000 = const on each subinterval
a k=1 x
a k−1
¯b N ¯x k
¯ X ¯
0 ¯
00 0
= s (y − s )¯ − ck (y − s)¯¯ both interpolants
a k=1 xk−1
¯b
¯
= s (y − s )¯¯
00 0 0

Rb
If we choose s : s00 (a) = 0 = s00 (b) for example or if y and s both interpolate f 0 at a and b then s00 (y 00 −s00 )dx =
a
0.
Zb Zb Zb Zb
00 00
2 00 00 2 00 2
∴ y dx = (y − s ) dx + (s ) dx ≥ s 2 dx.
a a a a
Thus s is the interpolant with the MINIMUM CURVATURE (i.e. smoothest)
(2) Error involved in spline interpolation:
∆x̄4
|f (x) = s(x)| ≤ ||f (4) ||∞ 5 ∆x̄ = max ∆x : for nonuniform points and all x ∈ [x0 , xN ]
384
3
∆x̄
|f 0 (x) − s0 (x)| ≤ ||f (4) ||∞ for nonuniform points and all x ∈ [x0 , xN ]
24
4
∆x
|f 0 (xi ) − s0 (xi )| ≤ ||f (5) ||∞ for uniform sample points xi
60
∴ cubic spline provides an excellent technique for NUMERICAL DIFFERENTIATION.
Interpolation 11
How do we solve for the {s00k }?

 
d1 c1    
 a2 d2 c2 0  x1 b1
   x2   
 0 a3 d3    
    
    
    
    
 .. ..  = 
 . .    
    
 0 dn−1 cn−1    
    
 ..    
 . 
xn bn
an dn

d1 6= 0 d1 x1 + c1 x2 = b1 (4.1)
a2 x1 + d2 x2 + c2 x3 = b2 (4.2)
µ ¶
a2 a2 a2
(2) − (1) ⇒ d2 − c1 x2 + c2 x3 = b2 − b1
d1 d1 d1
a2
d02 x2 + c2 x3 = b02 d02 = d2 − c1
d1
a2
b02 = b2 − b1
d1

Similarly

d0k+1 xk+1 + ck+1 xk+2 = b0k+1 (4.3)


ak+1 ak+1
where d0k+1 = dk+1 − 0 ck b0k+1 = bk+1 − 0 b0k (4.4)
dk dk

    
d01 c1 x1 b01
 d02 c2  ..   b02 
  .   
  = 
  ..   
 d0n−1 cn−1  .   
d0n xn b0n

Back Substitution

xn = b0n /d0n
xn−1 = (b0n−1 − cn−1 x)/d0n−1

xn = b0n /d0n (4.5)


xk = (b0k − ck xk+1 )/d0k k = n − 1, . . . , 1 (4.6)
12
ak
Note, if we let mk = d0k−1 then
 
..  0 
1 . 0  
  d1 c1 0
LU
 ..  .. 
 m2 .  .   Forward Ly =b y = L−1 b 
A=



 = LU 
  Back


  0 ..  U x =y
 0  . cn−1
Substitution
d0n
mn 1

You might also like