-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathjacobi_polynomial.cpp
1665 lines (1523 loc) · 32.1 KB
/
jacobi_polynomial.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# include <cstdlib>
# include <cmath>
# include <iostream>
# include <fstream>
# include <sstream>
# include <iomanip>
# include <ctime>
# include <cstring>
using namespace std;
# include "jacobi_polynomial.hpp"
//****************************************************************************80
int i4_max ( int i1, int i2 )
//****************************************************************************80
//
// Purpose:
//
// I4_MAX returns the maximum of two I4's.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 13 October 1998
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, int I1, I2, are two integers to be compared.
//
// Output, int I4_MAX, the larger of I1 and I2.
//
{
int value;
if ( i2 < i1 )
{
value = i1;
}
else
{
value = i2;
}
return value;
}
//****************************************************************************80
int i4_min ( int i1, int i2 )
//****************************************************************************80
//
// Purpose:
//
// I4_MIN returns the minimum of two I4's.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 13 October 1998
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, int I1, I2, two integers to be compared.
//
// Output, int I4_MIN, the smaller of I1 and I2.
//
{
int value;
if ( i1 < i2 )
{
value = i1;
}
else
{
value = i2;
}
return value;
}
//****************************************************************************80
string i4_to_string ( int i4 )
//****************************************************************************80
//
// Purpose:
//
// I4_TO_STRING converts an I4 to a C++ string.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 16 January 2013
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, int I4, an integer.
//
// Input, string FORMAT, the format string.
//
// Output, string I4_TO_STRING, the string.
//
{
ostringstream fred;
string value;
fred << i4;
value = fred.str ( );
return value;
}
//****************************************************************************80
void imtqlx ( int n, double d[], double e[], double z[] )
//****************************************************************************80
//
// Purpose:
//
// IMTQLX diagonalizes a symmetric tridiagonal matrix.
//
// Discussion:
//
// This routine is a slightly modified version of the EISPACK routine to
// perform the implicit QL algorithm on a symmetric tridiagonal matrix.
//
// The authors thank the authors of EISPACK for permission to use this
// routine.
//
// It has been modified to produce the product Q' * Z, where Z is an input
// vector and Q is the orthogonal matrix diagonalizing the input matrix.
// The changes consist (essentialy) of applying the orthogonal transformations
// directly to Z as they are generated.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 08 January 2010
//
// Author:
//
// Original FORTRAN77 version by Sylvan Elhay, Jaroslav Kautsky.
// C++ version by John Burkardt.
//
// Reference:
//
// Sylvan Elhay, Jaroslav Kautsky,
// Algorithm 655: IQPACK, FORTRAN Subroutines for the Weights of
// Interpolatory Quadrature,
// ACM Transactions on Mathematical Software,
// Volume 13, Number 4, December 1987, pages 399-415.
//
// Roger Martin, James Wilkinson,
// The Implicit QL Algorithm,
// Numerische Mathematik,
// Volume 12, Number 5, December 1968, pages 377-383.
//
// Parameters:
//
// Input, int N, the order of the matrix.
//
// Input/output, double D(N), the diagonal entries of the matrix.
// On output, the information in D has been overwritten.
//
// Input/output, double E(N), the subdiagonal entries of the
// matrix, in entries E(1) through E(N-1). On output, the information in
// E has been overwritten.
//
// Input/output, double Z(N). On input, a vector. On output,
// the value of Q' * Z, where Q is the matrix that diagonalizes the
// input symmetric tridiagonal matrix.
//
{
double b;
double c;
double f;
double g;
int i;
int ii;
int itn = 30;
int j;
int k;
int l;
int m;
int mml;
double p;
double prec;
double r;
double s;
prec = r8_epsilon ( );
if ( n == 1 )
{
return;
}
e[n-1] = 0.0;
for ( l = 1; l <= n; l++ )
{
j = 0;
for ( ; ; )
{
for ( m = l; m <= n; m++ )
{
if ( m == n )
{
break;
}
if ( fabs ( e[m-1] ) <= prec * ( fabs ( d[m-1] ) + fabs ( d[m] ) ) )
{
break;
}
}
p = d[l-1];
if ( m == l )
{
break;
}
if ( itn <= j )
{
cout << "\n";
cout << "IMTQLX - Fatal error!\n";
cout << " Iteration limit exceeded\n";
exit ( 1 );
}
j = j + 1;
g = ( d[l] - p ) / ( 2.0 * e[l-1] );
r = sqrt ( g * g + 1.0 );
g = d[m-1] - p + e[l-1] / ( g + fabs ( r ) * r8_sign ( g ) );
s = 1.0;
c = 1.0;
p = 0.0;
mml = m - l;
for ( ii = 1; ii <= mml; ii++ )
{
i = m - ii;
f = s * e[i-1];
b = c * e[i-1];
if ( fabs ( g ) <= fabs ( f ) )
{
c = g / f;
r = sqrt ( c * c + 1.0 );
e[i] = f * r;
s = 1.0 / r;
c = c * s;
}
else
{
s = f / g;
r = sqrt ( s * s + 1.0 );
e[i] = g * r;
c = 1.0 / r;
s = s * c;
}
g = d[i] - p;
r = ( d[i-1] - g ) * s + 2.0 * c * b;
p = s * r;
d[i] = g + p;
g = c * r - b;
f = z[i];
z[i] = s * z[i-1] + c * f;
z[i-1] = c * z[i-1] - s * f;
}
d[l-1] = d[l-1] - p;
e[l-1] = g;
e[m-1] = 0.0;
}
}
//
// Sorting.
//
for ( ii = 2; ii <= m; ii++ )
{
i = ii - 1;
k = i;
p = d[i-1];
for ( j = ii; j <= n; j++ )
{
if ( d[j-1] < p )
{
k = j;
p = d[j-1];
}
}
if ( k != i )
{
d[k-1] = d[i-1];
d[i-1] = p;
p = z[i-1];
z[i-1] = z[k-1];
z[k-1] = p;
}
}
return;
}
//****************************************************************************80
double j_double_product_integral ( int i, int j, double a, double b )
//****************************************************************************80
//
// Purpose:
//
// J_DOUBLE_PRODUCT_INTEGRAL: integral of J(i,x)*J(j,x)*(1-x)^a*(1+x)^b.
//
// Discussion:
//
// VALUE = integral ( -1 <= x <= +1 ) J(i,x)*J(j,x)*(1-x)^a*(1+x)^b dx
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 19 April 2012
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, int I, J, the polynomial indices.
//
// Input, double A, B, the parameters.
// -1 < A, B.
//
// Output, double VALUE, the value of the integral.
//
{
double i_r8;
double value;
if ( i != j )
{
value = 0.0;
}
else
{
i_r8 = ( double ) ( i );
value = pow ( 2, a + b + 1.0 )
/ ( 2.0 * i_r8 + a + b + 1.0 )
* tgamma ( i_r8 + a + 1.0 )
* tgamma ( i_r8 + b + 1.0 )
/ r8_factorial ( i )
/ tgamma ( i_r8 + a + b + 1.0 );
}
return value;
}
//****************************************************************************80
double j_integral ( int n )
//****************************************************************************80
//
// Purpose:
//
// J_INTEGRAL evaluates a monomial integral associated with J(n,a,b,x).
//
// Discussion:
//
// The integral:
//
// integral ( -1 <= x < +1 ) x^n dx
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 19 April 2012
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, int N, the exponent.
// 0 <= N.
//
// Output, double J_INTEGRAL, the value of the integral.
//
{
double value;
if ( ( n % 2 ) == 1 )
{
value = 0.0;
}
else
{
value = 2.0 / ( double ) ( n + 1 );
}
return value;
}
//****************************************************************************80
double *j_polynomial ( int m, int n, double alpha, double beta, double x[] )
//****************************************************************************80
//
// Purpose:
//
// JACOBI_POLY evaluates the Jacobi polynomial J(n,a,b,x).
//
// Differential equation:
//
// (1-X*X) Y'' + (BETA-ALPHA-(ALPHA+BETA+2) X) Y' + N (N+ALPHA+BETA+1) Y = 0
//
// Recursion:
//
// P(0,ALPHA,BETA,X) = 1,
//
// P(1,ALPHA,BETA,X) = ( (2+ALPHA+BETA)*X + (ALPHA-BETA) ) / 2
//
// P(N,ALPHA,BETA,X) =
// (
// (2*N+ALPHA+BETA-1)
// * ((ALPHA^2-BETA**2)+(2*N+ALPHA+BETA)*(2*N+ALPHA+BETA-2)*X)
// * P(N-1,ALPHA,BETA,X)
// -2*(N-1+ALPHA)*(N-1+BETA)*(2*N+ALPHA+BETA) * P(N-2,ALPHA,BETA,X)
// ) / 2*N*(N+ALPHA+BETA)*(2*N-2+ALPHA+BETA)
//
// Restrictions:
//
// -1 < ALPHA
// -1 < BETA
//
// Norm:
//
// Integral ( -1 <= X <= 1 ) ( 1 - X )^ALPHA * ( 1 + X )^BETA
// * P(N,ALPHA,BETA,X)^2 dX
// = 2^(ALPHA+BETA+1) * Gamma ( N + ALPHA + 1 ) * Gamma ( N + BETA + 1 ) /
// ( 2 * N + ALPHA + BETA ) * N! * Gamma ( N + ALPHA + BETA + 1 )
//
// Special values:
//
// P(N,ALPHA,BETA,1) = (N+ALPHA)!/(N!*ALPHA!) for integer ALPHA.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 12 May 2003
//
// Author:
//
// John Burkardt
//
// Reference:
//
// Milton Abramowitz, Irene Stegun,
// Handbook of Mathematical Functions,
// National Bureau of Standards, 1964,
// ISBN: 0-486-61272-4,
// LC: QA47.A34.
//
// Parameters:
//
// Input, int M, the number of evaluation points.
//
// Input, int N, the highest order polynomial to compute. Note
// that polynomials 0 through N will be computed.
//
// Input, double ALPHA, one of the parameters defining the Jacobi
// polynomials, ALPHA must be greater than -1.
//
// Input, double BETA, the second parameter defining the Jacobi
// polynomials, BETA must be greater than -1.
//
// Input, double X[M], the evaluation points.
//
// Output, double J_POLYNOMIAL[M*(N+1)], the values.
//
{
double c1;
double c2;
double c3;
double c4;
int i;
int j;
double *v;
if ( alpha <= -1.0 )
{
cerr << "\n";
cerr << "J_POLYNOMIAL - Fatal error!\n";
cerr << " Illegal input value of ALPHA = " << alpha << "\n";
cerr << " But ALPHA must be greater than -1.\n";
exit ( 1 );
}
if ( beta <= -1.0 )
{
cerr << "\n";
cerr << "J_POLYNOMIAL - Fatal error!\n";
cerr << " Illegal input value of BETA = " << beta << "\n";
cerr << " But BETA must be greater than -1.\n";
exit ( 1 );
}
if ( n < 0 )
{
return NULL;
}
v = new double[m*(n+1)];
for ( i = 0; i < m; i++ )
{
v[i+0*m] = 1.0;
}
if ( n == 0 )
{
return v;
}
for ( i = 0; i < m; i++ )
{
v[i+1*m] = ( 1.0 + 0.5 * ( alpha + beta ) ) * x[i]
+ 0.5 * ( alpha - beta );
}
for ( i = 0; i < m; i++ )
{
for ( j = 2; j <= n; j++ )
{
c1 = 2.0 * ( double ) ( j ) * ( ( double ) ( j ) + alpha + beta )
* ( ( double ) ( 2 * j - 2 ) + alpha + beta );
c2 = ( ( double ) ( 2 * j - 1 ) + alpha + beta )
* ( ( double ) ( 2 * j ) + alpha + beta )
* ( ( double ) ( 2 * j - 2 ) + alpha + beta );
c3 = ( ( double ) ( 2 * j - 1 ) + alpha + beta )
* ( alpha + beta ) * ( alpha - beta );
c4 = - ( double ) ( 2 ) * ( ( double ) ( j - 1 ) + alpha )
* ( ( double ) ( j - 1 ) + beta )
* ( ( double ) ( 2 * j ) + alpha + beta );
v[i+j*m] = ( ( c3 + c2 * x[i] ) * v[i+(j-1)*m] + c4 * v[i+(j-2)*m] ) / c1;
}
}
return v;
}
//****************************************************************************80
void j_polynomial_values ( int &n_data, int &n, double &a, double &b, double &x,
double &fx )
//****************************************************************************80
//
// Purpose:
//
// J_POLYNOMIAL_VALUES returns some values of the Jacobi polynomial.
//
// Discussion:
//
// In Mathematica, the function can be evaluated by:
//
// JacobiP[ n, a, b, x ]
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 19 April 2012
//
// Author:
//
// John Burkardt
//
// Reference:
//
// Milton Abramowitz, Irene Stegun,
// Handbook of Mathematical Functions,
// National Bureau of Standards, 1964,
// ISBN: 0-486-61272-4,
// LC: QA47.A34.
//
// Stephen Wolfram,
// The Mathematica Book,
// Fourth Edition,
// Cambridge University Press, 1999,
// ISBN: 0-521-64314-7,
// LC: QA76.95.W65.
//
// Parameters:
//
// Input/output, int &N_DATA. The user sets N_DATA to 0 before the
// first call. On each call, the routine increments N_DATA by 1, and
// returns the corresponding data; when there is no more data, the
// output value of N_DATA will be 0 again.
//
// Output, int &N, the degree of the polynomial.
//
// Output, double &A, &B, parameters of the function.
//
// Output, double &X, the argument of the function.
//
// Output, double &FX, the value of the function.
//
{
# define N_MAX 26
static double a_vec[N_MAX] = {
0.0, 0.0, 0.0, 0,
0.0, 0.0, 1.0, 2,
3.0, 4.0, 5.0, 0,
0.0, 0.0, 0.0, 0,
0.0, 0.0, 0.0, 0,
0.0, 0.0, 0.0, 0,
0.0, 0.0 };
static double b_vec[N_MAX] = {
1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 2.0,
3.0, 4.0, 5.0, 1.0,
1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0,
1.0, 1.0 };
static double fx_vec[N_MAX] = {
0.1000000000000000E+01,
0.2500000000000000E+00,
-0.3750000000000000E+00,
-0.4843750000000000E+00,
-0.1328125000000000E+00,
0.2753906250000000E+00,
-0.1640625000000000E+00,
-0.1174804687500000E+01,
-0.2361328125000000E+01,
-0.2616210937500000E+01,
0.1171875000000000E+00,
0.4218750000000000E+00,
0.5048828125000000E+00,
0.5097656250000000E+00,
0.4306640625000000E+00,
-0.6000000000000000E+01,
0.3862000000000000E-01,
0.8118400000000000E+00,
0.3666000000000000E-01,
-0.4851200000000000E+00,
-0.3125000000000000E+00,
0.1891200000000000E+00,
0.4023400000000000E+00,
0.1216000000000000E-01,
-0.4396200000000000E+00,
0.1000000000000000E+01 };
static int n_vec[N_MAX] = {
0, 1, 2, 3,
4, 5, 5, 5,
5, 5, 5, 5,
5, 5, 5, 5,
5, 5, 5, 5,
5, 5, 5, 5,
5, 5 };
static double x_vec[N_MAX] = {
0.5E+00,
0.5E+00,
0.5E+00,
0.5E+00,
0.5E+00,
0.5E+00,
0.5E+00,
0.5E+00,
0.5E+00,
0.5E+00,
0.5E+00,
0.5E+00,
0.5E+00,
0.5E+00,
0.5E+00,
-1.0E+00,
-0.8E+00,
-0.6E+00,
-0.4E+00,
-0.2E+00,
0.0E+00,
0.2E+00,
0.4E+00,
0.6E+00,
0.8E+00,
1.0E+00 };
if ( n_data < 0 )
{
n_data = 0;
}
n_data = n_data + 1;
if ( N_MAX < n_data )
{
n_data = 0;
n = 0;
a = 0.0;
b = 0.0;
x = 0.0;
fx = 0.0;
}
else
{
n = n_vec[n_data-1];
a = a_vec[n_data-1];
b = b_vec[n_data-1];
x = x_vec[n_data-1];
fx = fx_vec[n_data-1];
}
return;
# undef N_MAX
}
//****************************************************************************80
double *j_polynomial_zeros ( int n, double alpha, double beta )
//****************************************************************************80
//
// Purpose:
//
// J_POLYNOMIAL_ZEROS: zeros of Jacobi polynomial J(n,a,b,x).
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 19 April 2012
//
// Author:
//
// John Burkardt.
//
// Reference:
//
// Sylvan Elhay, Jaroslav Kautsky,
// Algorithm 655: IQPACK, FORTRAN Subroutines for the Weights of
// Interpolatory Quadrature,
// ACM Transactions on Mathematical Software,
// Volume 13, Number 4, December 1987, pages 399-415.
//
// Parameters:
//
// Input, int, N, the order.
//
// Input, double, ALPHA, BETA, the parameters.
// -1 < ALPHA, BETA.
//
// Output, double J_POLYNOMIAL_ZEROS[N], the zeros.
//
{
double a2b2;
double ab;
double abi;
double *bj;
int i;
double i_r8;
double *w;
double *x;
double zemu;
ab = alpha + beta;
abi = 2.0 + ab;
//
// Define the zero-th moment.
//
zemu = pow ( 2.0, ab + 1.0 ) * tgamma ( alpha + 1.0 )
* tgamma ( beta + 1.0 ) / tgamma ( abi );
//
// Define the Jacobi matrix.
//
x = new double[n];
x[0] = ( beta - alpha ) / abi;
for ( i = 1; i < n; i++ )
{
x[i] = 0.0;
}
bj = new double[n];
bj[0] = 4.0 * ( 1.0 + alpha ) * ( 1.0 + beta )
/ ( ( abi + 1.0 ) * abi * abi );
for ( i = 1; i < n; i++ )
{
bj[i] = 0.0;
}
a2b2 = beta * beta - alpha * alpha;
for ( i = 1; i < n; i++ )
{
i_r8 = ( double ) ( i + 1 );
abi = 2.0 * i_r8 + ab;
x[i] = a2b2 / ( ( abi - 2.0 ) * abi );
abi = abi * abi;
bj[i] = 4.0 * i_r8 * ( i_r8 + alpha ) * ( i_r8 + beta )
* ( i_r8 + ab ) / ( ( abi - 1.0 ) * abi );
}
for ( i = 0; i < n; i++ )
{
bj[i] = sqrt ( bj[i] );
}
w = new double[n];
w[0] = sqrt ( zemu );
for ( i = 1; i < n; i++ )
{
w[i] = 0.0;
}
//
// Diagonalize the Jacobi matrix.
//
imtqlx ( n, x, bj, w );
delete [] bj;
delete [] w;
return x;
}
//****************************************************************************80
void j_quadrature_rule ( int n, double alpha, double beta, double x[],
double w[] )
//****************************************************************************80
//
// Purpose:
//
// J_QUADRATURE_RULE: Gauss-Jacobi quadrature based on J(n,a,b,x).
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 19 April 2012
//
// Author:
//
// John Burkardt.
//
// Reference:
//
// Sylvan Elhay, Jaroslav Kautsky,
// Algorithm 655: IQPACK, FORTRAN Subroutines for the Weights of
// Interpolatory Quadrature,
// ACM Transactions on Mathematical Software,
// Volume 13, Number 4, December 1987, pages 399-415.
//
// Parameters:
//
// Input, int, N, the order.
//
// Input, double, ALPHA, BETA, the parameters.
// -1 < ALPHA, BETA.
//
// Output, double X[N], the abscissas.
//
// Output, double W[N], the weights.
//
{
double a2b2;
double ab;
double abi;
double *bj;
int i;
double i_r8;
double zemu;
ab = alpha + beta;
abi = 2.0 + ab;
//
// Define the zero-th moment.
//
zemu = pow ( 2.0, ab + 1.0 ) * tgamma ( alpha + 1.0 )
* tgamma ( beta + 1.0 ) / tgamma ( abi );
//
// Define the Jacobi matrix.
//
x[0] = ( beta - alpha ) / abi;
for ( i = 1; i < n; i++ )
{
x[i] = 0.0;
}
bj = new double[n];
bj[0] = 4.0 * ( 1.0 + alpha ) * ( 1.0 + beta )
/ ( ( abi + 1.0 ) * abi * abi );
for ( i = 1; i < n; i++ )
{
bj[i] = 0.0;
}
a2b2 = beta * beta - alpha * alpha;
for ( i = 1; i < n; i++ )
{
i_r8 = ( double ) ( i + 1 );
abi = 2.0 * i_r8 + ab;
x[i] = a2b2 / ( ( abi - 2.0 ) * abi );
abi = abi * abi;
bj[i] = 4.0 * i_r8 * ( i_r8 + alpha ) * ( i_r8 + beta )
* ( i_r8 + ab ) / ( ( abi - 1.0 ) * abi );
}
for ( i = 0; i < n; i++ )
{
bj[i] = sqrt ( bj[i] );
}
w[0] = sqrt ( zemu );
for ( i = 1; i < n; i++ )
{
w[i] = 0.0;
}
//
// Diagonalize the Jacobi matrix.
//
imtqlx ( n, x, bj, w );
for ( i = 0; i < n; i++ )
{
w[i] = w[i] * w[i];
}
delete [] bj;
return;
}
//****************************************************************************80
double r8_choose ( int n, int k )
//****************************************************************************80
//
// Purpose:
//
// R8_CHOOSE computes the binomial coefficient C(N,K) as an R8.
//
// Discussion:
//
// The value is calculated in such a way as to avoid overflow and
// roundoff. The calculation is done in R8 arithmetic.
//
// The formula used is: