You are on page 1of 9

Test data for B-spline operators based on Galerkin L2 projection.

Wrap Mathematica's B-spline routines so they match the GNU Scientific Library's semantics. Note that Mathematica works
with piecewise polynomial degree while the GSL uses piecewise order plus one.

In[1]:= Knots@k_, b_D := Join@ConstantArray@First@bD, k - 1D, b, ConstantArray@Last@bD, k - 1DD


Lastdof@k_, b_D := Length@Knots@k, bDD - Hk - 1L - 2;
Basis@k_, b_D := BSplineBasis@8k - 1, Knots@k, bD<, ð1, ð2D &

Provide some sample breakpoints for testing purposes and visualize some different basis orders:

In[4]:= b = Sort@80, 1, 3  2, 2, 9  8, 3<D;

In[5]:= Plotem@k_D := Plot@Table@Basis@k, bD@i, xD, 8i, 0, Lastdof@k, bD<D,


8x, First@bD, Last@bD<, PlotRange ® Full, PlotLabel ® kD
Table@Plotem@kD, 8k, 1, 4<D

1
1.0

0.8

0.6
Out[6]= : ,
0.4

0.2

0.5 1.0 1.5 2.0 2.5 3.0

2
1.0

0.8

0.6
,
0.4

0.2

,
,
2 BsplineGalerkinL2Operators.nb

0.5 1.0 1.5 2.0 2.5 3.0

3
1.0

0.8

0.6
,
0.4

0.2

0.5 1.0 1.5 2.0 2.5 3.0

4
1.0

0.8

0.6
>
0.4

0.2

0.5 1.0 1.5 2.0 2.5 3.0

Compute the Galerkin L2 -based mass matrices for the above bases:

In[7]:= MassMatrix@k_, b_D := Module@8


B = Basis@k, bD, n = Lastdof@k, bD
<, Table@
Integrate@B@i, xD B@j, xD, 8x, First@bD, Last@bD<D,
8i, 0, n<, 8j, 0, n<D
D;

In[8]:= MassMatrix@1, bD  MatrixForm


MassMatrix@2, bD  MatrixForm
MassMatrix@3, bD  MatrixForm
MassMatrix@4, bD  MatrixForm
BsplineGalerkinL2Operators.nb 3

Out[8]//MatrixForm=
1 0 0 0 0
1
0 8
0 0 0
3
0 0 8
0 0
1
0 0 0 2
0
0 0 0 0 1
Out[9]//MatrixForm=
1 1
3 6
0 0 0 0
1 3 1
6 8 48
0 0 0
1 1 1
0 48 6 16
0 0
1 7 1
0 0 16 24 12
0
1 1 1
0 0 0 12 2 6
1 1
0 0 0 0 6 3
Out[10]//MatrixForm=
1 14 4
5 135 135
0 0 0 0
14 19 65 1
135 120 576 8640
0 0 0
4 65 107 851 9
135 576 360 15 120 2240
0 0
1 851 5 1919 1
0 8640 15 120 28 20 160 315
0
9 1919 59 16 1
0 0 2240 20 160 168 105 45
1 16 7 1
0 0 0 315 105 30 9
1 1 1
0 0 0 0 45 9 5
4 BsplineGalerkinL2Operators.nb

Out[11]//MatrixForm=
1 121 16 4
7 1620 567 945
0 0 0 0
121 257 7901 66 553 1
1620 2520 96 768 2 903 040 2 903 040
0 0 0
16 7901 9263 111 205 63 109 27
567 96 768 60 480 1 016 064 25 401 600 627 200
0 0
4 66 553 111 205 56 569 18 281 347 1
945 2 903 040 1 016 064 211 680 211 680 35 840 8820
0
1 63 109 18 281 85 759 507 307 271 4
0 2 903 040 25 401 600 211 680 352 800 3 763 200 8820 1575
27 347 507 307 75 647 4
0 0 627 200 35 840 3 763 200 392 5880 175
1 271 647 16 103
0 0 0 8820 8820 5880 105 1260
4 4 103 1
0 0 0 0 1575 175 1260 7

Quite annoyingly, Mathematica will not successfully differentiate the first and last basis function:

In[12]:= D@Basis@3, bD@0, xD, xD


D@Basis@3, bD@Lastdof@3, bD, xD, xD
1
Power::infy : Infinite expression encountered. ‡
0
Out[12]= ComplexInfinity

1
Power::infy : Infinite expression encountered. ‡
0
Out[13]= ComplexInfinity

The problem steps from the support of the basis functions ending (as it technically should) outside the knots:
BsplineGalerkinL2Operators.nb 5

In[14]:= Table@PiecewiseExpand@Basis@3, bD@i, xDD, 8i, 0, Lastdof@3, bD<D  MatrixForm


Out[14]//MatrixForm=
1 - 2 x + x2 0 £ x £ 1
0 True
1
I18 x - 17 x2 M 0£x<1
9
1 9
I81 - 144 x + 64 x2 M 1 £ x £
9 8
0 True
8 x2
0£x<1
9
4 9 3
I9 - 12 x + 4 x2 M £x£
3 8 2
8 9
- I27 - 54 x + 26 x2 M 1 £ x <
9 8
0 True
16 3
I4 - 4 x + x2 M £x£2
7 2
9
16 I1 - 2 x + x2 M 1£x<
8
8 9 3
- I39 - 60 x + 22 x2 M £x<
21 8 2
0 True
2
I9 - 6 x + x2 M 2£x£3
3
2 3
- I117 - 138 x + 38 x2 M £x<2
21 2
1 9 3
I81 - 144 x + 64 x2 M £x<
21 8 2
0 True
1
I- 27 + 24 x - 5 x2 M 2£x£3
3
1 3
I9 - 12 x + 4 x2 M £x<2
3 2
0 True
4 - 4 x + x2 2 £ x £ 3
0 True

While this is correct, it leads to ComplexInfinity problems during differentiation.

We circumvent the problem by working with the piecewise polynomial representation and promising on some ancestor to never,
ever evaluate outside the knots:

In[15]:= RefinedBasis@k_, b_D :=


Refine@PiecewiseExpand@Basis@k, bD@ð1, ð2DD, First@bD < ð2 < Last@bDD &

Notice that we lied and will most certainly evaluate at the two endpoints!

Finally, we can define and symbolically evaluate Galerkin L2 -based B-spline operators:

In[16]:= OperatorMatrix@k_, b_, d_D := Module@8


B = RefinedBasis@k, bD, n = Lastdof@k, bD, y
<, Table@
Integrate@B@i, xD H D@B@j, yD, 8y, d<D . y ® xL, 8x, First@bD, Last@bD<D,
8i, 0, n<, 8j, 0, n<D
D;

Some sample outputs for the previous bases are :

In[17]:= With@8k = 2<, Do@Print@OperatorMatrix@k, b, dD  MatrixFormD, 8d, 0, k - 1<DD


6 BsplineGalerkinL2Operators.nb

1 1
3 6
0 0 0 0
1 3 1
6 8 48
0 0 0
1 1 1
0 48 6 16
0 0
1 7 1
0 0 16 24 12
0
1 1 1
0 0 0 12 2 6
1 1
0 0 0 0 6 3

- 12 1
2
0 0 0 0
- 12 0 1
2
0 0 0
0 - 12 0 1
2
0 0
0 0 - 12 0 1
2
0
0 0 0 - 12 0 1
2
0 0 0 0 - 12 1
2
In[18]:= With@8k = 3<, Do@Print@OperatorMatrix@k, b, dD  MatrixFormD, 8d, 0, k - 1<DD
BsplineGalerkinL2Operators.nb 7

1 14 4
5 135 135
0 0 0 0
14 19 65 1
135 120 576 8640
0 0 0
4 65 107 851 9
135 576 360 15 120 2240
0 0
1 851 5 1919 1
0 8640 15 120 28 20 160 315
0
9 1919 59 16 1
0 0 2240 20 160 168 105 45
1 16 7 1
0 0 0 315 105 30 9
1 1 1
0 0 0 0 45 9 5

- 12 19
54
4
27
0 0 0 0
- 19
54
0 25
72
1
216
0 0 0
4
- 27 - 25
72
0 167
378
3
56
0 0
1
0 - 216 - 167
378
0 209
504
2
63
0
3
0 0 - 56 - 209
504
0 5
14
1
9
2 5 7
0 0 0 - 63 - 14 0 18

0 0 0 0 - 19 7
- 18 1
2
2
3
- 34
27
16
27
0 0 0 0
20
27
- 43 4
9
4
27
0 0 0
16 4
27 9
- 32
9
368
189
4
7
0 0
4 368
0 27 189
- 64
21
44
63
16
63
0
4 44
0 0 7 63
- 40
21
4
21
4
9
16 4
0 0 0 63 21
- 43 8
9
4
0 0 0 0 9
- 10
9
2
3

In[19]:= With@8k = 4<, Do@Print@OperatorMatrix@k, b, dD  MatrixFormD, 8d, 0, k - 1<DD


8 BsplineGalerkinL2Operators.nb

1 121 16 4
7 1620 567 945
0 0 0 0
121 257 7901 66 553 1
1620 2520 96 768 2 903 040 2 903 040
0 0 0
16 7901 9263 111 205 63 109 27
567 96 768 60 480 1 016 064 25 401 600 627 200
0 0
4 66 553 111 205 56 569 18 281 347 1
945 2 903 040 1 016 064 211 680 211 680 35 840 8820
0
1 63 109 18 281 85 759 507 307 271 4
0 2 903 040 25 401 600 211 680 352 800 3 763 200 8820 1575
27 347 507 307 75 647 4
0 0 627 200 35 840 3 763 200 392 5880 175
1 271 647 16 103
0 0 0 8820 8820 5880 105 1260
4 4 103 1
0 0 0 0 1575 175 1260 7

- 12 257
810
62
405
4
135
0 0 0 0
- 257
810
0 353
1728
5857
51 840
1
51 840
0 0 0
62 353 29 489 14 293 9
- 405 - 1728 0 90 720 453 600 11 200
0 0
4 5857
- 135 - 51 840
- 29 489
90 720
0 1861
4725
4853
67 200
1
630
0
0 - 51 1840 - 453
14 293
600
- 1861
4725
0 19 093
67 200
389
3150
4
225

0 0 - 11 9200 4853
- 67 200
- 19 093
67 200
0 121
525
19
150
1 389
0 0 0 - 630 - 3150 - 121
525
0 16
45
4 19
0 0 0 0 - 225 - 150 - 16
45
1
2
6
5
- 274
135
88
135
8
45
0 0 0 0
131
135
- 19
15
23
- 180 457
1080
1
1080
0 0 0
88 23
135
- 180 - 109
473
1890
3061
9450
9
700
0 0
8 457 473
45 1080 1890
- 668
315
52
63
17
40
2
105
0
1 3061 52
0 1080 9450 63
- 836
525
37
- 1400 38
105
8
75
9 17 37
0 0 700 40
- 1400 - 67 4
- 35 14
25
2 38 4
0 0 0 105 105
- 35 - 75 17
15
8 14
0 0 0 0 75 25
- 28
15
6
5
BsplineGalerkinL2Operators.nb 9

- 32 217
54
- 92
27
8
9
0 0 0 0
- 91
54
9
2
- 34
9
25
27
1
27
0 0 0
- 52
27
34
9
0 - 844
189
2308
945
6
35
0 0
- 89 - 25
27
844
189
0 - 1408
315
57
35
4
21
0
1
0 - 27 - 2308
945
1408
315
0 - 103
35
44
105
8
15
6
0 0 - 35 - 57
35
103
35
0 - 103
35
9
5
4 44 103
0 0 0 - 21 - 105 35
- 92 13
6
8 11
0 0 0 0 - 15 5
- 196
3
2

You might also like