1 SUBROUTINE ZBIRY
(ZR
, ZI
, ID
, KODE
, BIR
, BII
, IERR
)
2 C***BEGIN PROLOGUE ZBIRY
3 C***DATE WRITTEN 830501 (YYMMDD)
4 C***REVISION DATE 890801 (YYMMDD)
6 C***KEYWORDS AIRY FUNCTION,BESSEL FUNCTIONS OF ORDER ONE THIRD
7 C***AUTHOR AMOS, DONALD E., SANDIA NATIONAL LABORATORIES
8 C***PURPOSE TO COMPUTE AIRY FUNCTIONS BI(Z) AND DBI(Z) FOR COMPLEX Z
11 C ***A DOUBLE PRECISION ROUTINE***
12 C ON KODE=1, CBIRY COMPUTES THE COMPLEX AIRY FUNCTION BI(Z) OR
13 C ITS DERIVATIVE DBI(Z)/DZ ON ID=0 OR ID=1 RESPECTIVELY. ON
14 C KODE=2, A SCALING OPTION CEXP(-AXZTA)*BI(Z) OR CEXP(-AXZTA)*
15 C DBI(Z)/DZ IS PROVIDED TO REMOVE THE EXPONENTIAL BEHAVIOR IN
16 C BOTH THE LEFT AND RIGHT HALF PLANES WHERE
17 C ZTA=(2/3)*Z*CSQRT(Z)=CMPLX(XZTA,YZTA) AND AXZTA=ABS(XZTA).
18 C DEFINITIONS AND NOTATION ARE FOUND IN THE NBS HANDBOOK OF
19 C MATHEMATICAL FUNCTIONS (REF. 1).
21 C INPUT ZR,ZI ARE DOUBLE PRECISION
22 C ZR,ZI - Z=CMPLX(ZR,ZI)
23 C ID - ORDER OF DERIVATIVE, ID=0 OR ID=1
24 C KODE - A PARAMETER TO INDICATE THE SCALING OPTION
27 C BI=DBI(Z)/DZ ON ID=1
29 C BI=CEXP(-AXZTA)*BI(Z) ON ID=0 OR
30 C BI=CEXP(-AXZTA)*DBI(Z)/DZ ON ID=1 WHERE
31 C ZTA=(2/3)*Z*CSQRT(Z)=CMPLX(XZTA,YZTA)
34 C OUTPUT BIR,BII ARE DOUBLE PRECISION
35 C BIR,BII- COMPLEX ANSWER DEPENDING ON THE CHOICES FOR ID AND
38 C IERR=0, NORMAL RETURN - COMPUTATION COMPLETED
39 C IERR=1, INPUT ERROR - NO COMPUTATION
40 C IERR=2, OVERFLOW - NO COMPUTATION, REAL(Z)
42 C IERR=3, CABS(Z) LARGE - COMPUTATION COMPLETED
43 C LOSSES OF SIGNIFCANCE BY ARGUMENT REDUCTION
44 C PRODUCE LESS THAN HALF OF MACHINE ACCURACY
45 C IERR=4, CABS(Z) TOO LARGE - NO COMPUTATION
46 C COMPLETE LOSS OF ACCURACY BY ARGUMENT
48 C IERR=5, ERROR - NO COMPUTATION,
49 C ALGORITHM TERMINATION CONDITION NOT MET
53 C BI AND DBI ARE COMPUTED FOR CABS(Z).GT.1.0 FROM THE I BESSEL
56 C BI(Z)=C*SQRT(Z)*( I(-1/3,ZTA) + I(1/3,ZTA) )
57 C DBI(Z)=C * Z * ( I(-2/3,ZTA) + I(2/3,ZTA) )
61 C WITH THE POWER SERIES FOR CABS(Z).LE.1.0.
63 C IN MOST COMPLEX VARIABLE COMPUTATION, ONE MUST EVALUATE ELE-
64 C MENTARY FUNCTIONS. WHEN THE MAGNITUDE OF Z IS LARGE, LOSSES
65 C OF SIGNIFICANCE BY ARGUMENT REDUCTION OCCUR. CONSEQUENTLY, IF
66 C THE MAGNITUDE OF ZETA=(2/3)*Z**1.5 EXCEEDS U1=SQRT(0.5/UR),
67 C THEN LOSSES EXCEEDING HALF PRECISION ARE LIKELY AND AN ERROR
68 C FLAG IERR=3 IS TRIGGERED WHERE UR=DMAX1(D1MACH(4),1.0D-18) IS
69 C DOUBLE PRECISION UNIT ROUNDOFF LIMITED TO 18 DIGITS PRECISION.
70 C ALSO, IF THE MAGNITUDE OF ZETA IS LARGER THAN U2=0.5/UR, THEN
71 C ALL SIGNIFICANCE IS LOST AND IERR=4. IN ORDER TO USE THE INT
72 C FUNCTION, ZETA MUST BE FURTHER RESTRICTED NOT TO EXCEED THE
73 C LARGEST INTEGER, U3=I1MACH(9). THUS, THE MAGNITUDE OF ZETA
74 C MUST BE RESTRICTED BY MIN(U2,U3). ON 32 BIT MACHINES, U1,U2,
75 C AND U3 ARE APPROXIMATELY 2.0E+3, 4.2E+6, 2.1E+9 IN SINGLE
76 C PRECISION ARITHMETIC AND 1.3E+8, 1.8E+16, 2.1E+9 IN DOUBLE
77 C PRECISION ARITHMETIC RESPECTIVELY. THIS MAKES U2 AND U3 LIMIT-
78 C ING IN THEIR RESPECTIVE ARITHMETICS. THIS MEANS THAT THE MAG-
79 C NITUDE OF Z CANNOT EXCEED 3.1E+4 IN SINGLE AND 2.1E+6 IN
80 C DOUBLE PRECISION ARITHMETIC. THIS ALSO MEANS THAT ONE CAN
81 C EXPECT TO RETAIN, IN THE WORST CASES ON 32 BIT MACHINES,
82 C NO DIGITS IN SINGLE PRECISION AND ONLY 7 DIGITS IN DOUBLE
83 C PRECISION ARITHMETIC. SIMILAR CONSIDERATIONS HOLD FOR OTHER
86 C THE APPROXIMATE RELATIVE ERROR IN THE MAGNITUDE OF A COMPLEX
87 C BESSEL FUNCTION CAN BE EXPRESSED BY P*10**S WHERE P=MAX(UNIT
88 C ROUNDOFF,1.0E-18) IS THE NOMINAL PRECISION AND 10**S REPRE-
89 C SENTS THE INCREASE IN ERROR DUE TO ARGUMENT REDUCTION IN THE
90 C ELEMENTARY FUNCTIONS. HERE, S=MAX(1,ABS(LOG10(CABS(Z))),
91 C ABS(LOG10(FNU))) APPROXIMATELY (I.E. S=MAX(1,ABS(EXPONENT OF
92 C CABS(Z),ABS(EXPONENT OF FNU)) ). HOWEVER, THE PHASE ANGLE MAY
93 C HAVE ONLY ABSOLUTE ACCURACY. THIS IS MOST LIKELY TO OCCUR WHEN
94 C ONE COMPONENT (IN ABSOLUTE VALUE) IS LARGER THAN THE OTHER BY
95 C SEVERAL ORDERS OF MAGNITUDE. IF ONE COMPONENT IS 10**K LARGER
96 C THAN THE OTHER, THEN ONE CAN EXPECT ONLY MAX(ABS(LOG10(P))-K,
97 C 0) SIGNIFICANT DIGITS; OR, STATED ANOTHER WAY, WHEN K EXCEEDS
98 C THE EXPONENT OF P, NO SIGNIFICANT DIGITS REMAIN IN THE SMALLER
99 C COMPONENT. HOWEVER, THE PHASE ANGLE RETAINS ABSOLUTE ACCURACY
100 C BECAUSE, IN COMPLEX ARITHMETIC WITH PRECISION P, THE SMALLER
101 C COMPONENT WILL NOT (AS A RULE) DECREASE BELOW P TIMES THE
102 C MAGNITUDE OF THE LARGER COMPONENT. IN THESE EXTREME CASES,
103 C THE PRINCIPAL PHASE ANGLE IS ON THE ORDER OF +P, -P, PI/2-P,
106 C***REFERENCES HANDBOOK OF MATHEMATICAL FUNCTIONS BY M. ABRAMOWITZ
107 C AND I. A. STEGUN, NBS AMS SERIES 55, U.S. DEPT. OF
110 C COMPUTATION OF BESSEL FUNCTIONS OF COMPLEX ARGUMENT
111 C AND LARGE ORDER BY D. E. AMOS, SAND83-0643, MAY, 1983
113 C A SUBROUTINE PACKAGE FOR BESSEL FUNCTIONS OF A COMPLEX
114 C ARGUMENT AND NONNEGATIVE ORDER BY D. E. AMOS, SAND85-
117 C A PORTABLE PACKAGE FOR BESSEL FUNCTIONS OF A COMPLEX
118 C ARGUMENT AND NONNEGATIVE ORDER BY D. E. AMOS, TRANS.
119 C MATH. SOFTWARE, 1986
121 C***ROUTINES CALLED ZBINU,AZABS,ZDIV,AZSQRT,D1MACH,I1MACH
122 C***END PROLOGUE ZBIRY
123 C COMPLEX BI,CONE,CSQ,CY,S1,S2,TRM1,TRM2,Z,ZTA,Z3
124 DOUBLE PRECISION AA
, AD
, AK
, ALIM
, ATRM
, AZ
, AZ3
, BB
, BII
, BIR
,
125 * BK
, CC
, CK
, COEF
, CONEI
, CONER
, CSQI
, CSQR
, CYI
, CYR
, C1
, C2
,
126 * DIG
, DK
, D1
, D2
, EAA
, ELIM
, FID
, FMR
, FNU
, FNUL
, PI
, RL
, R1M5
,
127 * SFAC
, STI
, STR
, S1I
, S1R
, S2I
, S2R
, TOL
, TRM1I
, TRM1R
, TRM2I
,
128 * TRM2R
, TTH
, ZI
, ZR
, ZTAI
, ZTAR
, Z3I
, Z3R
, D1MACH
, AZABS
129 INTEGER ID
, IERR
, K
, KODE
, K1
, K2
, NZ
, I1MACH
130 DIMENSION CYR
(2), CYI
(2)
131 DATA TTH
, C1
, C2
, COEF
, PI
/6.66666666666666667D
-01,
132 * 6.14926627446000736D
-01,4.48288357353826359D
-01,
133 * 5.77350269189625765D
-01,3.14159265358979324D
+00/
134 DATA CONER
, CONEI
/1.0D0
,0.0D0
/
135 C***FIRST EXECUTABLE STATEMENT ZBIRY
138 IF (ID
.LT
.0 .OR
. ID
.GT
.1) IERR
=1
139 IF (KODE
.LT
.1 .OR
. KODE
.GT
.2) IERR
=1
140 IF (IERR
.NE
.0) RETURN
142 TOL
= DMAX1
(D1MACH
(4),1.0D
-18)
143 FID
= DBLE
(FLOAT
(ID
))
144 IF (AZ
.GT
.1.0E0
) GO TO 70
145 C-----------------------------------------------------------------------
146 C POWER SERIES FOR CABS(Z).LE.1.
147 C-----------------------------------------------------------------------
152 IF (AZ
.LT
.TOL
) GO TO 130
154 IF (AA
.LT
.TOL
/AZ
) GO TO 40
162 Z3R
= STR*ZR
- STI*ZI
163 Z3I
= STR*ZI
+ STI*ZR
166 BK
= 3.0D0
- FID
- FID
168 DK
= 3.0D0
+ FID
+ FID
172 AK
= 24.0D0
+ 9.0D0*FID
173 BK
= 30.0D0
- 9.0D0*FID
175 STR
= (TRM1R*Z3R
-TRM1I*Z3I
)/D1
176 TRM1I
= (TRM1R*Z3I
+TRM1I*Z3R
)/D1
180 STR
= (TRM2R*Z3R
-TRM2I*Z3I
)/D2
181 TRM2I
= (TRM2R*Z3I
+TRM2I*Z3R
)/D2
189 IF (ATRM
.LT
.TOL*AD
) GO TO 40
194 IF (ID
.EQ
.1) GO TO 50
195 BIR
= C1*S1R
+ C2*
(ZR*S2R
-ZI*S2I
)
196 BII
= C1*S1I
+ C2*
(ZR*S2I
+ZI*S2R
)
197 IF (KODE
.EQ
.1) RETURN
198 CALL AZSQRT
(ZR
, ZI
, STR
, STI
)
199 ZTAR
= TTH*
(ZR*STR
-ZI*STI
)
200 ZTAI
= TTH*
(ZR*STI
+ZI*STR
)
210 IF (AZ
.LE
.TOL
) GO TO 60
212 STR
= S1R*ZR
- S1I*ZI
213 STI
= S1R*ZI
+ S1I*ZR
214 BIR
= BIR
+ CC*
(STR*ZR
-STI*ZI
)
215 BII
= BII
+ CC*
(STR*ZI
+STI*ZR
)
217 IF (KODE
.EQ
.1) RETURN
218 CALL AZSQRT
(ZR
, ZI
, STR
, STI
)
219 ZTAR
= TTH*
(ZR*STR
-ZI*STI
)
220 ZTAI
= TTH*
(ZR*STI
+ZI*STR
)
227 C-----------------------------------------------------------------------
228 C CASE FOR CABS(Z).GT.1.0
229 C-----------------------------------------------------------------------
231 FNU
= (1.0D0
+FID
)/3.0D0
232 C-----------------------------------------------------------------------
233 C SET PARAMETERS RELATED TO MACHINE CONSTANTS.
234 C TOL IS THE APPROXIMATE UNIT ROUNDOFF LIMITED TO 1.0E-18.
235 C ELIM IS THE APPROXIMATE EXPONENTIAL OVER- AND UNDERFLOW LIMIT.
236 C EXP(-ELIM).LT.EXP(-ALIM)=EXP(-ELIM)/TOL AND
237 C EXP(ELIM).GT.EXP(ALIM)=EXP(ELIM)*TOL ARE INTERVALS NEAR
238 C UNDERFLOW AND OVERFLOW LIMITS WHERE SCALED ARITHMETIC IS DONE.
239 C RL IS THE LOWER BOUNDARY OF THE ASYMPTOTIC EXPANSION FOR LARGE Z.
240 C DIG = NUMBER OF BASE 10 DIGITS IN TOL = 10**(-DIG).
241 C FNUL IS THE LOWER BOUNDARY OF THE ASYMPTOTIC SERIES FOR LARGE FNU.
242 C-----------------------------------------------------------------------
246 K
= MIN0
(IABS
(K1
),IABS
(K2
))
247 ELIM
= 2.303D0*
(DBLE
(FLOAT
(K
))*R1M5
-3.0D0
)
249 AA
= R1M5*DBLE
(FLOAT
(K1
))
250 DIG
= DMIN1
(AA
,18.0D0
)
252 ALIM
= ELIM
+ DMAX1
(-AA
,-41.45D0
)
253 RL
= 1.2D0*DIG
+ 3.0D0
254 FNUL
= 10.0D0
+ 6.0D0*
(DIG
-3.0D0
)
255 C-----------------------------------------------------------------------
257 C-----------------------------------------------------------------------
259 BB
=DBLE
(FLOAT
(I1MACH
(9)))*0.5D0
262 IF (AZ
.GT
.AA
) GO TO 260
265 CALL AZSQRT
(ZR
, ZI
, CSQR
, CSQI
)
266 ZTAR
= TTH*
(ZR*CSQR
-ZI*CSQI
)
267 ZTAI
= TTH*
(ZR*CSQI
+ZI*CSQR
)
268 C-----------------------------------------------------------------------
269 C RE(ZTA).LE.0 WHEN RE(Z).LT.0, ESPECIALLY WHEN IM(Z) IS SMALL
270 C-----------------------------------------------------------------------
273 IF (ZR
.GE
.0.0D0
) GO TO 80
279 IF (ZI
.NE
.0.0D0
.OR
. ZR
.GT
.0.0D0
) GO TO 90
284 IF (KODE
.EQ
.2) GO TO 100
285 C-----------------------------------------------------------------------
287 C-----------------------------------------------------------------------
289 IF (BB
.LT
.ALIM
) GO TO 100
290 BB
= BB
+ 0.25D0*DLOG
(AZ
)
292 IF (BB
.GT
.ELIM
) GO TO 190
295 IF (AA
.GE
.0.0D0
.AND
. ZR
.GT
.0.0D0
) GO TO 110
297 IF (ZI
.LT
.0.0D0
) FMR
= -PI
301 C-----------------------------------------------------------------------
302 C AA=FACTOR FOR ANALYTIC CONTINUATION OF I(FNU,ZTA)
303 C KODE=2 RETURNS EXP(-ABS(XZTA))*I(FNU,ZTA) FROM CBESI
304 C-----------------------------------------------------------------------
305 CALL ZBINU
(ZTAR
, ZTAI
, FNU
, KODE
, 1, CYR
, CYI
, NZ
, RL
, FNUL
, TOL
,
307 IF (NZ
.LT
.0) GO TO 200
312 S1R
= (STR*CYR
(1)-STI*CYI
(1))*Z3R
313 S1I
= (STR*CYI
(1)+STI*CYR
(1))*Z3R
314 FNU
= (2.0D0
-FID
)/3.0D0
315 CALL ZBINU
(ZTAR
, ZTAI
, FNU
, KODE
, 2, CYR
, CYI
, NZ
, RL
, FNUL
, TOL
,
321 C-----------------------------------------------------------------------
322 C BACKWARD RECUR ONE STEP FOR ORDERS -1/3 OR -2/3
323 C-----------------------------------------------------------------------
324 CALL ZDIV
(CYR
(1), CYI
(1), ZTAR
, ZTAI
, STR
, STI
)
325 S2R
= (FNU
+FNU
)*STR
+ CYR
(2)
326 S2I
= (FNU
+FNU
)*STI
+ CYI
(2)
330 S1R
= COEF*
(S1R
+S2R*STR
-S2I*STI
)
331 S1I
= COEF*
(S1I
+S2R*STI
+S2I*STR
)
332 IF (ID
.EQ
.1) GO TO 120
333 STR
= CSQR*S1R
- CSQI*S1I
334 S1I
= CSQR*S1I
+ CSQI*S1R
340 STR
= ZR*S1R
- ZI*S1I
341 S1I
= ZR*S1I
+ ZI*S1R
347 AA
= C1*
(1.0D0
-FID
) + FID*C2
356 IF(NZ
.EQ
.(-1)) GO TO 190