Docsity

Cubic Splines - Lecture Slides - Numerical Analysis | MATH 375, Study notes of Mathematical Methods for Numerical Analysis and Optimization

Partial preview of the text

Download Cubic Splines - Lecture Slides - Numerical Analysis | MATH 375 and more Study notes Mathematical Methods for Numerical Analysis and Optimization in PDF only on Docsity!

Cubic Splines

MATH 375

J. Robert Buchanan

Department of Mathematics

Fall 2006

Introduction

Given data {(x 0 , f (x 0 )), (x 1 , f (x 1 )),... , (xn, f (xn))} which we

wish to interpolate using a polynomial...

Lagrange interpolating polynomial of degree n,

Determine n + 1 coefficients,

Error term can be difficult to construct and measure.

Interpolate piecewise,

Piecewise linear result not differentiable at xi ,

i = 0 , 1 ,... , n,

Piecewise quadratic not twice differentiable at xi ,

i = 0 , 1 ,... , n,

Piecewise cubic!

General Form

For j = 0 , 1 ,... , n − 1 assume

Sj (x) = aj + bj (x − xj ) + cj (x − xj )

2

  • dj (x − xj )

3 .

We must find aj , bj , cj and dj subject to the conditions specified

in the definition.

Let hj = xj+ 1 − xj then

Sj (xj ) = aj = f (xj )

Sj+ 1 (xj+ 1 ) = aj+ 1 = Sj (xj+ 1 ) = aj + bj hj + cj h

2 j +^ dj^ h

3 j

So far we know aj for j = 0 , 1 ,... , n − 1 and have n equations

and 3n unknowns.

First Derivative

For j = 0 , 1 ,... , n − 1 we have

S

′ j (x) =^ bj^ +^2 cj^ (x^ −^ xj^ ) +^3 dj^ (x^ −^ xj^ )

2 .

Thus

S

′ j (xj^ )^ =^ bj

S

′ j+ 1 (xj+^1 )^ =^ bj+^1 =^ S

′ j (xj+^1 ) =^ bj^ +^2 cj^ hj^ +^3 dj^ h

2 j

Now we have 2n equations and 3n unknowns.

Summary of Equations

For j = 0 , 1 ,... , n − 1 we have

aj+ 1 = aj + bj hj + cj h

2 j +^ dj^ h

3 j

bj+ 1 = bj + 2 cj hj + 3 dj h

2 j

cj+ 1 = cj + 3 dj hj.

Note: The quantities aj and hj are known.

Solve the third equation for dj and substitute into the other two

equations.

Solving the Equations

dj =

cj+ 1 − cj

3 hj

aj+ 1 = aj + bj hj + cj h

2 j +

cj+ 1 − cj

3 hj

h

3 j

= aj + bj hj +

h

2 j

3

( 2 cj + cj+ 1 )

bj+ 1 = bj + 2 cj hj + 3

cj+ 1 − cj

3 hj

h

2 j

= bj + hj (cj + cj+ 1 )

Solve the second equation for bj.

Solution (continued)

hj

(aj+ 1 − aj ) −

hj

( 2 cj + cj+ 1 ) =

hj− 1

(aj − aj− 1 ) −

hj− 1

( 2 cj− 1 + cj )

  • hj− 1 (cj− 1 + cj )

Collect all terms involving c to one side.

hj− 1 cj− 1 + 2 cj (hj− 1 +hj )+hj cj+ 1 =

hj

(aj+ 1 −aj )−

hj− 1

(aj −aj− 1 )

We have n − 1 equations of this form and n + 1 unknowns.

Natural Boundary Conditions

If S

′′ (x 0 ) = S

′′ 0 (x^0 ) =^2 c^0 =^ 0 then^ c^0 =^ 0 and if S

′′ (xn) = S

′′ n− 1

(xn) = 2 cn = 0 then cn = 0.

Theorem

If f is defined at a = x 0 < x 1 < · · · < xn = b then f has a unique

natural cubic spline interpolant.

Natural BC Linear System (continued)

A

c 0

c 1

c 2

. . .

cn− 1

cn

3 h 1

(a 2 − a 1 ) −

3 h 0

(a 1 − a 0 )

3 h 2 (a^3 −^ a^2 )^ −^

3 h 1 (a^2 −^ a^1 ) . . . 3 hn− 1

(an − an− 1 ) −

3 hn− 2

(an− 1 − an− 2 )

Clamped Boundary Conditions

If S

′ (a) = S

′ 0

(a) = f

′ (a) = b 0 then

f

′ (a) =

h 0

(a 1 − a 0 ) −

h 0

3

( 2 c 0 + c 1 )

which is equivalent to

h 0 ( 2 c 0 + c 1 ) =

h 0

(a 1 − a 0 ) − 3 f

′ (a).

Clamped BC Linear System

In matrix form the system of n + 1 equations has the form

A c = y where

A =

2 h 0 h 0 0 0 · · · 0

h 0 2 (h 0 + h 1 ) h 1 0 · · · 0

0 h 1 2 (h 1 + h 2 ) h 2 · · · 0

. . .

0 0 0 hn− 2 2 (hn− 2 + hn− 1 ) hn− 1

0 0 0 · · · hn− 1 2 hn− 1

Note: A is a tridiagonal matrix.

Clamped BC Linear System (continued)

A

c 0

c 1

c 2

. . .

cn− 1

cn

3 h 0

(a 1 − a 0 ) − 3 f

′ (a)

3 h 1

(a 2 − a 1 ) −

3 h 0

(a 1 − a 0 )

3 h 2

(a 3 − a 2 ) −

3 h 1

(a 2 − a 1 )

. . . 3 hn− 1

(an − an− 1 ) −

3 hn− 2

(an− 1 − an− 2 )

3 f

′ (b) −

3 hn− 1

(an − an− 1 )

Natural Cubic Spline Example

Consider the following data:

x f (x)

− 0. 5 − 0. 02475

− 0. 25 0. 334938

  1. 0 1. 101

The coefficients of the natural cubic spline interpolant are

a b c d

− 0. 02475 1. 03238 0. 0 6. 502

  1. 334938 2. 2515 4. 8765 − 6. 502

Natural Cubic Spline Example (continued)

-0.5 -0.4 -0.3 -0.2 -0.

x

1

fHxL