2 SUBROUTINE ZBESJ
(ZR
, ZI
, FNU
, KODE
, N
, CYR
, CYI
, NZ
, IERR
)
3 C***BEGIN PROLOGUE ZBESJ
4 C***PURPOSE Compute a sequence of the Bessel functions J(a,z) for
5 C complex argument z and real nonnegative orders a=b,b+1,
6 C b+2,... where b>0. A scaling option is available to
10 C***TYPE COMPLEX (CBESJ-C, ZBESJ-C)
11 C***KEYWORDS BESSEL FUNCTIONS OF COMPLEX ARGUMENT,
12 C BESSEL FUNCTIONS OF THE FIRST KIND, J BESSEL FUNCTIONS
13 C***AUTHOR Amos, D. E., (SNL)
16 C ***A DOUBLE PRECISION ROUTINE***
17 C On KODE=1, ZBESJ computes an N member sequence of complex
18 C Bessel functions CY(L)=J(FNU+L-1,Z) for real nonnegative
19 C orders FNU+L-1, L=1,...,N and complex Z in the cut plane
20 C -pi<arg(Z)<=pi where Z=ZR+i*ZI. On KODE=2, CBESJ returns
21 C the scaled functions
23 C CY(L) = exp(-abs(Y))*J(FNU+L-1,Z), L=1,...,N and Y=Im(Z)
25 C which remove the exponential growth in both the upper and
26 C lower half planes as Z goes to infinity. Definitions and
27 C notation are found in the NBS Handbook of Mathematical
31 C ZR - DOUBLE PRECISION real part of argument Z
32 C ZI - DOUBLE PRECISION imag part of argument Z
33 C FNU - DOUBLE PRECISION initial order, FNU>=0
34 C KODE - A parameter to indicate the scaling option
36 C CY(L)=J(FNU+L-1,Z), L=1,...,N
38 C CY(L)=J(FNU+L-1,Z)*exp(-abs(Y)), L=1,...,N
40 C N - Number of terms in the sequence, N>=1
43 C CYR - DOUBLE PRECISION real part of result vector
44 C CYI - DOUBLE PRECISION imag part of result vector
45 C NZ - Number of underflows set to zero
47 C NZ>0 CY(L)=0, L=N-NZ+1,...,N
49 C IERR=0 Normal return - COMPUTATION COMPLETED
50 C IERR=1 Input error - NO COMPUTATION
51 C IERR=2 Overflow - NO COMPUTATION
52 C (Im(Z) too large on KODE=1)
53 C IERR=3 Precision warning - COMPUTATION COMPLETED
54 C (Result has half precision or less
55 C because abs(Z) or FNU+N-1 is large)
56 C IERR=4 Precision error - NO COMPUTATION
57 C (Result has no precision because
58 C abs(Z) or FNU+N-1 is too large)
59 C IERR=5 Algorithmic error - NO COMPUTATION
60 C (Termination condition not met)
64 C The computation is carried out by the formulae
66 C J(a,z) = exp( a*pi*i/2)*I(a,-i*z), Im(z)>=0
68 C J(a,z) = exp(-a*pi*i/2)*I(a, i*z), Im(z)<0
70 C where the I Bessel function is computed as described in the
73 C For negative orders, the formula
75 C J(-a,z) = J(a,z)*cos(a*pi) - Y(a,z)*sin(a*pi)
77 C can be used. However, for large orders close to integers, the
78 C the function changes radically. When a is a large positive
79 C integer, the magnitude of J(-a,z)=J(a,z)*cos(a*pi) is a
80 C large negative power of ten. But when a is not an integer,
81 C Y(a,z) dominates in magnitude with a large positive power of
82 C ten and the most that the second term can be reduced is by
83 C unit roundoff from the coefficient. Thus, wide changes can
84 C occur within unit roundoff of a large integer for a. Here,
85 C large means a>abs(z).
87 C In most complex variable computation, one must evaluate ele-
88 C mentary functions. When the magnitude of Z or FNU+N-1 is
89 C large, losses of significance by argument reduction occur.
90 C Consequently, if either one exceeds U1=SQRT(0.5/UR), then
91 C losses exceeding half precision are likely and an error flag
92 C IERR=3 is triggered where UR=MAX(D1MACH(4),1.0D-18) is double
93 C precision unit roundoff limited to 18 digits precision. Also,
94 C if either is larger than U2=0.5/UR, then all significance is
95 C lost and IERR=4. In order to use the INT function, arguments
96 C must be further restricted not to exceed the largest machine
97 C integer, U3=I1MACH(9). Thus, the magnitude of Z and FNU+N-1
98 C is restricted by MIN(U2,U3). In IEEE arithmetic, U1,U2, and
99 C U3 approximate 2.0E+3, 4.2E+6, 2.1E+9 in single precision
100 C and 4.7E+7, 2.3E+15 and 2.1E+9 in double precision. This
101 C makes U2 limiting in single precision and U3 limiting in
102 C double precision. This means that one can expect to retain,
103 C in the worst cases on IEEE machines, no digits in single pre-
104 C cision and only 6 digits in double precision. Similar con-
105 C siderations hold for other machines.
107 C The approximate relative error in the magnitude of a complex
108 C Bessel function can be expressed as P*10**S where P=MAX(UNIT
109 C ROUNDOFF,1.0E-18) is the nominal precision and 10**S repre-
110 C sents the increase in error due to argument reduction in the
111 C elementary functions. Here, S=MAX(1,ABS(LOG10(ABS(Z))),
112 C ABS(LOG10(FNU))) approximately (i.e., S=MAX(1,ABS(EXPONENT OF
113 C ABS(Z),ABS(EXPONENT OF FNU)) ). However, the phase angle may
114 C have only absolute accuracy. This is most likely to occur
115 C when one component (in magnitude) is larger than the other by
116 C several orders of magnitude. If one component is 10**K larger
117 C than the other, then one can expect only MAX(ABS(LOG10(P))-K,
118 C 0) significant digits; or, stated another way, when K exceeds
119 C the exponent of P, no significant digits remain in the smaller
120 C component. However, the phase angle retains absolute accuracy
121 C because, in complex arithmetic with precision P, the smaller
122 C component will not (as a rule) decrease below P times the
123 C magnitude of the larger component. In these extreme cases,
124 C the principal phase angle is on the order of +P, -P, PI/2-P,
127 C***REFERENCES 1. M. Abramowitz and I. A. Stegun, Handbook of Mathe-
128 C matical Functions, National Bureau of Standards
129 C Applied Mathematics Series 55, U. S. Department
130 C of Commerce, Tenth Printing (1972) or later.
131 C 2. D. E. Amos, Computation of Bessel Functions of
132 C Complex Argument, Report SAND83-0086, Sandia National
133 C Laboratories, Albuquerque, NM, May 1983.
134 C 3. D. E. Amos, Computation of Bessel Functions of
135 C Complex Argument and Large Order, Report SAND83-0643,
136 C Sandia National Laboratories, Albuquerque, NM, May
138 C 4. D. E. Amos, A Subroutine Package for Bessel Functions
139 C of a Complex Argument and Nonnegative Order, Report
140 C SAND85-1018, Sandia National Laboratory, Albuquerque,
142 C 5. D. E. Amos, A portable package for Bessel functions
143 C of a complex argument and nonnegative order, ACM
144 C Transactions on Mathematical Software, 12 (September
145 C 1986), pp. 265-273.
147 C***ROUTINES CALLED D1MACH, I1MACH, ZABS, ZBINU
148 C***REVISION HISTORY (YYMMDD)
149 C 830501 DATE WRITTEN
150 C 890801 REVISION DATE from Version 3.2
151 C 910415 Prologue converted to Version 4.0 format. (BAB)
152 C 920128 Category corrected. (WRB)
153 C 920811 Prologue revised. (DWL)
154 C***END PROLOGUE ZBESJ
156 C COMPLEX CI,CSGN,CY,Z,ZN
157 DOUBLE PRECISION AA
, ALIM
, ARG
, CII
, CSGNI
, CSGNR
, CYI
, CYR
, DIG
,
158 * ELIM
, FNU
, FNUL
, HPI
, RL
, R1M5
, STR
, TOL
, ZI
, ZNI
, ZNR
, ZR
,
159 * D1MACH
, BB
, FN
, AZ
, ZABS
, ASCLE
, RTOL
, ATOL
, STI
160 INTEGER I
, IERR
, INU
, INUH
, IR
, K
, KODE
, K1
, K2
, N
, NL
, NZ
, I1MACH
161 DIMENSION CYR
(N
), CYI
(N
)
163 DATA HPI
/1.57079632679489662D0
/
165 C***FIRST EXECUTABLE STATEMENT ZBESJ
168 IF (FNU
.LT
.0.0D0
) IERR
=1
169 IF (KODE
.LT
.1 .OR
. KODE
.GT
.2) IERR
=1
171 IF (IERR
.NE
.0) RETURN
172 C-----------------------------------------------------------------------
173 C SET PARAMETERS RELATED TO MACHINE CONSTANTS.
174 C TOL IS THE APPROXIMATE UNIT ROUNDOFF LIMITED TO 1.0E-18.
175 C ELIM IS THE APPROXIMATE EXPONENTIAL OVER- AND UNDERFLOW LIMIT.
176 C EXP(-ELIM).LT.EXP(-ALIM)=EXP(-ELIM)/TOL AND
177 C EXP(ELIM).GT.EXP(ALIM)=EXP(ELIM)*TOL ARE INTERVALS NEAR
178 C UNDERFLOW AND OVERFLOW LIMITS WHERE SCALED ARITHMETIC IS DONE.
179 C RL IS THE LOWER BOUNDARY OF THE ASYMPTOTIC EXPANSION FOR LARGE Z.
180 C DIG = NUMBER OF BASE 10 DIGITS IN TOL = 10**(-DIG).
181 C FNUL IS THE LOWER BOUNDARY OF THE ASYMPTOTIC SERIES FOR LARGE FNU.
182 C-----------------------------------------------------------------------
183 TOL
= MAX
(D1MACH
(4),1.0D
-18)
187 K
= MIN
(ABS
(K1
),ABS
(K2
))
188 ELIM
= 2.303D0*
(K*R1M5
-3.0D0
)
193 ALIM
= ELIM
+ MAX
(-AA
,-41.45D0
)
194 RL
= 1.2D0*DIG
+ 3.0D0
195 FNUL
= 10.0D0
+ 6.0D0*
(DIG
-3.0D0
)
196 C-----------------------------------------------------------------------
197 C TEST FOR PROPER RANGE
198 C-----------------------------------------------------------------------
204 IF (AZ
.GT
.AA
) GO TO 260
205 IF (FN
.GT
.AA
) GO TO 260
209 C-----------------------------------------------------------------------
210 C CALCULATE CSGN=EXP(FNU*HPI*I) TO MINIMIZE LOSSES OF SIGNIFICANCE
212 C-----------------------------------------------------------------------
217 ARG
= (FNU
-(INU
-IR
))*HPI
220 IF (MOD
(INUH
,2).EQ
.0) GO TO 40
224 C-----------------------------------------------------------------------
225 C ZN IS IN THE RIGHT HALF PLANE
226 C-----------------------------------------------------------------------
229 IF (ZI
.GE
.0.0D0
) GO TO 50
235 CALL ZBINU
(ZNR
, ZNI
, FNU
, KODE
, N
, CYR
, CYI
, NZ
, RL
, FNUL
, TOL
,
237 IF (NZ
.LT
.0) GO TO 130
241 ASCLE
= D1MACH
(1)*RTOL*1
.0D
+3
243 C STR = CYR(I)*CSGNR - CYI(I)*CSGNI
244 C CYI(I) = CYR(I)*CSGNI + CYI(I)*CSGNR
249 IF (MAX
(ABS
(AA
),ABS
(BB
)).GT
.ASCLE
) GO TO 55
254 STR
= AA*CSGNR
- BB*CSGNI
255 STI
= AA*CSGNI
+ BB*CSGNR
264 IF(NZ
.EQ
.(-2)) GO TO 140