1
1
C COMPUTATION OF SPECIAL FUNCTIONS
3
3
C Shanjie Zhang and Jianming Jin
5
C Copyrighted but permission granted to use code in programs.
5
C Copyrighted but permission granted to use code in programs.
6
6
C Buy their book "Computation of Special Functions", 1996, John Wiley & Sons, Inc.
9
9
C Compiled into a single source file and changed REAL To DBLE throughout.
11
11
C Changed according to ERRATA also.
13
13
C Changed GAMMA to GAMMA2 and PSI to PSI_SPEC to avoid potential conflicts.
135
135
C ==========================================================
136
136
C Purpose: Compute the associated Legendre functions of the
137
137
C second kind, Qmn(x) and Qmn'(x)
138
C Input : x --- Argument of Qmn(x)
138
C Input : x --- Argument of Qmn(x)
139
139
C m --- Order of Qmn(x) ( m = 0,1,2,… )
140
140
C n --- Degree of Qmn(x) ( n = 0,1,2,… )
141
141
C mm --- Physical dimension of QM and QD
224
224
SUBROUTINE CLPMN(MM,M,N,X,Y,CPM,CPD)
226
226
C =========================================================
227
C Purpose: Compute the associated Legendre functions Pmn(z)
228
C and their derivatives Pmn'(z) for a complex
227
C Purpose: Compute the associated Legendre functions Pmn(z)
228
C and their derivatives Pmn'(z) for a complex
230
230
C Input : x --- Real part of z
231
231
C y --- Imaginary part of z
340
340
C **********************************
341
341
C SciPy: Changed P from a character array to an integer array.
342
342
SUBROUTINE JDZO(NT,N,M,P,ZO)
357
357
C P(L) --- 0 (TM) or 1 (TE), a code for designating the
358
358
C zeros of Jn(x) or Jn'(x).
359
359
C In the waveguide applications, the zeros
360
C of Jn(x) correspond to TM modes and
360
C of Jn(x) correspond to TM modes and
361
361
C those of Jn'(x) correspond to TE modes
362
C Routine called: BJNDD for computing Jn(x), Jn'(x) and
362
C Routine called: BJNDD for computing Jn(x), Jn'(x) and
364
364
C =============================================================
367
367
INTEGER P(1400), P1(70)
368
368
DIMENSION N(1400),M(1400),ZO(0:1400),N1(70),M1(70),
369
369
& ZOC(0:70),BJ(101),DJ(101),FJ(101)
370
372
IF (NT.LT.600) THEN
371
373
XM=-1.0+2.248485*NT**0.5-.0159382*NT+3.208775E-4
453
455
C **********************************
455
457
SUBROUTINE CBK(M,N,C,CV,QT,CK,BK)
523
525
C **********************************
525
527
SUBROUTINE CJY01(Z,CBJ0,CDJ0,CBJ1,CDJ1,CBY0,CDY0,CBY1,CDY1)
527
529
C =======================================================
528
C Purpose: Compute Bessel functions J0(z), J1(z), Y0(z),
530
C Purpose: Compute Bessel functions J0(z), J1(z), Y0(z),
529
531
C Y1(z), and their derivatives for a complex
531
533
C Input : z --- Complex argument
670
672
C of the second kind with a small argument
671
673
C Routines called:
672
674
C (1) LPMNS for computing the associated Legendre
673
C functions of the first kind
675
C functions of the first kind
674
676
C (2) LQMNS for computing the associated Legendre
675
C functions of the second kind
677
C functions of the second kind
676
678
C (3) KMN for computing expansion coefficients
677
679
C and joining factors
678
680
C ======================================================
1087
1089
C **********************************
1089
1091
SUBROUTINE CSPHJY(N,Z,NM,CSJ,CDJ,CSY,CDY)
1169
1171
INTEGER FUNCTION MSTA1(X,MP)
1171
1173
C ===================================================
1172
C Purpose: Determine the starting point for backward
1173
C recurrence such that the magnitude of
1174
C Purpose: Determine the starting point for backward
1175
C recurrence such that the magnitude of
1174
1176
C Jn(x) at that point is about 10^(-MP)
1175
1177
C Input : x --- Argument of Jn(x)
1176
1178
C MP --- Value of magnitude
1177
C Output: MSTA1 --- Starting point
1179
C Output: MSTA1 --- Starting point
1178
1180
C ===================================================
1180
1182
IMPLICIT DOUBLE PRECISION (A-H,O-Z)
1446
1448
C **********************************
1448
1450
SUBROUTINE RMN2L(M,N,C,X,DF,KD,R2F,R2D,ID)
1453
1455
C c and a large cx
1454
1456
C Routine called:
1455
1457
C SPHY for computing the spherical Bessel
1456
C functions of the second kind
1458
C functions of the second kind
1457
1459
C ========================================================
1459
1461
IMPLICIT DOUBLE PRECISION (A-H,O-Z)
1520
1522
EPS2=DABS(SUD-SW)
1521
1523
IF (K.GT.NM1.AND.EPS2.LT.DABS(SUD)*EPS) GO TO 65
1524
1526
ID2=INT(LOG10(EPS2/DABS(SUD)+EPS))
1525
1527
ID=MAX(ID1,ID2)
1531
1533
C **********************************
1533
1535
SUBROUTINE PSI_SPEC(X,PS)
1822
1824
C the second kind
1823
1825
C Routines called:
1824
1826
C (1) SDMN for computing expansion coefficients dk
1825
C (2) RMN1 for computing prolate and oblate radial
1827
C (2) RMN1 for computing prolate and oblate radial
1826
1828
C functions of the first kind
1827
1829
C (3) RMN2L for computing prolate and oblate radial
1828
1830
C functions of the second kind for a large argument
1829
C (4) RMN2SP for computing the prolate radial function
1831
C (4) RMN2SP for computing the prolate radial function
1830
1832
C of the second kind for a small argument
1831
1833
C ==============================================================
1851
1853
C **********************************
1853
1855
SUBROUTINE JYNDD(N,X,BJN,DJN,FJN,BYN,DYN,FYN)
1855
1857
C ===========================================================
1856
1858
C Purpose: Compute Bessel functions Jn(x) and Yn(x), and
1857
C their first and second derivatives
1859
C their first and second derivatives
1858
1860
C Input: x --- Argument of Jn(x) and Yn(x) ( x > 0 )
1859
1861
C n --- Order of Jn(x) and Yn(x)
1860
1862
C Output: BJN --- Jn(x)
2314
2316
C KF=1 for Ai(x) and Ai'(x)
2315
2317
C KF=2 for Bi(x) and Bi'(x)
2316
2318
C Output: XA(m) --- a, the m-th zero of Ai(x) or
2317
C b, the m-th zero of Bi(x)
2319
C b, the m-th zero of Bi(x)
2318
2320
C XB(m) --- a', the m-th zero of Ai'(x) or
2319
2321
C b', the m-th zero of Bi'(x)
2320
2322
C XC(m) --- Ai(a') or Bi(b')
2536
2538
C ============================================================
2537
2539
C Purpose: Compute a sequence of characteristic values of
2539
2541
C Input : M --- Maximum order of Mathieu functions
2540
2542
C q --- Parameter of Mathieu functions
2541
2543
C KD --- Case code
2779
2781
C ========================================================
2780
2782
C Purpose: Compute the expansion coefficients for the
2781
C asymptotic expansion of Bessel functions
2783
C asymptotic expansion of Bessel functions
2782
2784
C with large orders
2783
2785
C Input : Km --- Maximum k
2784
C Output: A(L) --- Cj(k) where j and k are related to L
2786
C Output: A(L) --- Cj(k) where j and k are related to L
2785
2787
C by L=j+1+[k*(k+1)]/2; j,k=0,1,...,Km
2786
2788
C ========================================================
2887
2889
C Purpose: Compute lambda function with arbitrary order v,
2888
2890
C and their derivative
2889
2891
C Input : x --- Argument of lambda function
2890
C v --- Order of lambda function
2892
C v --- Order of lambda function
2891
2893
C Output: VL(n) --- Lambda function of order n+v0
2892
C DL(n) --- Derivative of lambda function
2894
C DL(n) --- Derivative of lambda function
2893
2895
C VM --- Highest order computed
2894
2896
C Routines called:
2895
C (1) MSTA1 and MSTA2 for computing the starting
2897
C (1) MSTA1 and MSTA2 for computing the starting
2896
2898
C point for backward recurrence
2897
2899
C (2) GAM0 for computing gamma function (|x| ≤ 1)
2898
2900
C =========================================================
3120
3122
C **********************************
3122
3124
SUBROUTINE KMN(M,N,C,CV,KD,DF,DN,CK1,CK2)
3302
3304
C **********************************
3304
3306
SUBROUTINE CJYVA(V,Z,VM,CBJ,CDJ,CBY,CDY)
3306
3308
C ===========================================================
3307
C Purpose: Compute Bessel functions Jv(z), Yv(z) and their
3309
C Purpose: Compute Bessel functions Jv(z), Yv(z) and their
3308
3310
C derivatives for a complex argument
3309
3311
C Input : z --- Complex argument
3310
3312
C v --- Order of Jv(z) and Yv(z)
3558
3560
C **********************************
3560
3562
SUBROUTINE CJYVB(V,Z,VM,CBJ,CDJ,CBY,CDY)
3562
3564
C ===========================================================
3563
C Purpose: Compute Bessel functions Jv(z), Yv(z) and their
3565
C Purpose: Compute Bessel functions Jv(z), Yv(z) and their
3564
3566
C derivatives for a complex argument
3565
3567
C Input : z --- Complex argument
3566
3568
C v --- Order of Jv(z) and Yv(z)
3720
3722
C **********************************
3722
3724
SUBROUTINE JY01A(X,BJ0,DJ0,BJ1,DJ1,BY0,DY0,BY1,DY1)
3852
3854
C Purpose: Compute the incomplete gamma function
3853
3855
C r(a,x), Г(a,x) and P(a,x)
3854
3856
C Input : a --- Parameter ( a ≤ 170 )
3856
3858
C Output: GIN --- r(a,x)
3857
3859
C GIM --- Г(a,x)
3858
3860
C GIP --- P(a,x)
4229
4231
C **********************************
4231
4233
SUBROUTINE JYNB(N,X,NM,BJ,DJ,BY,DY)
4278
4280
C BY(n-NMIN) --- Yn(x) ; if indexing starts at 0
4279
4281
C NM --- Highest order computed
4280
4282
C Routines called:
4281
C MSTA1 and MSTA2 to calculate the starting
4283
C MSTA1 and MSTA2 to calculate the starting
4282
4284
C point for backward recurrence
4283
4285
C =====================================================
4548
4550
C **********************************
4550
4552
SUBROUTINE JYNA(N,X,NM,BJ,DJ,BY,DY)
4561
4563
C NM --- Highest order computed
4562
4564
C Routines called:
4563
4565
C (1) JY01B to calculate J0(x), J1(x), Y0(x) & Y1(x)
4564
C (2) MSTA1 and MSTA2 to calculate the starting
4566
C (2) MSTA1 and MSTA2 to calculate the starting
4565
4567
C point for backward recurrence
4566
4568
C =========================================================
4644
4646
C v --- Order of Dv(x)
4645
4647
C Output: DV(na) --- Dn+v0(x)
4646
4648
C DP(na) --- Dn+v0'(x)
4647
C ( na = |n|, v0 = v-n, |v0| < 1,
4649
C ( na = |n|, v0 = v-n, |v0| < 1,
4648
4650
C n = 0,±1,±2,… )
4649
4651
C PDF --- Dv(x)
4650
4652
C PDD --- Dv'(x)
6073
6075
C **********************************
6075
6077
SUBROUTINE HYGFZ(A,B,C,Z,ZHF)
6077
6079
C ======================================================
6078
C Purpose: Compute the hypergeometric function for a
6080
C Purpose: Compute the hypergeometric function for a
6079
6081
C complex argument, F(a,b,c,z)
6080
6082
C Input : a --- Parameter
6081
6083
C b --- Parameter
6481
6483
C NM --- Highest order computed
6482
6484
C Routines called:
6483
6485
C (1) IK01A for computing I0(x),I1(x),K0(x) & K1(x)
6484
C (2) MSTA1 and MSTA2 for computing the starting
6486
C (2) MSTA1 and MSTA2 for computing the starting
6485
6487
C point for backward recurrence
6486
6488
C ========================================================
6553
6555
C **********************************
6555
6557
SUBROUTINE CJYNA(N,Z,NM,CBJ,CDJ,CBY,CDY)
6566
6568
C NM --- Highest order computed
6567
6569
C Rouitines called:
6568
6570
C (1) CJY01 to calculate J0(z), J1(z), Y0(z), Y1(z)
6569
C (2) MSTA1 and MSTA2 to calculate the starting
6571
C (2) MSTA1 and MSTA2 to calculate the starting
6570
6572
C point for backward recurrence
6571
6573
C =======================================================
6700
6702
C **********************************
6702
6704
SUBROUTINE CJYNB(N,Z,NM,CBJ,CDJ,CBY,CDY)
6837
6839
C **********************************
6839
6841
SUBROUTINE IKNB(N,X,NM,BI,DI,BK,DK)
6849
6851
C DK(n) --- Kn'(x)
6850
6852
C NM --- Highest order computed
6851
6853
C Routines called:
6852
C MSTA1 and MSTA2 for computing the starting point
6854
C MSTA1 and MSTA2 for computing the starting point
6853
6855
C for backward recurrence
6854
6856
C ===========================================================
6931
6933
SUBROUTINE LPMN(MM,M,N,X,PM,PD)
6933
6935
C =====================================================
6934
C Purpose: Compute the associated Legendre functions
6936
C Purpose: Compute the associated Legendre functions
6935
6937
C Pmn(x) and their derivatives Pmn'(x)
6936
6938
C Input : x --- Argument of Pmn(x)
6937
6939
C m --- Order of Pmn(x), m = 0,1,2,...,n
7207
7209
SUBROUTINE FFK(KS,X,FR,FI,FM,FA,GR,GI,GM,GA)
7209
7211
C =======================================================
7210
C Purpose: Compute modified Fresnel integrals F±(x)
7212
C Purpose: Compute modified Fresnel integrals F±(x)
7212
7214
C Input : x --- Argument of F±(x) and K±(x)
7213
7215
C KS --- Sign code
7692
7694
C KF=1 for C(z) or KF=2 for S(z)
7693
7695
C NT --- Total number of zeros
7694
7696
C Output: ZO(L) --- L-th zero of C(z) or S(z)
7696
7698
C (1) CFC for computing Fresnel integral C(z)
7697
7699
C (2) CFS for computing Fresnel integral S(z)
7698
7700
C ==============================================================
7744
7746
C **********************************
7746
7748
SUBROUTINE E1XA(X,E1)
7748
7750
C ============================================
7749
7751
C Purpose: Compute exponential integral E1(x)
7750
C Input : x --- Argument of E1(x)
7752
C Input : x --- Argument of E1(x)
7751
7753
C Output: E1 --- E1(x) ( x > 0 )
7752
7754
C ============================================
7770
7772
C **********************************
7772
SUBROUTINE LPMV(V,M,X,PMV)
7774
SUBROUTINE LPMV0(V,M,X,PMV)
7774
7776
C =======================================================
7775
7777
C Purpose: Compute the associated Legendre function
7776
C Pmv(x) with an integer order and an arbitrary
7778
C Pmv(x) with an integer order and an arbitrary
7777
7779
C nonnegative degree v
7778
7780
C Input : x --- Argument of Pm(x) ( -1 ≤ x ≤ 1 )
7779
7781
C m --- Order of Pmv(x)
7869
C **********************************
7871
SUBROUTINE LPMV(V,M,X,PMV)
7873
C =======================================================
7874
C Purpose: Compute the associated Legendre function
7875
C Pmv(x) with an integer order and an arbitrary
7876
C degree v, using down-recursion for large degrees
7877
C Input : x --- Argument of Pm(x) ( -1 ≤ x ≤ 1 )
7878
C m --- Order of Pmv(x)
7879
C v --- Degree of Pmv(x)
7880
C Output: PMV --- Pmv(x)
7881
C Routine called: LPMV0
7882
C =======================================================
7884
IMPLICIT DOUBLE PRECISION (A-H,O-Z)
7885
IF (X.EQ.-1.0D0.AND.V.NE.INT(V)) THEN
7886
IF (M.EQ.0) PMV=-1.0D+300
7887
IF (M.NE.0) PMV=1.0D+300
7896
IF (M.LT.0.AND.(VX+M+1).GT.0D0) THEN
7897
C XXX: does not handle the cases where AMS 8.2.5
7904
IF (NV.GT.2.AND.NV.GT.MX) THEN
7905
C Up-recursion on degree, AMS 8.5.3
7906
CALL LPMV0(V0+MX, MX, X, P0)
7907
CALL LPMV0(V0+MX+1, MX, X, P1)
7910
PMV = ((2*(V0+J)-1)*X*P1 - (V0+J-1+MX)*P0) / (V0+J-MX)
7915
CALL LPMV0(VX, MX, X, PMV)
7917
IF (NEG_M.NE.0.AND.ABS(PMV).LT.1.0D+300) THEN
7918
C AMS 8.2.5, for integer order
7919
CALL GAMMA2(VX-MX+1, G1)
7920
CALL GAMMA2(VX+MX+1, G2)
7921
PMV = PMV*G1/G2 * (-1)**MX
7869
7926
C **********************************
7871
7928
SUBROUTINE CGAMA(X,Y,KF,GR,GI)
8211
8268
C **********************************
8213
8270
SUBROUTINE IK01A(X,BI0,DI0,BI1,DI1,BK0,DK0,BK1,DK1)
8322
8379
SUBROUTINE CPBDN(N,Z,CPB,CPD)
8324
8381
C ==================================================
8325
C Purpose: Compute the parabolic cylinder functions
8382
C Purpose: Compute the parabolic cylinder functions
8326
8383
C Dn(z) and Dn'(z) for a complex argument
8327
8384
C Input: z --- Complex argument of Dn(z)
8328
8385
C n --- Order of Dn(z) ( n=0,±1,±2,… )
8414
8471
C **********************************
8416
8473
SUBROUTINE IK01B(X,BI0,DI0,BI1,DI1,BK0,DK0,BK1,DK1)
8731
8788
85 IF (FC(1).LT.0.0D0) THEN
8740
8797
C **********************************
8742
8799
SUBROUTINE SPHI(N,X,NM,SI,DI)
8896
8953
C **********************************
8898
8955
SUBROUTINE RMN1(M,N,C,X,DF,KD,R1F,R1D)
8904
8961
C Routines called:
8905
8962
C (1) SCKB for computing expansion coefficients c2k
8906
8963
C (2) SPHJ for computing the spherical Bessel
8907
C functions of the first kind
8964
C functions of the first kind
8908
8965
C =======================================================
8910
8967
IMPLICIT DOUBLE PRECISION (A-H,O-Z)
8960
9017
CALL SPHJ(NM2,CX,NM2,SJ,DJ)
8961
A0=(1.0D0-KD/(X*X))**(0.5D0*M)/SUC
9018
A0=(1.0D0-KD/(X*X))**(0.5D0*M)/SUC
9197
9254
C **********************************
9199
9256
SUBROUTINE GMN(M,N,C,X,BK,GF,GD)
9755
9812
C **********************************
9757
9814
SUBROUTINE CYZO(NT,KF,KC,ZO,ZV)
9759
9816
C ===========================================================
9760
9817
C Purpose : Compute the complex zeros of Y0(z), Y1(z) and
9761
C Y1'(z), and their associated values at the zeros
9818
C Y1'(z), and their associated values at the zeros
9762
9819
C using the modified Newton's iteration method
9763
9820
C Input: NT --- Total number of zeros/roots
9764
9821
C KF --- Function choice code
9837
9894
C **********************************
9839
9896
SUBROUTINE KLVNB(X,BER,BEI,GER,GEI,DER,DEI,HER,HEI)
10013
10070
C **********************************
10015
10072
SUBROUTINE CSPHIK(N,Z,NM,CSI,CDI,CSK,CDK)
10327
10384
C **********************************
10329
10386
SUBROUTINE RSWFO(M,N,C,X,CV,KF,R1F,R1D,R2F,R2D)
10380
10437
C **********************************
10382
10439
SUBROUTINE CH12N(N,Z,NM,CHF1,CHD1,CHF2,CHD2)
10569
10626
C **********************************
10571
10628
SUBROUTINE IKV(V,X,VM,BI,DI,BK,DK)
10841
10898
C **********************************
10843
10900
SUBROUTINE AJYIK(X,VJ1,VJ2,VY1,VY2,VI1,VI2,VK1,VK2)
11172
11229
C **********************************
11174
11231
SUBROUTINE CIKVA(V,Z,VM,CBI,CDI,CBK,CDK)
11187
11244
C VM --- Highest order computed
11188
11245
C Routines called:
11189
11246
C (1) GAMMA2 for computing the gamma function
11190
C (2) MSTA1 and MSTA2 for computing the starting
11247
C (2) MSTA1 and MSTA2 for computing the starting
11191
11248
C point for backward recurrence
11192
11249
C ============================================================
11962
12019
C **********************************
11964
12021
SUBROUTINE CLQMN(MM,M,N,X,Y,CQM,CQD)
12343
12400
C **********************************
12345
12402
SUBROUTINE MTU12(KF,KC,M,Q,X,F1R,D1R,F2R,D2R)
12469
12526
C **********************************
12471
12528
SUBROUTINE CIK01(Z,CBI0,CDI0,CBI1,CDI1,CBK0,CDK0,CBK1,CDK1)
12473
12530
C ==========================================================
12474
C Purpose: Compute modified Bessel functions I0(z), I1(z),
12475
C K0(z), K1(z), and their derivatives for a
12531
C Purpose: Compute modified Bessel functions I0(z), I1(z),
12532
C K0(z), K1(z), and their derivatives for a
12476
12533
C complex argument
12477
12534
C Input : z --- Complex argument
12478
12535
C Output: CBI0 --- I0(z)
12862
12919
BJ0=SR*(PU0*DCOS(T0)-QU0*DSIN(T0))
12863
12920
BJ1=SR*(PU1*DCOS(T1)-QU1*DSIN(T1))
12864
12921
C Forward recurrence for J_|v| (Abm & Stg 9.1.27)
12865
C It's OK for the limited range -8.0 ≤ v ≤ 12.5,
12922
C It's OK for the limited range -8.0 ≤ v ≤ 12.5,
12866
12923
C since x >= 20 here; but would be unstable for v <~ -20