zairy.f

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