Docsity

Natural cubic splines, Exams of Numerical Methods in Engineering

Partial preview of the text

Download Natural cubic splines and more Exams Numerical Methods in Engineering in PDF only on Docsity!

Natural cubic splines

Arne Morten Kvarving

Department of Mathematical Sciences

Norwegian University of Science and Technology

October 21 2008

Motivation

  • We are given a “large” dataset, i.e. a function sampled in

many points.

  • We want to find an approximation in-between these points.
  • (^) Until now we have seen one way to do this, namely high order

interpolation - we express the solution over the whole domain

as one polynomial of degree N for N + 1 data points.

a = t 0 t 1 t 2 t 3 tn− 1 b = tn x

Motivation

−5 −4 −3 −2 −1 0 1 2 3 4 5

0

1

Figure: Runge’s example plotted on a grid with 100 equidistantly spaced

grid points.

Motivation

−5 −4 −3 −2 −1 0 1 2 3 4 5

−

0

1

2

3

4

5

6

7

8

exact interpolated

Figure: Runge’s example interpolated using a 15th order polynomial

based on equidistant sample points.

Motivation

−5 −4 −3 −2 −1 0 1 2 3 4 5

0

1

Figure: Runge’s example interpolated using piecewise linear interpolation.

We have used 7 points to interpolate the function in order to ensure that

we can actually see the discontinuities on the plot.

A better strategy - spline interpolation

  • (^) We would like to avoid the Runge phenomenon for large

datasets ⇒ we cannot do higher order interpolation.

  • (^) The solution to this is using piecewise polynomial

interpolation.

  • However piecewise linear is not a good choice as the regularity

of the solution is only C

0 .

  • These desires lead to splines and spline interpolation.

t 1 t 2 t 3 tn− 1 x

s 1 (x) s 2 (x) s 0 (x)

sn− 1 (x)

a = t 0 b = tn

Cubic spline

S(x) =

S 0 (x) = a 0 x

3

  • b 0 x

2

  • c 0 x + d 0 , t 0 ≤ x ≤ t 1

. . .

Sn− 1 (x) = an− 1 x

3

  • bn− 1 x

2

  • cn− 1 x + dn− 1 , tn− 1 ≤ x ≤ tn.

which satisfies

S(x) ∈ C

2 [t 0 , tn] :

Si− 1 (xi ) = Si (xi )

S

′ i− 1 (xi^ ) =^ S

′ i (xi^ )

S

′′ i− 1 (xi^ ) =^ S

′′ i (xi^ )

, i = 1, 2 , · · · , n − 1.

Cubic spline - interpolation

Given (xi , yi )

n i=

. Task: Find S(x) such that it is a cubic spline

interpolant.

  • (^) The requirement that it is to be a cubic spline gives us

3(n − 1) equations.

  • (^) In addition we require that

S(xi ) = yi , i = 0, · · · , n

which gives n + 1 equations.

  • This means we have 4n − 2 equations in total.
  • (^) We have 4n degrees of freedom (ai , bi , ci , di )

n− 1 i=.

  • Thus we have 2 degrees of freedom left.

Natural cubic splines

Task: Find S(x) such that it is a natural cubic spline.

  • Let ti = xi , i = 0, · · · , n.
  • (^) Let zi = S′′(xi ), i = 0, · · · , n. This means the condition that

it is a natural cubic spline is simply expressed as z 0 = zn = 0.

  • (^) Now, since S(x) is a third order polynomial we know that

S

′′ (x) is a linear spline which interpolates (ti , zi ).

  • (^) Hence one strategy is to first construct the linear spline

interpolant S

′′ (x), and then integrate that twice to obtain

S(x).

Natural cubic splines

  • The linear spline is simply expressed as

S

′′ i (x) =^ zi

x − ti+

ti − ti+

  • zi+

x − ti

ti+1 − ti

  • (^) We introduce hi = ti+1 − ti , i = 0, · · · , n which leads to

S

′′ (x) = zi+

x − ti

hi

  • zi

ti+1 − x

hi

  • (^) We now integrate twice

Si (x) =

zi+

6 hi

(x − ti )

3

zi

6 hi

(ti+1 − x)

3

  • Ci (x − ti ) + Di (ti+1 − x).

Natural cubic splines

  • (^) We insert these expressions to find the following form of the

system

Si (x) =

zi+

6 hi

(x − ti )

3

zi

6 hi

(ti+1 − x)

3

yi+

hi

zi+

hi

(x − ti )

yi

hi

hi

zi

(ti+1 − x).

  • (^) We then take the derivative.

Natural cubic splines

  • (^) The derivative reads

S

′ i (x) =^

zi+

2 hi

(x − ti )

2 −

zi

2 hi

(ti+1 − x)

2

hi

(yi+1 − yi )

︸ ︷︷ ︸ bi

hi

(zi+1 − zi ).

  • (^) In our abscissas this gives

S

′ i (ti^ ) =^ −^

zi hi + bi −

hi

zi+1 +

hi zi

S

′ i (ti+1) =^

zi+

2

hi + bi −

hi

6

zi+1 +

hi zi

Si− 1 (ti ) =

zi hi+1 +

hi− 1 zi− 1 + bi− 1

S

′ i (ti^ ) =^ Si−^1 (ti^ )^ ⇒

6 (bi − bi− 1 ) = hi− 1 z− 1 + 2 (hi− 1 + hi ) zi + hi zi+1.

Natural cubic splines - algorithm

  • (^) Then solve the tridiagonal system

v 1 h 1

h 1 v 2 h 2

h 2 v 3 h 3

.. .

. (^) hn− 2

hn− 2 vn− 1

z 1

z 2

z 3

. . .

zn− 2

zn− 1

u 1

u 2

u 3

. . .

un− 2

un− 1

Natural cubic splines - example

  • Given the dataset

i 0 1 2 3

xi 0.9 1.3 1.9 2.

yi 1.3 1.5 1.85 2.

hi = xi+1 − xi 0.4 0.6 0.

bi =

1 hi

(yi+1 − yi ) 0.5 0.5833 1.

vi = 2 (hi− 1 + hi ) 2.0 1.

ui = 6 (bi − bi− 1 ) 0.5 4

  • (^) The linear system reads

[

] [

z 1

z 2

]

[

]