00001 SUBROUTINE ZBIRY(ZR, ZI, ID, KODE, BIR, BII, IERR) 00002 C***BEGIN PROLOGUE ZBIRY 00003 C***DATE WRITTEN 830501 (YYMMDD) 00004 C***REVISION DATE 890801 (YYMMDD) 00005 C***CATEGORY NO. B5K 00006 C***KEYWORDS AIRY FUNCTION,BESSEL FUNCTIONS OF ORDER ONE THIRD 00007 C***AUTHOR AMOS, DONALD E., SANDIA NATIONAL LABORATORIES 00008 C***PURPOSE TO COMPUTE AIRY FUNCTIONS BI(Z) AND DBI(Z) FOR COMPLEX Z 00009 C***DESCRIPTION 00010 C 00011 C ***A DOUBLE PRECISION ROUTINE*** 00012 C ON KODE=1, CBIRY COMPUTES THE COMPLEX AIRY FUNCTION BI(Z) OR 00013 C ITS DERIVATIVE DBI(Z)/DZ ON ID=0 OR ID=1 RESPECTIVELY. ON 00014 C KODE=2, A SCALING OPTION CEXP(-AXZTA)*BI(Z) OR CEXP(-AXZTA)* 00015 C DBI(Z)/DZ IS PROVIDED TO REMOVE THE EXPONENTIAL BEHAVIOR IN 00016 C BOTH THE LEFT AND RIGHT HALF PLANES WHERE 00017 C ZTA=(2/3)*Z*CSQRT(Z)=CMPLX(XZTA,YZTA) AND AXZTA=ABS(XZTA). 00018 C DEFINTIONS AND NOTATION ARE FOUND IN THE NBS HANDBOOK OF 00019 C MATHEMATICAL FUNCTIONS (REF. 1). 00020 C 00021 C INPUT ZR,ZI ARE DOUBLE PRECISION 00022 C ZR,ZI - Z=CMPLX(ZR,ZI) 00023 C ID - ORDER OF DERIVATIVE, ID=0 OR ID=1 00024 C KODE - A PARAMETER TO INDICATE THE SCALING OPTION 00025 C KODE= 1 RETURNS 00026 C BI=BI(Z) ON ID=0 OR 00027 C BI=DBI(Z)/DZ ON ID=1 00028 C = 2 RETURNS 00029 C BI=CEXP(-AXZTA)*BI(Z) ON ID=0 OR 00030 C BI=CEXP(-AXZTA)*DBI(Z)/DZ ON ID=1 WHERE 00031 C ZTA=(2/3)*Z*CSQRT(Z)=CMPLX(XZTA,YZTA) 00032 C AND AXZTA=ABS(XZTA) 00033 C 00034 C OUTPUT BIR,BII ARE DOUBLE PRECISION 00035 C BIR,BII- COMPLEX ANSWER DEPENDING ON THE CHOICES FOR ID AND 00036 C KODE 00037 C IERR - ERROR FLAG 00038 C IERR=0, NORMAL RETURN - COMPUTATION COMPLETED 00039 C IERR=1, INPUT ERROR - NO COMPUTATION 00040 C IERR=2, OVERFLOW - NO COMPUTATION, REAL(Z) 00041 C TOO LARGE ON KODE=1 00042 C IERR=3, CABS(Z) LARGE - COMPUTATION COMPLETED 00043 C LOSSES OF SIGNIFCANCE BY ARGUMENT REDUCTION 00044 C PRODUCE LESS THAN HALF OF MACHINE ACCURACY 00045 C IERR=4, CABS(Z) TOO LARGE - NO COMPUTATION 00046 C COMPLETE LOSS OF ACCURACY BY ARGUMENT 00047 C REDUCTION 00048 C IERR=5, ERROR - NO COMPUTATION, 00049 C ALGORITHM TERMINATION CONDITION NOT MET 00050 C 00051 C***LONG DESCRIPTION 00052 C 00053 C BI AND DBI ARE COMPUTED FOR CABS(Z).GT.1.0 FROM THE I BESSEL 00054 C FUNCTIONS BY 00055 C 00056 C BI(Z)=C*SQRT(Z)*( I(-1/3,ZTA) + I(1/3,ZTA) ) 00057 C DBI(Z)=C * Z * ( I(-2/3,ZTA) + I(2/3,ZTA) ) 00058 C C=1.0/SQRT(3.0) 00059 C ZTA=(2/3)*Z**(3/2) 00060 C 00061 C WITH THE POWER SERIES FOR CABS(Z).LE.1.0. 00062 C 00063 C IN MOST COMPLEX VARIABLE COMPUTATION, ONE MUST EVALUATE ELE- 00064 C MENTARY FUNCTIONS. WHEN THE MAGNITUDE OF Z IS LARGE, LOSSES 00065 C OF SIGNIFICANCE BY ARGUMENT REDUCTION OCCUR. CONSEQUENTLY, IF 00066 C THE MAGNITUDE OF ZETA=(2/3)*Z**1.5 EXCEEDS U1=SQRT(0.5/UR), 00067 C THEN LOSSES EXCEEDING HALF PRECISION ARE LIKELY AND AN ERROR 00068 C FLAG IERR=3 IS TRIGGERED WHERE UR=DMAX1(D1MACH(4),1.0D-18) IS 00069 C DOUBLE PRECISION UNIT ROUNDOFF LIMITED TO 18 DIGITS PRECISION. 00070 C ALSO, IF THE MAGNITUDE OF ZETA IS LARGER THAN U2=0.5/UR, THEN 00071 C ALL SIGNIFICANCE IS LOST AND IERR=4. IN ORDER TO USE THE INT 00072 C FUNCTION, ZETA MUST BE FURTHER RESTRICTED NOT TO EXCEED THE 00073 C LARGEST INTEGER, U3=I1MACH(9). THUS, THE MAGNITUDE OF ZETA 00074 C MUST BE RESTRICTED BY MIN(U2,U3). ON 32 BIT MACHINES, U1,U2, 00075 C AND U3 ARE APPROXIMATELY 2.0E+3, 4.2E+6, 2.1E+9 IN SINGLE 00076 C PRECISION ARITHMETIC AND 1.3E+8, 1.8E+16, 2.1E+9 IN DOUBLE 00077 C PRECISION ARITHMETIC RESPECTIVELY. THIS MAKES U2 AND U3 LIMIT- 00078 C ING IN THEIR RESPECTIVE ARITHMETICS. THIS MEANS THAT THE MAG- 00079 C NITUDE OF Z CANNOT EXCEED 3.1E+4 IN SINGLE AND 2.1E+6 IN 00080 C DOUBLE PRECISION ARITHMETIC. THIS ALSO MEANS THAT ONE CAN 00081 C EXPECT TO RETAIN, IN THE WORST CASES ON 32 BIT MACHINES, 00082 C NO DIGITS IN SINGLE PRECISION AND ONLY 7 DIGITS IN DOUBLE 00083 C PRECISION ARITHMETIC. SIMILAR CONSIDERATIONS HOLD FOR OTHER 00084 C MACHINES. 00085 C 00086 C THE APPROXIMATE RELATIVE ERROR IN THE MAGNITUDE OF A COMPLEX 00087 C BESSEL FUNCTION CAN BE EXPRESSED BY P*10**S WHERE P=MAX(UNIT 00088 C ROUNDOFF,1.0E-18) IS THE NOMINAL PRECISION AND 10**S REPRE- 00089 C SENTS THE INCREASE IN ERROR DUE TO ARGUMENT REDUCTION IN THE 00090 C ELEMENTARY FUNCTIONS. HERE, S=MAX(1,ABS(LOG10(CABS(Z))), 00091 C ABS(LOG10(FNU))) APPROXIMATELY (I.E. S=MAX(1,ABS(EXPONENT OF 00092 C CABS(Z),ABS(EXPONENT OF FNU)) ). HOWEVER, THE PHASE ANGLE MAY 00093 C HAVE ONLY ABSOLUTE ACCURACY. THIS IS MOST LIKELY TO OCCUR WHEN 00094 C ONE COMPONENT (IN ABSOLUTE VALUE) IS LARGER THAN THE OTHER BY 00095 C SEVERAL ORDERS OF MAGNITUDE. IF ONE COMPONENT IS 10**K LARGER 00096 C THAN THE OTHER, THEN ONE CAN EXPECT ONLY MAX(ABS(LOG10(P))-K, 00097 C 0) SIGNIFICANT DIGITS; OR, STATED ANOTHER WAY, WHEN K EXCEEDS 00098 C THE EXPONENT OF P, NO SIGNIFICANT DIGITS REMAIN IN THE SMALLER 00099 C COMPONENT. HOWEVER, THE PHASE ANGLE RETAINS ABSOLUTE ACCURACY 00100 C BECAUSE, IN COMPLEX ARITHMETIC WITH PRECISION P, THE SMALLER 00101 C COMPONENT WILL NOT (AS A RULE) DECREASE BELOW P TIMES THE 00102 C MAGNITUDE OF THE LARGER COMPONENT. IN THESE EXTREME CASES, 00103 C THE PRINCIPAL PHASE ANGLE IS ON THE ORDER OF +P, -P, PI/2-P, 00104 C OR -PI/2+P. 00105 C 00106 C***REFERENCES HANDBOOK OF MATHEMATICAL FUNCTIONS BY M. ABRAMOWITZ 00107 C AND I. A. STEGUN, NBS AMS SERIES 55, U.S. DEPT. OF 00108 C COMMERCE, 1955. 00109 C 00110 C COMPUTATION OF BESSEL FUNCTIONS OF COMPLEX ARGUMENT 00111 C AND LARGE ORDER BY D. E. AMOS, SAND83-0643, MAY, 1983 00112 C 00113 C A SUBROUTINE PACKAGE FOR BESSEL FUNCTIONS OF A COMPLEX 00114 C ARGUMENT AND NONNEGATIVE ORDER BY D. E. AMOS, SAND85- 00115 C 1018, MAY, 1985 00116 C 00117 C A PORTABLE PACKAGE FOR BESSEL FUNCTIONS OF A COMPLEX 00118 C ARGUMENT AND NONNEGATIVE ORDER BY D. E. AMOS, TRANS. 00119 C MATH. SOFTWARE, 1986 00120 C 00121 C***ROUTINES CALLED ZBINU,XZABS,ZDIV,XZSQRT,D1MACH,I1MACH 00122 C***END PROLOGUE ZBIRY 00123 C COMPLEX BI,CONE,CSQ,CY,S1,S2,TRM1,TRM2,Z,ZTA,Z3 00124 DOUBLE PRECISION AA, AD, AK, ALIM, ATRM, AZ, AZ3, BB, BII, BIR, 00125 * BK, CC, CK, COEF, CONEI, CONER, CSQI, CSQR, CYI, CYR, C1, C2, 00126 * DIG, DK, D1, D2, EAA, ELIM, FID, FMR, FNU, FNUL, PI, RL, R1M5, 00127 * SFAC, STI, STR, S1I, S1R, S2I, S2R, TOL, TRM1I, TRM1R, TRM2I, 00128 * TRM2R, TTH, ZI, ZR, ZTAI, ZTAR, Z3I, Z3R, D1MACH, XZABS 00129 INTEGER ID, IERR, K, KODE, K1, K2, NZ, I1MACH 00130 DIMENSION CYR(2), CYI(2) 00131 DATA TTH, C1, C2, COEF, PI /6.66666666666666667D-01, 00132 * 6.14926627446000736D-01,4.48288357353826359D-01, 00133 * 5.77350269189625765D-01,3.14159265358979324D+00/ 00134 DATA CONER, CONEI /1.0D0,0.0D0/ 00135 C***FIRST EXECUTABLE STATEMENT ZBIRY 00136 IERR = 0 00137 NZ=0 00138 IF (ID.LT.0 .OR. ID.GT.1) IERR=1 00139 IF (KODE.LT.1 .OR. KODE.GT.2) IERR=1 00140 IF (IERR.NE.0) RETURN 00141 AZ = XZABS(ZR,ZI) 00142 TOL = DMAX1(D1MACH(4),1.0D-18) 00143 FID = DBLE(FLOAT(ID)) 00144 IF (AZ.GT.1.0E0) GO TO 70 00145 C----------------------------------------------------------------------- 00146 C POWER SERIES FOR CABS(Z).LE.1. 00147 C----------------------------------------------------------------------- 00148 S1R = CONER 00149 S1I = CONEI 00150 S2R = CONER 00151 S2I = CONEI 00152 IF (AZ.LT.TOL) GO TO 130 00153 AA = AZ*AZ 00154 IF (AA.LT.TOL/AZ) GO TO 40 00155 TRM1R = CONER 00156 TRM1I = CONEI 00157 TRM2R = CONER 00158 TRM2I = CONEI 00159 ATRM = 1.0D0 00160 STR = ZR*ZR - ZI*ZI 00161 STI = ZR*ZI + ZI*ZR 00162 Z3R = STR*ZR - STI*ZI 00163 Z3I = STR*ZI + STI*ZR 00164 AZ3 = AZ*AA 00165 AK = 2.0D0 + FID 00166 BK = 3.0D0 - FID - FID 00167 CK = 4.0D0 - FID 00168 DK = 3.0D0 + FID + FID 00169 D1 = AK*DK 00170 D2 = BK*CK 00171 AD = DMIN1(D1,D2) 00172 AK = 24.0D0 + 9.0D0*FID 00173 BK = 30.0D0 - 9.0D0*FID 00174 DO 30 K=1,25 00175 STR = (TRM1R*Z3R-TRM1I*Z3I)/D1 00176 TRM1I = (TRM1R*Z3I+TRM1I*Z3R)/D1 00177 TRM1R = STR 00178 S1R = S1R + TRM1R 00179 S1I = S1I + TRM1I 00180 STR = (TRM2R*Z3R-TRM2I*Z3I)/D2 00181 TRM2I = (TRM2R*Z3I+TRM2I*Z3R)/D2 00182 TRM2R = STR 00183 S2R = S2R + TRM2R 00184 S2I = S2I + TRM2I 00185 ATRM = ATRM*AZ3/AD 00186 D1 = D1 + AK 00187 D2 = D2 + BK 00188 AD = DMIN1(D1,D2) 00189 IF (ATRM.LT.TOL*AD) GO TO 40 00190 AK = AK + 18.0D0 00191 BK = BK + 18.0D0 00192 30 CONTINUE 00193 40 CONTINUE 00194 IF (ID.EQ.1) GO TO 50 00195 BIR = C1*S1R + C2*(ZR*S2R-ZI*S2I) 00196 BII = C1*S1I + C2*(ZR*S2I+ZI*S2R) 00197 IF (KODE.EQ.1) RETURN 00198 CALL XZSQRT(ZR, ZI, STR, STI) 00199 ZTAR = TTH*(ZR*STR-ZI*STI) 00200 ZTAI = TTH*(ZR*STI+ZI*STR) 00201 AA = ZTAR 00202 AA = -DABS(AA) 00203 EAA = DEXP(AA) 00204 BIR = BIR*EAA 00205 BII = BII*EAA 00206 RETURN 00207 50 CONTINUE 00208 BIR = S2R*C2 00209 BII = S2I*C2 00210 IF (AZ.LE.TOL) GO TO 60 00211 CC = C1/(1.0D0+FID) 00212 STR = S1R*ZR - S1I*ZI 00213 STI = S1R*ZI + S1I*ZR 00214 BIR = BIR + CC*(STR*ZR-STI*ZI) 00215 BII = BII + CC*(STR*ZI+STI*ZR) 00216 60 CONTINUE 00217 IF (KODE.EQ.1) RETURN 00218 CALL XZSQRT(ZR, ZI, STR, STI) 00219 ZTAR = TTH*(ZR*STR-ZI*STI) 00220 ZTAI = TTH*(ZR*STI+ZI*STR) 00221 AA = ZTAR 00222 AA = -DABS(AA) 00223 EAA = DEXP(AA) 00224 BIR = BIR*EAA 00225 BII = BII*EAA 00226 RETURN 00227 C----------------------------------------------------------------------- 00228 C CASE FOR CABS(Z).GT.1.0 00229 C----------------------------------------------------------------------- 00230 70 CONTINUE 00231 FNU = (1.0D0+FID)/3.0D0 00232 C----------------------------------------------------------------------- 00233 C SET PARAMETERS RELATED TO MACHINE CONSTANTS. 00234 C TOL IS THE APPROXIMATE UNIT ROUNDOFF LIMITED TO 1.0E-18. 00235 C ELIM IS THE APPROXIMATE EXPONENTIAL OVER- AND UNDERFLOW LIMIT. 00236 C EXP(-ELIM).LT.EXP(-ALIM)=EXP(-ELIM)/TOL AND 00237 C EXP(ELIM).GT.EXP(ALIM)=EXP(ELIM)*TOL ARE INTERVALS NEAR 00238 C UNDERFLOW AND OVERFLOW LIMITS WHERE SCALED ARITHMETIC IS DONE. 00239 C RL IS THE LOWER BOUNDARY OF THE ASYMPTOTIC EXPANSION FOR LARGE Z. 00240 C DIG = NUMBER OF BASE 10 DIGITS IN TOL = 10**(-DIG). 00241 C FNUL IS THE LOWER BOUNDARY OF THE ASYMPTOTIC SERIES FOR LARGE FNU. 00242 C----------------------------------------------------------------------- 00243 K1 = I1MACH(15) 00244 K2 = I1MACH(16) 00245 R1M5 = D1MACH(5) 00246 K = MIN0(IABS(K1),IABS(K2)) 00247 ELIM = 2.303D0*(DBLE(FLOAT(K))*R1M5-3.0D0) 00248 K1 = I1MACH(14) - 1 00249 AA = R1M5*DBLE(FLOAT(K1)) 00250 DIG = DMIN1(AA,18.0D0) 00251 AA = AA*2.303D0 00252 ALIM = ELIM + DMAX1(-AA,-41.45D0) 00253 RL = 1.2D0*DIG + 3.0D0 00254 FNUL = 10.0D0 + 6.0D0*(DIG-3.0D0) 00255 C----------------------------------------------------------------------- 00256 C TEST FOR RANGE 00257 C----------------------------------------------------------------------- 00258 AA=0.5D0/TOL 00259 BB=DBLE(FLOAT(I1MACH(9)))*0.5D0 00260 AA=DMIN1(AA,BB) 00261 AA=AA**TTH 00262 IF (AZ.GT.AA) GO TO 260 00263 AA=DSQRT(AA) 00264 IF (AZ.GT.AA) IERR=3 00265 CALL XZSQRT(ZR, ZI, CSQR, CSQI) 00266 ZTAR = TTH*(ZR*CSQR-ZI*CSQI) 00267 ZTAI = TTH*(ZR*CSQI+ZI*CSQR) 00268 C----------------------------------------------------------------------- 00269 C RE(ZTA).LE.0 WHEN RE(Z).LT.0, ESPECIALLY WHEN IM(Z) IS SMALL 00270 C----------------------------------------------------------------------- 00271 SFAC = 1.0D0 00272 AK = ZTAI 00273 IF (ZR.GE.0.0D0) GO TO 80 00274 BK = ZTAR 00275 CK = -DABS(BK) 00276 ZTAR = CK 00277 ZTAI = AK 00278 80 CONTINUE 00279 IF (ZI.NE.0.0D0 .OR. ZR.GT.0.0D0) GO TO 90 00280 ZTAR = 0.0D0 00281 ZTAI = AK 00282 90 CONTINUE 00283 AA = ZTAR 00284 IF (KODE.EQ.2) GO TO 100 00285 C----------------------------------------------------------------------- 00286 C OVERFLOW TEST 00287 C----------------------------------------------------------------------- 00288 BB = DABS(AA) 00289 IF (BB.LT.ALIM) GO TO 100 00290 BB = BB + 0.25D0*DLOG(AZ) 00291 SFAC = TOL 00292 IF (BB.GT.ELIM) GO TO 190 00293 100 CONTINUE 00294 FMR = 0.0D0 00295 IF (AA.GE.0.0D0 .AND. ZR.GT.0.0D0) GO TO 110 00296 FMR = PI 00297 IF (ZI.LT.0.0D0) FMR = -PI 00298 ZTAR = -ZTAR 00299 ZTAI = -ZTAI 00300 110 CONTINUE 00301 C----------------------------------------------------------------------- 00302 C AA=FACTOR FOR ANALYTIC CONTINUATION OF I(FNU,ZTA) 00303 C KODE=2 RETURNS EXP(-ABS(XZTA))*I(FNU,ZTA) FROM CBESI 00304 C----------------------------------------------------------------------- 00305 CALL ZBINU(ZTAR, ZTAI, FNU, KODE, 1, CYR, CYI, NZ, RL, FNUL, TOL, 00306 * ELIM, ALIM) 00307 IF (NZ.LT.0) GO TO 200 00308 AA = FMR*FNU 00309 Z3R = SFAC 00310 STR = DCOS(AA) 00311 STI = DSIN(AA) 00312 S1R = (STR*CYR(1)-STI*CYI(1))*Z3R 00313 S1I = (STR*CYI(1)+STI*CYR(1))*Z3R 00314 FNU = (2.0D0-FID)/3.0D0 00315 CALL ZBINU(ZTAR, ZTAI, FNU, KODE, 2, CYR, CYI, NZ, RL, FNUL, TOL, 00316 * ELIM, ALIM) 00317 CYR(1) = CYR(1)*Z3R 00318 CYI(1) = CYI(1)*Z3R 00319 CYR(2) = CYR(2)*Z3R 00320 CYI(2) = CYI(2)*Z3R 00321 C----------------------------------------------------------------------- 00322 C BACKWARD RECUR ONE STEP FOR ORDERS -1/3 OR -2/3 00323 C----------------------------------------------------------------------- 00324 CALL ZDIV(CYR(1), CYI(1), ZTAR, ZTAI, STR, STI) 00325 S2R = (FNU+FNU)*STR + CYR(2) 00326 S2I = (FNU+FNU)*STI + CYI(2) 00327 AA = FMR*(FNU-1.0D0) 00328 STR = DCOS(AA) 00329 STI = DSIN(AA) 00330 S1R = COEF*(S1R+S2R*STR-S2I*STI) 00331 S1I = COEF*(S1I+S2R*STI+S2I*STR) 00332 IF (ID.EQ.1) GO TO 120 00333 STR = CSQR*S1R - CSQI*S1I 00334 S1I = CSQR*S1I + CSQI*S1R 00335 S1R = STR 00336 BIR = S1R/SFAC 00337 BII = S1I/SFAC 00338 RETURN 00339 120 CONTINUE 00340 STR = ZR*S1R - ZI*S1I 00341 S1I = ZR*S1I + ZI*S1R 00342 S1R = STR 00343 BIR = S1R/SFAC 00344 BII = S1I/SFAC 00345 RETURN 00346 130 CONTINUE 00347 AA = C1*(1.0D0-FID) + FID*C2 00348 BIR = AA 00349 BII = 0.0D0 00350 RETURN 00351 190 CONTINUE 00352 IERR=2 00353 NZ=0 00354 RETURN 00355 200 CONTINUE 00356 IF(NZ.EQ.(-1)) GO TO 190 00357 NZ=0 00358 IERR=5 00359 RETURN 00360 260 CONTINUE 00361 IERR=4 00362 NZ=0 00363 RETURN 00364 END