Chapter 5. B

advertisement
1
Chapter 5. B-Splines
5.1. First Order B-Spline
B-splines (think Basis splines) form a truly piecewise basis for the spline family
as can be learned later. For a set of infinite data points ( xi , i  , ) where xi  xi 1 for
any i , the B-splines of degree k are defined as
Bik ( x) 
x  xi
x
 x k 1
Bik 1 ( x)  i  k 1
Bi 1 ( x), k  1
xi  k  xi
xi  k 1  xi 1
(5.1.1)
and
  1, x  [ xi , xi 1 ) 
Bi0 ( x)  

 0, otherwise 
(5.1.2)
where i and k are integers as usual. Note: 1  Bik ( x)  0 always.
Each Bi0 ( x ) is nonzero in exactly one interval (Figure 5.1.1) and has a
discontinuity at xi 1 . For any dataset ( xi , yi , i  1,2,, n) , the “constant” B-spline is
n
s ( x)   y i Bi0 ( x)
(5.1.3)
i 1
which simply extends each yi across each i th interval.
1.5
B0i
B0i+2
1
0.5
0
x(i-1)
x(i) x(i+1)
x(i+2)
x(i+3)
Figure 5.1.1 Non-zero parts of B-splines of degree 0.
x(i+4)
2
For k  1 , Bi1 ( x) can be derived from Equations 5.1.1.and 5.1.2 as
Bi1 ( x) 
x  xi
x  xi 0
Bi0 ( x)  i  2
Bi 1 ( x)
xi 1  xi
xi  2  xi 1
 x  xi
x  [ xi , xi 1 ) 
x x ,
i
 i 1



 xi  2  x


, x  [ xi 1 , xi  2 )
 xi  2  xi 1





0,
elsewhere




(5.1.4)
which has two non-zero parts, in intervals x  xi , xi 1  and x  xi 1 , xi  2  as shown in
Figure 5.1.2 (Dashed lines are used in order to make the splines more distinguishable).
These intervals are called the support of Bi1 ( x) . On each of its support intervals, Bi1 ( x)
is a linear function and its location and slope are solely determined by the distribution of
the xi ’s. Bi1 ( x) has a peak value of 1 at xi 1 and is continuous there. It is quite clear that
Bi1 ( x) has C 0 but not C 1 continuity.
1.5
Support intervals for B1i
B1i-1
B1i
B1i+1
B1i+2
1
0.5
0
x(i-1)
x(i) x(i+1)
x(i+2)
x(i+3)
Figure 5.1.2 Non-zero parts of B-splines of degree 1.
x(i+4)
3
It is interesting to note that Bi1 ( x) has some connection to the elementary
Lagrange interpolating polynomial. If we write the linear Lagrange interpolating
polynomial for the two-point data set of ( x j , j  i and i  1) , the two elements would be:
l12 ( x) 
x  xi 1
x  xi
, l 22 ( x) 
xi  xi 1
xi 1  xi
which are the second part of Bi1 1 ( x) and the first part of Bi1 ( x) , respectively. As we shall
learn, this agreement does not extend to higher order B-splines.
In general, the 1st order B-spline is constructed from
s ( x) 

D B
i  
i
1
i 1
( x)
(5.1.5)
where Di are constants determined from the data. However, we know from Section 4.1.1
that the linear spline on a given data interval is also the Lagrange interpolation formula
for the data set consisting of the two end points of the same data interval. So let’s discuss
the relationship of Bi1 ( x) with the linear splines. It turns out that for any data set
( xi , yi , i  1,2,, n, where n can be infinity ) , the following function is a linear spline:
n
s ( x)   y i Bi11 ( x)
(5.1.6)
i 1
To prove it, let’s look at the formula of s (x ) on interval xi , xi 1  . Of all the terms
in the above equation, only Bi1 1 ( x) and Bi1 ( x) have non-zero contributions on the
interval. Thus
s ( x)  y i Bi11 ( x)  y i 1 Bi1 ( x) , x  [ xi , xi 1 ]
(5.1.7)
On the interval xi , xi 1  , Bi1 1 ( x) will take the second leg of its formula and Bi1 ( x)
will take the first leg of its formula (see Equation 5.1.4). Thus
s ( x)  y i
xi 1  x
x  xi
 yi 1
, x  [ xi , xi 1 ]
xi 1  xi
xi 1  xi
(5.1.8)
which is exactly the linear spline (see Equation 4.1.1) as well as the linear Lagrange
interpolating polynomial.
Say x1 , y1 ; x2 , y2 are the only nonzero data, then
4
s( x)  0    y1 B01 ( x)  y 2 B11 ( x)    0
x  x0 , x1 
where
 x  x0
x  x
 1
0
B01 ( x)  
 x2  x
 x 2  x1
x  x1 , x 2 
and
 x  x1
x  x
 2
1
1
B1 ( x)  
 x3  x
 x3  x 2
 x  x0
 y1
 x1  x0
 x  x 2
x  x1
 s ( x)   y1
 y2
x 2  x1
 x1  x 2

x  x3
 y2
 x 2  x3
x  x1 , x 2 
x  x 2 , x3 
x  x0 , x1   Left extension
x  x1 , x 2   This row is Lagrange
x  x 2 , x3   Right extension
The central row is the same as a Lagrange interpolating polynomial, but s (x ) in
terms of B-splines is more general: it contains Lagrange plus two arbitrary end extensions
(points x0 , x3 are not part of the data set) as seen in Fig 5.1.3.
Now we see why we would use )x ( 11iB instead of Bi1 ( x) in Equation 5.1.5 and
5.1.6. The reason is that the hat shape of Bi1 ( x) (Figure 5.1.2) is centered at xi 1 , not xi .
For yi ’s contribution to take place, it should be teamed with a component of B-splines
5
B00
B10
B20
y2
B01 ( x)
B11 ( x)
B01
y1
B11
1
x0
x1
x
x2
x3
Figure 5.1.3 First degree B-spline for two data points.
that lags by 1. So yi is teamed with )x ( 11iB . Similar notation is used for all higher order
B-splines. For example, in the case of k  2 which will be discussed later, the sum over i
of terms yi Bi2 2 ( x ) are used together. Furthermore, since )x ( 11iB is centered on xi ,
Di  yi . Further insight can be gleamed from Figure 5.1.2.
It is worth noting that on x  xi , xi 1  , )x ( 11iB + Bi1 ( x) = 1 exactly. As we will
prove later, this is true for all orders of B-splines on all intervals.
Generally for linear splines, two points are used to draw a straight line for each
interval. Then for each data point, its x and y information will contribute to two splines.
In the case of Bi1 ( x) , this contribution is built into its expression through its two legs.
This is the essence of all B-splines and one reason why they are called “basis” splines.
Polynomial splines and Lagrange interpolating polynomials discussed before can
all be viewed as functions over interval(s), as functions should be. The emphasis here is
on the intervals. A polynomial is set up over the interval(s), then, we go to its end points
for help on determining the coefficients of the polynomials.
B-splines, however, should be viewed more as belonging to the points. Each
“point” function covers certain interval(s). To build splines through B-splines, we will
always use the form similar to that in Equation 5.1.5. The y information is applied to the
“point” function and we are done (almost, anyway) with the building of the splines. This
feature will be more evident in the case for Bi2 ( x ) .
6
5.2 Second Order B-Splines
Now for k  2 , from Equation (5.1.1) and (5.1.2), we have
Bi2 ( x) 
x  xi
x x 1
Bi1 ( x)  i 3
Bi 1 ( x)
xi  2  xi
xi 3  xi 1
 x  xi

x x 0

Bi0 ( x)  i  2
Bi 1 ( x) 
xi  2  xi 1
 xi 1  xi


x  xi
xi  2  xi


xi 3  x  x  xi 1
x x 0

Bi01 ( x)  i 3
Bi  2 ( x) 
xi 3  xi 1  xi  2  xi 1
xi  3  xi  2



( x  xi ) 2
x  [ xi , xi 1 ) 
,

 ( xi 1  xi )( xi  2  xi )





 ( x  xi )( xi  2  x) ( x  xi 1 )( xi 3  x) 
1

, x  [ xi 1 , xi  2 )




xi  2  xi
xi 3  xi 1

Bi2 ( x)   xi  2  xi 1 





( xi  3  x ) 2
x  [ xi  2 , xi  3 ) 
,

 ( xi 3  xi 1 )( xi 3  xi  2 )



0,
elsewhere


(5.2.1)
Non-zero parts of three B 2 splines are plotted in Figures 5.2.1. The support of
each spline covers three intervals. It is a quadratic polynomial on each support interval.
Note that the peak value of Bi2 ( x ) is less than 1. This is different from Bi0 ( x ) , Bi1 ( x) and
other interpolation functions that do have peak values of 1. If all the B 2 splines could be
plotted, in any interval, there would be contributions from three splines. But we only see
this in [ xi 1 , xi  2 ] in Figure 5.2.1. Interestingly, these three contributions sum to unity.
Also, the components of Bi2 ( x ) differ from the quadratic Lagrange polynomials.
For comparison, Figure 5.2.2 shows three quadratic elementary Lagrange polynomials for
the data set of ( x j , j  i, i  1 and i  2) . The l13 term goes negative. Different indeed!
7
1
B2i-1
0.9
B2i+1
0.8
0.7
B2i
0.6
0.5
0.4
0.3
0.2
0.1
0
x(i-1)
x(i) x(i+1)
x(i+2)
x(i+3)
x(i+4)
Figure 5.2.1 Non-zero parts of B-splines of degree 2. Note that the peak values are less than 1, but the
splines in [ xi 1 , xi  2 ] sum to 1.
2
1.5
l32(x)
1
B2i
0.5
l33(x)
0
-0.5
l31(x)
-1
x(i-1)
x(i) x(i+1)
x(i+2)
x(i+3)
x(i+4)
Figure 5.2.2 Comparison between B-spline of degree 2 and the elementary quadratic Lagrange
3
polynomials. Note: one component goes negative, however
l
i 1
3
i
 1.
8
By taking derivatives of all the sections in Equation 5.2.1, we get
2( x  xi )

x  [ xi , xi 1 ) 
 ( x  x )( x  x ) ,
i
i2
i
 i 1







x

x

x

x
x

x

x

x
1
i2
i
i 1
 i 3
, x  [ xi 1 , xi  2 )






xi  2  xi
xi 3  xi 1

Bi2 ( x)   xi  2  xi 1 



 2( xi 3  x)


x  [ xi  2 , xi  3 ) 
 ( x  x )( x  x ) ,
i 1
i 3
i2
 i 3





0,
elsewhere
2( xi 1  xi )
2
 2
2

 Bi ( xi )  0, Bi ( xi 1 )  ( x  x )( x  x )  x  x
i 1
i
i2
i
i2
i


2
2
 2 
2

 Bi ( xi 1 )  x  x , Bi ( xi  2 )  x  x
i2
i
i 3
i 1

 
 2( xi 3  xi  2 )

2
 Bi2 ( xi 2 ) 

, Bi2 ( xi 3 )  0

( xi 3  xi 1 )( xi 3  xi  2 ) xi 3  xi 1



 Bi2  0 at all other data points
2













(5.2.2)
The second part of line one in Equation 5.2.2 is exactly the first part of line two,
so Bi is continuous at xi 1 . The second part of line two is also exactly the first part of

line three, thus Bi2 is continuous at xi  2 . The first part of line one equals line four and


Bi2 is continuous at xi . The second part of line three equals line four and Bi2 is

continuous at xi 3 . Line 4 also means Bi2 is continuous at all the other data points.


So, Bi2 is continuous at all the data points. From Equation 5.2.1, we know Bi2 is

continuous at all the locations between the data points. Thus Bi2 is continuous at any x
and Bi2 ( x ) has C 1 continuity. Any linear combination of Bi2 ( x ) ’s also has C 1 continuity.
9
It can be shown that for any k

B
i  
k
i
( x)  1
(5.2.3)
For k  0 and for any x , some m can be found such that x  xm , xm1  . Of all
the Bi0 ( x ) with i  ,  , only Bm0 ( x) will be nonzero, thus

B
i  
0
i
( x)  Bm0 ( x)  1
For k  0 , consider a function f which is a linear combination of Bik (x)
f ( x) 

D
i  
k
i
Bik ( x)
Note here that the proof of Equation 5.2.3 does not require Dik to be arbitrary, but rather
Dik  1 is enough. Dik is used to illustrate its relationship with lower order terms.

D
f ( x) 
k
i
i  


 Dik
i  
 x  xi
x
 x k 1 
Bik 1 ( x)  i  k 1
Bi 1 ( x)

xi  k 1  xi 1
 xi  k  xi


x  xi
x
 x k 1
Bik 1 ( x)   Dik i  k 1
Bi 1 ( x)
xi  k  xi
xi  k 1  xi 1
i  
Denoting j  i  1 , the second term above can be rewritten as
 1

j   1
D kj1
x jk  x
x j k  x j

x j k  x
j  
x jk  x j
B kj 1 ( x)   D kj1

B kj 1 ( x)   Dik1
i  
xi  k  x k 1
Bi ( x)
xi  k  xi
So, f can be rewritten as


x  xi
x  x k 1
k
k 1
f ( x)   Di
Bi ( x)   Dik1 i  k
Bi ( x)
xi  k  x i
xi  k  x i
i  
i  



  D

i  
Introducing
k
i
x  xi
x x
 Dik1 i  k
xi  k  xi
xi  k  xi
 k 1
 Bi ( x)

10
Dik 1  Dik
x  xi
x x
 Dik1 i  k
xi  k  xi
xi  k  xi
(5.2.4)
and we have
f ( x) 

D
i  
k 1
i
Bik 1 ( x)
which means any function f that can be written as a linear combination of Bik (x) can
also be written as a linear combination of Bik 1 ( x) . Equation 5.2.4 is the relationship
between their respective coefficients.
The above equations are recursive, f (x) can be written as combinations of
k 1
Bi ( x), Bik  2 ( x), , Bi0 ( x) while k is decreased to k  1, k  2, ,0 . In the case k is
eventually reduced to 0, we get
f ( x) 

D
i  
0
i
Bi0 ( x)
and Di0 can be calculated using the recursive scheme starting from Dik . So, if Dik are
known for all i  ,  , D i0 would be known for all i  ,  .
Now, considering a specific function f (x) , where its Dik = 1 for all i  ,  ,
the goal here is to find out what is f (x) exactly. In Equation 5.2.3, it is stated that f (x) is
exactly 1. Now we can prove that.
From Equation 5.2.4, we get for any i
Dik 1  Dik
Dik 2  Dik 1
x  xi
x x
x  xi
x x
 Dik1 i  k

 ik
1
xi  k  x i
x i  k  x i x i  k  x i x i  k  xi
x  xi
x
x
x  xi
x
x
 Dik11 i  k 1

 i  k 1
1
xi  k 1  xi
xi  k 1  xi xi  k 1  xi xi  k 1  xi
Repeating this process, we eventually get
Di0  Di1
x  xi
x
x
x  xi
x x
 Di11 i  k k 1

 i 1
1
xi  k k 1  xi
xi  k k 1  xi xi 1  xi xi 1  xi
which means
f ( x) 

D
i  

0
i
Bi0 ( x)   Bi0 ( x)  1
i  
11
where at the second step in the above equation, the result for k  0 is used. Thus,
Equation 5.2.3 has been proven.
Example 5.2.1 Illustrative example to demonstrate Equation 5.2.3
Say x  x0 , x1  , then

B
( x)    B23 ( x)  B22 ( x)  B21 ( x)  B02 ( x)  B12 ( x)  


i  
0
0
2
2
B 2 ( x)
B1 ( x) 
B 2 ( x ) 

 
0



 
2
2
( x  x) ( x  x0 )
( x  x0 )
( x1  x)
( x  x 1 )( x1  x)


 2

( x1  x 1 )( x1  x0 ) ( x1  x 1 )( x1  x0 ) ( x 2  x0 )( x1  x0 ) ( x 2  x0 )( x1  x0 )
2
i

( x  x) ( x  x0 )
( x  x0 ) 2
( x1  x) 2
( x  x 1 )( x1  x)

 2

( x  x 1 )( x1  x0 ) ( x1  x 1 )( x1  x0 ) ( x 2  x0 )( x1  x0 ) ( x 2  x0 )( x1  x0 )
1

 


( x1  x)
( x  x0 )


x1  x  x  x1  

 x 2  x  x  x 0 
( x1  x 1 )( x1  x0 )
( x 2  x0 )( x1  x0 ) 

( x1  x) ( x  x0 )

( x1  x0 ) ( x1  x0 )

1
x1  x  x  x0 
( x1  x0 )
1
5.3. Building Second Order B-Splines
Considering a data set: xi , yi , i  1, 2, , n  , we wish to find the B-spline of the
2 order. First, write the spline function as a linear combination of Bi2 ( x )
nd
s( x) 

D B
i  
i
2
i 2
( x)
(5.3.1)
where the index i goes from   to  in general and is consistent with what we use in
Section 5.1. We should view the data set xi , yi , i  1, 2, , n  as part of a data set that
12
has an infinite number of knots. As will be seen later, the rest of the infinite data set is of
no use to us for the current task. Also note, the subscripts on B 2 are shifted, e.g.,
Di Bi2 2 ( x ) is used here for the same reason mentioned for the Bi1 ( x) case.
As stated before, the support of this spline covers only three intervals. So
to find the splines that have contributions in the data set range, we need to find the left
most spline that has contributions to the 1st data interval and the right most spline that
contributes to the last data interval. As seen from the Figure 5.3.1, they should be B21 ( x)
2
2
2
2
2’
and Bn
1 ( x ) , respectively. So the contributing B s are B1 , B0 ,  , Bn 1 . Hence the
required range for
D B
i
i 2
is 1  i  n 1 . Equation 5.3.1 can then be rewritten as
n 1
s ( x)   Di Bi2 2 ( x)
(5.3.2)
i 1
Out of range
Out of range
Bn21
B21
x-1
x0
x1
xn-2
x2
xn-1
xn
xn+1
Data set
Figure 5.3.1.
The number of Di to be solved is n  1 , which is one more than the number of
knots (or data points). Right away, we know the C 0 continuity can give us n conditions
and one more condition is needed.
To apply the C 0 continuity conditions, we need to calculate the value of s (x ) at
the knots. Looking at point xi in Figure 5.3.1, it is clear that only Bi2 2 ( x ) and Bi2 1 ( x)
are nonzero. Thus
s( x i )  Di Bi2 2 ( x i )  Di  1 Bi2 1 ( x i )  y i
From Equation 5.2.1, setting i  i  2 , and letting hi  xi 1  xi , we get
(5.3.3)
13
Bi2 2 ( xi ) 

( xi 1
( xi 1  xi ) 2
 xi 1 )( xi 1  xi )
( xi 1  xi )
( xi 1  xi  xi  xi 1 )


 


hi
hi 1
 Bi22 ( xi ) 
hi
hi  hi 1
(5.3.4)
Similarly setting i  i  1 in Equation 5.2.1 gives
Bi22 ( xi ) 

 ( xi  xi 1 )( xi 1  xi ) ( xi  xi )( xi  2  xi ) 
1



( xi 1  xi ) 
( xi 1  xi 1 )
( xi  2  xi )

( xi  xi 1 )
( xi 1  xi 1 )
 Bi22 ( xi ) 
hi 1
hi  hi 1
(5.3.5)
Hence from Equation 5.3.3 - 5, we get
hi
hi 1
Di
 Di 1
 yi
hi  hi 1
hi  hi 1
hi Di  hi 1 Di 1  (hi  hi 1 ) yi
(5.3.6)
where hi  xi 1  xi . Equation 5.3.6 contains n equations and there are n  1 unknowns.
Certainly, we can assign a value to D1 and use the above equation as a recursive scheme
to calculate all the rest of the coefficients. The value of D1 can be zero, or can be
calculated by some other methods (e.g., Cheney and Kincaid, 1994).
h h
The values of x 0 and x n 1 need to be assigned. If we define h-ratio  0 : n ,
h1 hn1
then these can be set by the user. Usually they are assigned such that h-ratio  1 : 1 .
Example 5.3.1. Given 3 data points xi , yi , i  1,2,3 , solve for constants D.
i  1:
i  2:
i  3:
h1 D1  h0 D2  h1  h0  y1 

h2 D2  h1 D3  h2  h1  y 2 
h3 D3  h2 D4  h3  h2  y3 

3 equations in 3 unknowns given D1 , h0 , h3
14
To solve, we must choose
 Constraint like D1  0 or other.

To find h0 , h3 , vary the h-ratios
h0 h3
that, in concert with Di , i  1,,4 , yield
,
h1 h2
tautness to the spline.
The algorithm of the MATLAB code “bspline2.m” follows
(1)
(2)
(3)
(4)
(5)
(6)
Input x where the interpolation value y  s(x) is needed;
Check to see if x is out of range; if yes, abort the program; if no, proceed;
Calculate or assign D1 (See Cheney and Kincaid, 1994);
Calculate Di (Equation 5.3.3);
Find the data interval where x belongs;
Calculate y according to Equation 5.3.2.
Example 5.3.2. Show 2nd order B-splines for data sets in Examples 4.1.1 and 4.1.2
Figures 5.3.1 and 5.3.2 show the 2nd order B-splines for the data sets in Examples
4.1.1 and 4.1.2, respectively. Three sets of h0 and hn are used.
Quadratic B-Spline
20
d* => d calculated per
Cheney and Kincaid (1994)
15
10
h-ratio = 100:1 and d*
y
h-ratio = 1:1 and d = 0
h-ratio = 10:10 and d*
5
0
h-ratio = 1:1 and d*
-5
0
1
2
3
4
5
x
6
7
8
9
Figure 5.3.1 Second Order B-spline for dataset from Example 4.1.1.
10
15
Quadratic B-Spline
2.5
h-ratio = 1:0.1 and d*
2
d* => d calculated per
Cheney and Kincaid (1994)
1.5
1
0.5
y
0
h-ratio = 1:1 and d*
-0.5
-1
h-ratio = 1:10 and d*
-1.5
-2
-2.5
h-ratio = 1:1 and d = 0
0
0.5
1
1.5
2
2.5
x
3
3.5
4
4.5
5
Figure 5.3.2 Second Order B-spline for data set from Example 4.1.2.
We know s (x ) in Equation 5.3.2 has C 0 continuity, but what about C 1
continuity? Recalling from Section 4.2, the quadratic spline has C 1 continuity. What
about s (x ) in Equation 5.3.2? The answer is yes. Since s (x ) is a linear combination of
the Bi2 ( x ) ’s which have C 1 continuity, s (x ) has C 1 continuity too.
In general, Bik (x) has continuous derivatives up to order k  1 (see Cheney and
Kincaid, 1994).
Conclusion
(1)
(2)
(3)
(4)
In conclusion, we discovered that the B-splines:
Have C 0 continuity for any order.
The first order spline requires no information in addition to the data points.
The second order spline requires three additional pieces of information (one more
interval on each end of the data set and, say, d1 ) regardless of the number of data
points.
The second order spline has C 1 continuity.
Reference
Cheney, W. and Kincaid, D., “Numerical Mathematics and Computing,” Third Edition,
Brooks/Cole Publishing Company, 1994.
Download