Spline Functions

4.4.2 Spline Functions

The name spline comes from a very old technique in drawing smooth curves in which a thin strip of wood, called a drafting spline, is bent so that it passes through a given set of points; see Figure 4.4.5. The points of interpolation are called knots and the spline is secured at the knots by means of lead weights called ducks. Before the computer age splines were used in all kinds of geometric design to produce sufficiently smooth profiles. This process was slow and expensive.

Figure 4.4.5.

A drafting spline.

The mathematical model of a spline is a special case of the elastic line treated in the theory of elasticity. By Hamilton’s principle the spline assumes a shape y(x) which minimizes the strain energy. This is proportional to the line integral of the square of the curvature

( 1 + (y (x)) )

Since ds =

1 + (y ′ (x)) 2 dx , the energy becomes

b y ′′ (x) 2

E(y) =

dx.

′ (x)) 2 ) 1 + (y 5/2

A mathematical model of the nonlinear spline was given by Daniel Bernoulli (1742) and Euler (1744). 137

A modern description of the development of Bernoulli and Euler is given by Malcolm in [256], where algorithms for computing discrete approximations of nonlinear splines are also discussed and compared. In general these are very costly.

137 Euler derived the differential equation satisfied by an elastic line using techniques now known as calculus of variation and Lagrange multipliers. When Euler did this work Lagrange was still a small child!

418 Chapter 4. Interpolation and Approximation For slowly varying deflections, i.e., when (y ′ (x)) 2 is approximately constant, we have

the approximation

E(y)

≈ const · 2 y ′′ (x) dx.

Under this assumption, y(x) is built up of piecewise cubic polynomials in such a way that y(x) and its two first derivatives are everywhere continuous. Let x i , i = 0 : m, be the points the spline is forced to interpolate. Then the third derivative can have discontinuities at the points x i .

The mathematical concept of spline functions was introduced in 1946 by Schoenberg in the seminal paper [314]. The importance of the B-spline basis for spline approximation (see Sec. 4.4.3) was also first appreciated by Schoenberg. These were not used in practical calculations for general knot sequences until the early seventies, when a stable recurrence relation was established independently by de Boor [36] and Cox [84].

In the following we restrict ourself to consider curves in the plane. Today B-splines enable the mathematical representation of surfaces far beyond hand techniques. In aircraft design computations they may involve more than 50,000 data points.

Linear and Cubic Splines

We start by formally defining a spline function of order k ≥ 1.

Definition 4.4.3.

A spline function s(x) of order k ≥ 1 (degree k − 1 ≥ 0), on a grid

4 = {a = x 0 <x 1 < ···<x m = b}

of distinct knots is a real function s with the following properties: (a) For x ∈ [x i ,x i +1 ], i = 0 : m − 1, s(x) is a polynomial of degree < k.

(b) For k = 1, s(x) is a piecewise constant function. For k ≥ 2, s(x) and its first k − 2 k derivatives are continuous on [a, b], i.e., s(x) ∈ C −2 [a, b].

The space of all spline functions of order k on 4 is denoted by S 4,k . From the definition it follows that if s 1 (x) and s 2 (x) are spline functions of the same degree, so is

c 1 s 1 (x) +c 2 s 2 (x) . Clearly S 4,k is a linear vector space. The space P k of polynomials of degree less than k is a linear subspace of S 4,k . The truncated power functions

(x j ) k −1 j ) −x k + = max{(x − x −1 , 0}, j = 1 : m − 1, introduced in Sec. 3.3.3 in connection with the Peano kernel are also elements of S 4,k .

Theorem 4.4.4.

The monomials and truncated power functions

, . . . , (x −x m −1 ) k −1 + } (4.4.11) form a basis for the spline space S 4,k . In particular, the dimension of this space is k +m−1.

{1, x, . . . , x k −1 , (x −x 1 ) k −1

4.4. Piecewise Polynomial Interpolation 419 Proof. All we need for the first subinterval is a basis of P k , for example, the power basis

{1, x, . . . , x k −1 }. For each additional subinterval [x

+1 , j = 1 : m − 1, we need only add the new basis function (x − x −1

j ,x j )

. It is easy to show that these k + m − 1 functions are linearly independent.

The truncated power basis (4.4.35) has several disadvantages and is not well suited for numerical computations. The basis functions are not local; i.e., they are nonzero on the whole interval [a, b]. Further, they (4.4.35) are almost linearly dependent when the knots are close. Therefore, this basis yields dense ill-conditioned linear systems for various tasks.

A more suitable basis will be introduced in Sec. 4.4.3. The simplest case k = 1 is the linear spline interpolating given values y i = f (x i ) , x i ∈ [a, b], i = 0 : m. This is the broken line

s(x) =q i (x) =y i −1 +d i (x −x i −1 ), x ∈ [x i −1 ,x i ), i = 1 : m. (4.4.12) Here

d i = [x i −1 ,x i ]f (x) = (y i −y i −1 )/ h i , h i =x i −x i −1 , (4.4.13) are the divided differences of f at [x i −1 ,x i ]. By (4.2.16) the error satisfies

|f (x) − s(x)| ≤ max h 2 8 (x) i i max ′′ , (4.4.14)

x ∈[x i −1 ,x i ] |f

| if f ∈ C 2 [a, b]. Hence, we can make the error arbitrarily small by decreasing max i h i .

An important property of interpolation with a linear spline function is that it preserves monotonicity and convexity of the interpolated function.

The broken line interpolating function has a discontinuous first derivative at the knots which makes it unsuitable for many applications. To get better smoothness piecewise polynomials of higher degree need to be used. Cubic spline functions, which interpolate a given function f (x) on the grid 4 and have continuous first and second derivatives, are by far the most important; see Figure 4.4.6.

Figure 4.4.6. Broken line and cubic spline interpolation.

420 Chapter 4. Interpolation and Approximation With piecewise Lagrange–Hermite interpolation we can interpolate given function

values and first derivatives of a function on the grid 4. First recall that in cubic Lagrange– Hermite interpolation (see Theorem 4.3.1 and Problem 4.3.1) a cubic polynomial q i (x) is fit- ted to values of a function and its first derivative at the endpoints of the interval [x i −1 ,x i ) . Let

be a local variable. Then, by (4.3.11) translated to the notation in (4.4.13), the cubic q i (x) can be written in the form

q i (x) = θy i + (1 − θ)y i −1 +h i θ( 1 − θ) [(k i −1 −d i )( 1 − θ) − (k i −d i )θ ] , (4.4.16) where h i ,d i , i = 1 : m, are as defined in (4.4.13), and

(4.4.17) is the derivative at x i .

k i =q i ′ (x i )

The second derivative (and the curvature) of this piecewise polynomial will in general

be discontinuous at the grid points. We now show how to choose the parameters k i ,i=0: m , to also get a continuous second derivative. This will yield an interpolating cubic spline. In contrast to piecewise Lagrange–Hermite interpolation, each piece of the cubic spline will depend on all data points .

Theorem 4.4.5.

Every cubic spline function, with knots a = x 0 <x 1 < ···<x m = b, which interpolates the function y = f (x),

s(x i ) = f (x i ) =y i , i = 0 : m,

equals for x ∈ [x i −1 ,x i ), i = 1 : m, a third degree polynomial of the form (4.4.16). The m + 1 parameters k i , i = 0 : m, satisfy m − 1 linear equations

h i +1 k i −1 + 2(h i +h i +1 )k i +h i k i +1 = 3(h i d i +1 +h i +1 d i ), i = 1 : m − 1, (4.4.18) where h i =x i −x i −1 ,d i = (y i −y i −1 )/ h i .

Proof. We require the second derivative of the spline s(x) to be continuous at x i ,i=1: m − 1. We have

q i (x),

x ∈ [x i −1 ,x i ) ,

s(x) =

q i +1 (x), x ∈ [x i ,x i +1 ) ,

where q i (x) is given by (4.4.22)–(4.4.23). Differentiating q i (x) twice we get 1 2 q i ′′ (x) =

a 2,i + 3a 3,i (x −x i −1 ) , and putting x = x i we obtain

Replacing i by i + 1 we get 1

2 q ′′ i +1 (x) =a 2,i+1 + 3a 3,i+1 (x −x i ) , and hence

=a 2,i+1 =

2 h i +1

4.4. Piecewise Polynomial Interpolation 421 These last two expressions must be equal, which gives the conditions

Multiplying both sides by h i h i +1 we get (4.4.18).

If the cubic spline s(x) is to be evaluated at many points, then it is more efficient to first convert it from the form (4.4.16) to piecewise polynomial form (pp-form):

) 2 =y 3 −1 +a −x −1 +a −x −1 +a 3i (x −x i −1 ) , i = 1 : m. (4.4.22) From (4.4.16) we obtain after some calculation

Using Horner’s scheme q i (x) can be evaluated from (4.4.22) using only four multiplications. Algorithms for performing conversion to pp-form are given in [37, Chapter X].

The conditions (4.4.18) are (m − 1) linearly independent equations for the (m + 1) unknowns k i , i = 0 : m. Two additional conditions are therefore needed to uniquely

determine the interpolating spline. The most important choices are discussed below. • If the derivatives at the endpoints are known we can take

(4.4.24) The corresponding spline function s(x) is called the complete cubic spline inter-

k 0 =f ′ (a),

k m =f ′ (b).

polant . • If k 0 and k m are determined by numerical differentiation with a truncation error O(h 4 ) ,

we call the spline interpolant almost complete. For example, k 0 and k m may be the sum of (at least) four terms of the expansions

h h ln(1 − ∇)y m , into powers of the operators 4 and ∇, respectively. 138

Df (x 0 ) = ln(1 + 4)y 0 ,

Df (x m ) =−

• A physical spline is straight outside the interval [a, b]. The corresponding boundary conditions are q ′′ 1 (x 0 ) =q m ′′ (x m ) = 0. From (4.4.20) and (4.4.19) it follows that

1 −(3d i −k i − 2k i ) q i (x i −1 ) =

138 Two terms of the central difference expansion in (3.3.46).

422 Chapter 4. Interpolation and Approximation Setting i = 1 in the first equation and i = m in the second gives the two conditions

The spline function corresponding to these boundary conditions is called the natural spline interpolant . It should be stressed that when a cubic spline is used for the approximation of a smooth function, these boundary conditions are not natural! Al-

though the natural spline interpolant in general converges only with order h 2 , it has been shown that on any compact subinterval of the open interval (a, b) the order of

convergence is O(h 4 ) .

• If the endpoint derivatives are not known, a convenient boundary condition is to require that s ′′′ (x)

be continuous across the first and last interior knots x 1 and x m −1 . Hence

q ′′′ m −1 (x) =q m ′′′ (x). Then x 1 and x m −1 are no longer knots, and the corresponding spline interpolant is

q ′′′ 1 (x) =q ′′′ 2 (x),

called the not-a-knot spline interpolant. From (4.4.23) we obtain,

Hence the condition q ′′′ =q ′′′ 1 2 gives (k 0 +k 1 − 2d 1 )/ h 2 1 = (k 1 +k 2 − 2d 2 )/ h 2 2 , or

0 + (h 2 −h 1 )k 1 −h 1 k 2 = 2(h 2 d 1 −h 1 d 2 ). Since this equation would destroy the tridiagonal form of the system, we use (4.4.18),

with i = 1 to eliminate k 2 . This gives the equation

h 2 +h 1 If the right boundary condition is treated similarly we get

h m −1 +h m The error of the not-a-knot spline interpolant is of the same order as that of the complete

spline. For functions f ∈ C 4 [a, b] one has an error estimate of the same form as () for r = 0 : 2; see Beatson [22]. Indeed, the error analysis below shows that the

Lagrange–Hermite interpolation error is, in the whole interval [a, b], asymptotically, the dominant source of error for both complete and not-a-knot spline approximation.

• If the spline is used to represent a periodic function, then y 0 =y m and the boundary conditions

(4.4.28) suffice to determine the spline uniquely. From the first condition it follows that

s ′ (a) =s ′ (b),

s ′′ (a) =s ′′ (b)

k 0 =k m , which can be used to eliminate k 0 in (4.4.18) for k = 1. Using (4.4.21) the

4.4. Piecewise Polynomial Interpolation 423 second condition in (4.4.28) gives

(k 0 + 2k 1 − 3d 1 )/ h 1 = −(2k m −1 +k m − 3d m )/ h m

or, after eliminating k 0 ,

2h m k 1 + 2h 1 k m −1 + (h 1 +h m )k m = 3(h m d 1 +h 1 d m ). • The natural spline interpolant has the following best approximation property.

Theorem 4.4.6.

Among all functions g that are twice continuously differentiable on [a, b] and which interpolate f at the points a = x 0 <x 1 < ···<x m = b, the natural spline function minimizes

s ′′ (t ) dt.

The same minimum property holds for the complete spline interpolant if the functions g satisfy g ′ (a) =f ′ (a) and g ′ (b) =f ′ (b).

Proof. See de Boor [37, Chapter 5]. Due to this property spline functions yield smooth interpolation curves, except for

rather thin oscillatory layers near the boundaries if the “natural” boundary conditions s ′′ (a) =s ′′ (b) = 0 are far from being satisfied. For the complete or almost complete cubic spline and for cubic splines determined by the not-a-knot conditions, these oscil- lations are much smaller as we shall see below. Hence, when a spline is to be used for the approximate representation of a smooth function, the natural spline is not a natural choice!

Equations (4.4.18) together with any of these boundary conditions gives a linear sys- tem for determining the derivatives k i . It can be shown that this system is well-conditioned using the following result, which will be proved in Volume II.

Lemma 4.4.7.

Assume that the matrix A ∈ R n ×n is strictly row diagonally dominant, i.e.,

Then A is nonsingular, and for row diagonally dominant linear systems Gaussian elimination without pivoting is stable.

For the first three boundary conditions the system is tridiagonal and, which is easily verified, also strictly row diagonally dominant. In Example 1.3.2, and algorithm was given for solving a tridiagonal linear systems of order m by Gaussian elimination in O(m) flops.

The linear system resulting from the not-a-knot boundary condition is not diago- nally dominant in the first and last row. However, it can be shown that also in this case the system is well-conditioned and can be solved stably by Gaussian elimination without pivoting.

424 Chapter 4. Interpolation and Approximation

Example 4.4.2.

In the case of spline interpolation with constant step size h i = h, (4.4.18) becomes

(4.4.30) The not-a-knot boundary conditions (4.4.26)–(4.4.27) become

k i −1 + 4k i +k i +1 = 3(d i +d i +1 ), i = 1 : m − 1.

(d 2 m = 2 −1 + 5d m ). (4.4.31) We obtain for (k 0 ,k 1 ,...,k m ) a tridiagonal system T k = g, where

2 1 (d m −1 + 5d m )/ 6 Except for the first and last row, the elements of T are constant along the diagonals. The

condition number of T increases very slowly with m; for example, κ(T ) < 16 for m = 100. Consider now the periodic boundary conditions in (4.4.28). Setting k m =k 0 in the

last equation we obtain a linear system of equations T k = g for k 1 ,...,k m −1 where 

Here T is tridiagonal except for its last row and last column, where an extra nonzero element occurs. Such systems, called arrowhead systems, can be solved with about twice the work of a tridiagonal system; see [30].

In some applications one wants to smoothly interpolate given points (x j ,y j ) ,j=

0 : m, where a representation of the form y = f (x) is not possible. Then we can use a parametric spline representation x = x(t), y = y(t), where the parameter values 0 = t 0 ≤

t 1 ≤···≤t m correspond to the given points. Using the approach described previously, two spline functions s x (t ) and s y (t ) can then be determined that interpolate the points (t i ,x i ) and (t i ,y i ) , i = 0 : m, respectively. The parametrization is usually chosen as

t i =d i /d, i = 1 : m,

where d 0 = 0,

d i =d i −1 + (x i −x i −1 ) 2 + (y i −y i −1 ) 2 , i = 1 : m, are the cumulative distance, and d = d m .

4.4. Piecewise Polynomial Interpolation 425 For boundary conditions we have the same choices as mentioned previously. In

particular, using periodic boundary conditions for s x (t ) and s y (t ) allows the representation of closed curves (see Problem 4.4.8 (b)). Parametric splines can also be used to approximate curves in higher dimensions.

Error in Cubic Spline Interpolation

The following standard error estimate for the complete cubic spline interpolant is due to Beatson [22].

Theorem 4.4.8.

Let the function f be four times continuously differentiable in [a, b] and let s be the complete cubic spline interpolant on the grid a = x 0 <x 1 < ···<x m = b. Then

max (r) (x)

|f −s (x) |≤c r (β)h 4−r max

(r)

|f (iv) (x) |, r = 0 : 3, (4.4.33)

∈[a,b]

x ∈[a,b]

where h = max i h i , β = h/ min i h i , and

12 1 + 3β), c 3 (β) = 384 ( 2 1+β ). We comment below on the above result for r = 0 and how it is influenced by the

( 9+ 3), c 2 (β) =

choice of other boundary conditions. Let x ∈ I i = [x i −1 ,x i ], i = 1 : m, and set t = (x − x i −1 )/ h i ,

y i ′ =f ′ (x i ). The error in cubic spline interpolation can be expressed as the sum of two components:

y i = f (x i ),

i. The error E H (x) due to Lagrange–Hermite interpolation with correct values of f ′ (x i −1 ) ,

f ′ (x i ) . From (4.3.12) we obtain

ii. The error E S (x) due to the errors of the slopes e i =k i −y i ′ , i = 0 : m. In particular,

e 0 and e m are the errors in the boundary derivatives. The bound in Theorem 4.4.8 for r = 0 is only a factor of five larger than that for piecewise

Lagrange–Hermite interpolation with correct derivatives of f at all points x i , i = 0 : m, not just at x 0 = a and x m = b. Indeed, typically the error E H (x) is the dominant part. By (4.4.16) the second part of the error is

=x i −1 + th i , t ∈ [0, 1). Since |1 − t| + |t| = 1, and the maxima of t(1 − t) on [0, 1] equals 1/4, it follows that

E S (x)

=h i t( 1 − t) e i −1 ( 1 − t) − e i t

(4.4.34) where h i =x i −x i −1 .

|E S (x) |≤

max |h i e j

4 1≤i≤m

|, j = i − 1, i,

426Chapter 4. Interpolation and Approximation We shall consider the case of constant step size h i = h. For complete splines e 0 =

e m = 0 and for almost complete splines e 0 = O(h 4 ) ,e m = O(h 4 ) . It can be shown that then e i = O(h 4 ) , and its contribution to E S is O(h 5 ) . Thus if h is sufficiently small, the Lagrange–Hermite interpolation error is asymptotically the dominant source of error in the whole interval [a, b].

Finally, we discuss the effect of the boundary slope errors for other boundary condi- tions. Figure 4.4.7 shows (for m = 20, e 0 =e m = −1) how rapidly the error component

from the boundary dies out. At the midpoint x = 0.5 the error is 0.3816 · 10 −5 . If m ≫ 1,

e 0 m x =x 0 and x = x m . The height and thickness of the layers depend on e 0 and e m .

Figure 4.4.7. Boundary slope errors e B,i for a cubic spline, e 0 =e m = −1; m = 20. Consider the left boundary; the right one is analogous. For the natural splines, there is

a peak error near x = x 0 of approximately 0.049h 2 |y ′′ |, i.e., 40% of the linear interpolation error (instead of cubic). This is often clearly visible in a graph of s(x).

For the not-a-knot splines we obtain approximately e

3 y 0 ( ∼ 0.180h 4) , and the peak near x 0 becomes 0.031h 4 y ( 4) , typically very much smaller than we found for natural splines.

Still it is about 11.5 times as large as the Lagrange–Hermite interpolation error, but since the oscillations quickly die out, we conclude that the Lagrange–Hermite interpolation is the dominant error source in cubic not-a-knot spline interpolation in (say) the interval [a + 3h, b − 3h] .

Similar conclusions seem to hold in the case of variable step size also, under the reasonable assumption that h n +1 −h n = O(h 2 n ) . (The use of variable step size in the context of ordinary differential equations will be treated in a later volume.)

Dokumen yang terkait

Analisis Komparasi Internet Financial Local Government Reporting Pada Website Resmi Kabupaten dan Kota di Jawa Timur The Comparison Analysis of Internet Financial Local Government Reporting on Official Website of Regency and City in East Java

19 819 7

ANTARA IDEALISME DAN KENYATAAN: KEBIJAKAN PENDIDIKAN TIONGHOA PERANAKAN DI SURABAYA PADA MASA PENDUDUKAN JEPANG TAHUN 1942-1945 Between Idealism and Reality: Education Policy of Chinese in Surabaya in the Japanese Era at 1942-1945)

1 29 9

Improving the Eighth Year Students' Tense Achievement and Active Participation by Giving Positive Reinforcement at SMPN 1 Silo in the 2013/2014 Academic Year

7 202 3

An Analysis of illocutionary acts in Sherlock Holmes movie

27 148 96

The Effectiveness of Computer-Assisted Language Learning in Teaching Past Tense to the Tenth Grade Students of SMAN 5 Tangerang Selatan

4 116 138

The correlation between listening skill and pronunciation accuracy : a case study in the firt year of smk vocation higt school pupita bangsa ciputat school year 2005-2006

9 128 37

Existentialism of Jack in David Fincher’s Fight Club Film

5 71 55

Phase response analysis during in vivo l 001

2 30 2

The Risk and Trust Factors in Relation to the Consumer Buying Decision Process Model

0 0 15

PENERAPAN ADING (AUTOMATIC FEEDING) PINTAR DALAM BUDIDAYA IKAN PADA KELOMPOK PETANI IKAN SEKITAR SUNGAI IRIGASI DI KELURAHAN KOMET RAYA, BANJARBARU Implementation of Ading (Automatic Feeding) Pintar in Fish Farming on Group of Farmer Close to River Irriga

0 0 5