cbesh.f 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. *DECK CBESH
  2. SUBROUTINE CBESH (Z, FNU, KODE, M, N, CY, NZ, IERR)
  3. C***BEGIN PROLOGUE CBESH
  4. C***PURPOSE Compute a sequence of the Hankel functions H(m,a,z)
  5. C for superscript m=1 or 2, real nonnegative orders a=b,
  6. C b+1,... where b>0, and nonzero complex argument z. A
  7. C scaling option is available to help avoid overflow.
  8. C***LIBRARY SLATEC
  9. C***CATEGORY C10A4
  10. C***TYPE COMPLEX (CBESH-C, ZBESH-C)
  11. C***KEYWORDS BESSEL FUNCTIONS OF COMPLEX ARGUMENT,
  12. C BESSEL FUNCTIONS OF THE THIRD KIND, H BESSEL FUNCTIONS,
  13. C HANKEL FUNCTIONS
  14. C***AUTHOR Amos, D. E., (SNL)
  15. C***DESCRIPTION
  16. C
  17. C On KODE=1, CBESH computes an N member sequence of complex
  18. C Hankel (Bessel) functions CY(L)=H(M,FNU+L-1,Z) for super-
  19. C script M=1 or 2, real nonnegative orders FNU+L-1, L=1,...,
  20. C N, and complex nonzero Z in the cut plane -pi<arg(Z)<=pi.
  21. C On KODE=2, CBESH returns the scaled functions
  22. C
  23. C CY(L) = H(M,FNU+L-1,Z)*exp(-(3-2*M)*Z*i), i**2=-1
  24. C
  25. C which removes the exponential behavior in both the upper
  26. C and lower half planes. Definitions and notation are found
  27. C in the NBS Handbook of Mathematical Functions (Ref. 1).
  28. C
  29. C Input
  30. C Z - Nonzero argument of type COMPLEX
  31. C FNU - Initial order of type REAL, FNU>=0
  32. C KODE - A parameter to indicate the scaling option
  33. C KODE=1 returns
  34. C CY(L)=H(M,FNU+L-1,Z), L=1,...,N
  35. C =2 returns
  36. C CY(L)=H(M,FNU+L-1,Z)*exp(-(3-2M)*Z*i),
  37. C L=1,...,N
  38. C M - Superscript of Hankel function, M=1 or 2
  39. C N - Number of terms in the sequence, N>=1
  40. C
  41. C Output
  42. C CY - Result vector of type COMPLEX
  43. C NZ - Number of underflows set to zero
  44. C NZ=0 Normal return
  45. C NZ>0 CY(L)=0 for NZ values of L (if M=1 and
  46. C Im(Z)>0 or if M=2 and Im(Z)<0, then
  47. C CY(L)=0 for L=1,...,NZ; in the com-
  48. C plementary half planes, the underflows
  49. C may not be in an uninterrupted sequence)
  50. C IERR - Error flag
  51. C IERR=0 Normal return - COMPUTATION COMPLETED
  52. C IERR=1 Input error - NO COMPUTATION
  53. C IERR=2 Overflow - NO COMPUTATION
  54. C (abs(Z) too small and/or FNU+N-1
  55. C too large)
  56. C IERR=3 Precision warning - COMPUTATION COMPLETED
  57. C (Result has half precision or less
  58. C because abs(Z) or FNU+N-1 is large)
  59. C IERR=4 Precision error - NO COMPUTATION
  60. C (Result has no precision because
  61. C abs(Z) or FNU+N-1 is too large)
  62. C IERR=5 Algorithmic error - NO COMPUTATION
  63. C (Termination condition not met)
  64. C
  65. C *Long Description:
  66. C
  67. C The computation is carried out by the formula
  68. C
  69. C H(m,a,z) = (1/t)*exp(-a*t)*K(a,z*exp(-t))
  70. C t = (3-2*m)*i*pi/2
  71. C
  72. C where the K Bessel function is computed as described in the
  73. C prologue to CBESK.
  74. C
  75. C Exponential decay of H(m,a,z) occurs in the upper half z
  76. C plane for m=1 and the lower half z plane for m=2. Exponential
  77. C growth occurs in the complementary half planes. Scaling
  78. C by exp(-(3-2*m)*z*i) removes the exponential behavior in the
  79. C whole z plane as z goes to infinity.
  80. C
  81. C For negative orders, the formula
  82. C
  83. C H(m,-a,z) = H(m,a,z)*exp((3-2*m)*a*pi*i)
  84. C
  85. C can be used.
  86. C
  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=R1MACH(4)=UNIT ROUNDOFF. Also,
  93. C if either is larger than U2=0.5/UR, then all significance is
  94. C lost and IERR=4. In order to use the INT function, arguments
  95. C must be further restricted not to exceed the largest machine
  96. C integer, U3=I1MACH(9). Thus, the magnitude of Z and FNU+N-1
  97. C is restricted by MIN(U2,U3). In IEEE arithmetic, U1,U2, and
  98. C U3 approximate 2.0E+3, 4.2E+6, 2.1E+9 in single precision
  99. C and 4.7E+7, 2.3E+15 and 2.1E+9 in double precision. This
  100. C makes U2 limiting in single precision and U3 limiting in
  101. C double precision. This means that one can expect to retain,
  102. C in the worst cases on IEEE machines, no digits in single pre-
  103. C cision and only 6 digits in double precision. Similar con-
  104. C siderations hold for other machines.
  105. C
  106. C The approximate relative error in the magnitude of a complex
  107. C Bessel function can be expressed as P*10**S where P=MAX(UNIT
  108. C ROUNDOFF,1.0E-18) is the nominal precision and 10**S repre-
  109. C sents the increase in error due to argument reduction in the
  110. C elementary functions. Here, S=MAX(1,ABS(LOG10(ABS(Z))),
  111. C ABS(LOG10(FNU))) approximately (i.e., S=MAX(1,ABS(EXPONENT OF
  112. C ABS(Z),ABS(EXPONENT OF FNU)) ). However, the phase angle may
  113. C have only absolute accuracy. This is most likely to occur
  114. C when one component (in magnitude) is larger than the other by
  115. C several orders of magnitude. If one component is 10**K larger
  116. C than the other, then one can expect only MAX(ABS(LOG10(P))-K,
  117. C 0) significant digits; or, stated another way, when K exceeds
  118. C the exponent of P, no significant digits remain in the smaller
  119. C component. However, the phase angle retains absolute accuracy
  120. C because, in complex arithmetic with precision P, the smaller
  121. C component will not (as a rule) decrease below P times the
  122. C magnitude of the larger component. In these extreme cases,
  123. C the principal phase angle is on the order of +P, -P, PI/2-P,
  124. C or -PI/2+P.
  125. C
  126. C***REFERENCES 1. M. Abramowitz and I. A. Stegun, Handbook of Mathe-
  127. C matical Functions, National Bureau of Standards
  128. C Applied Mathematics Series 55, U. S. Department
  129. C of Commerce, Tenth Printing (1972) or later.
  130. C 2. D. E. Amos, Computation of Bessel Functions of
  131. C Complex Argument, Report SAND83-0086, Sandia National
  132. C Laboratories, Albuquerque, NM, May 1983.
  133. C 3. D. E. Amos, Computation of Bessel Functions of
  134. C Complex Argument and Large Order, Report SAND83-0643,
  135. C Sandia National Laboratories, Albuquerque, NM, May
  136. C 1983.
  137. C 4. D. E. Amos, A Subroutine Package for Bessel Functions
  138. C of a Complex Argument and Nonnegative Order, Report
  139. C SAND85-1018, Sandia National Laboratory, Albuquerque,
  140. C NM, May 1985.
  141. C 5. D. E. Amos, A portable package for Bessel functions
  142. C of a complex argument and nonnegative order, ACM
  143. C Transactions on Mathematical Software, 12 (September
  144. C 1986), pp. 265-273.
  145. C
  146. C***ROUTINES CALLED CACON, CBKNU, CBUNK, CUOIK, I1MACH, R1MACH
  147. C***REVISION HISTORY (YYMMDD)
  148. C 830501 DATE WRITTEN
  149. C 890801 REVISION DATE from Version 3.2
  150. C 910415 Prologue converted to Version 4.0 format. (BAB)
  151. C 920128 Category corrected. (WRB)
  152. C 920811 Prologue revised. (DWL)
  153. C***END PROLOGUE CBESH
  154. C
  155. COMPLEX CY, Z, ZN, ZT, CSGN
  156. REAL AA, ALIM, ALN, ARG, AZ, CPN, DIG, ELIM, FMM, FN, FNU, FNUL,
  157. * HPI, RHPI, RL, R1M5, SGN, SPN, TOL, UFL, XN, XX, YN, YY, R1MACH,
  158. * BB, ASCLE, RTOL, ATOL
  159. INTEGER I, IERR, INU, INUH, IR, K, KODE, K1, K2, M,
  160. * MM, MR, N, NN, NUF, NW, NZ, I1MACH
  161. DIMENSION CY(N)
  162. C
  163. DATA HPI /1.57079632679489662E0/
  164. C
  165. C***FIRST EXECUTABLE STATEMENT CBESH
  166. NZ=0
  167. XX = REAL(Z)
  168. YY = AIMAG(Z)
  169. IERR = 0
  170. IF (XX.EQ.0.0E0 .AND. YY.EQ.0.0E0) IERR=1
  171. IF (FNU.LT.0.0E0) IERR=1
  172. IF (M.LT.1 .OR. M.GT.2) IERR=1
  173. IF (KODE.LT.1 .OR. KODE.GT.2) IERR=1
  174. IF (N.LT.1) IERR=1
  175. IF (IERR.NE.0) RETURN
  176. NN = N
  177. C-----------------------------------------------------------------------
  178. C SET PARAMETERS RELATED TO MACHINE CONSTANTS.
  179. C TOL IS THE APPROXIMATE UNIT ROUNDOFF LIMITED TO 1.0E-18.
  180. C ELIM IS THE APPROXIMATE EXPONENTIAL OVER- AND UNDERFLOW LIMIT.
  181. C EXP(-ELIM).LT.EXP(-ALIM)=EXP(-ELIM)/TOL AND
  182. C EXP(ELIM).GT.EXP(ALIM)=EXP(ELIM)*TOL ARE INTERVALS NEAR
  183. C UNDERFLOW AND OVERFLOW LIMITS WHERE SCALED ARITHMETIC IS DONE.
  184. C RL IS THE LOWER BOUNDARY OF THE ASYMPTOTIC EXPANSION FOR LARGE Z.
  185. C DIG = NUMBER OF BASE 10 DIGITS IN TOL = 10**(-DIG).
  186. C FNUL IS THE LOWER BOUNDARY OF THE ASYMPTOTIC SERIES FOR LARGE FNU
  187. C-----------------------------------------------------------------------
  188. TOL = MAX(R1MACH(4),1.0E-18)
  189. K1 = I1MACH(12)
  190. K2 = I1MACH(13)
  191. R1M5 = R1MACH(5)
  192. K = MIN(ABS(K1),ABS(K2))
  193. ELIM = 2.303E0*(K*R1M5-3.0E0)
  194. K1 = I1MACH(11) - 1
  195. AA = R1M5*K1
  196. DIG = MIN(AA,18.0E0)
  197. AA = AA*2.303E0
  198. ALIM = ELIM + MAX(-AA,-41.45E0)
  199. FNUL = 10.0E0 + 6.0E0*(DIG-3.0E0)
  200. RL = 1.2E0*DIG + 3.0E0
  201. FN = FNU + (NN-1)
  202. MM = 3 - M - M
  203. FMM = MM
  204. ZN = Z*CMPLX(0.0E0,-FMM)
  205. XN = REAL(ZN)
  206. YN = AIMAG(ZN)
  207. AZ = ABS(Z)
  208. C-----------------------------------------------------------------------
  209. C TEST FOR RANGE
  210. C-----------------------------------------------------------------------
  211. AA = 0.5E0/TOL
  212. BB=I1MACH(9)*0.5E0
  213. AA=MIN(AA,BB)
  214. IF(AZ.GT.AA) GO TO 240
  215. IF(FN.GT.AA) GO TO 240
  216. AA=SQRT(AA)
  217. IF(AZ.GT.AA) IERR=3
  218. IF(FN.GT.AA) IERR=3
  219. C-----------------------------------------------------------------------
  220. C OVERFLOW TEST ON THE LAST MEMBER OF THE SEQUENCE
  221. C-----------------------------------------------------------------------
  222. UFL = R1MACH(1)*1.0E+3
  223. IF (AZ.LT.UFL) GO TO 220
  224. IF (FNU.GT.FNUL) GO TO 90
  225. IF (FN.LE.1.0E0) GO TO 70
  226. IF (FN.GT.2.0E0) GO TO 60
  227. IF (AZ.GT.TOL) GO TO 70
  228. ARG = 0.5E0*AZ
  229. ALN = -FN*ALOG(ARG)
  230. IF (ALN.GT.ELIM) GO TO 220
  231. GO TO 70
  232. 60 CONTINUE
  233. CALL CUOIK(ZN, FNU, KODE, 2, NN, CY, NUF, TOL, ELIM, ALIM)
  234. IF (NUF.LT.0) GO TO 220
  235. NZ = NZ + NUF
  236. NN = NN - NUF
  237. C-----------------------------------------------------------------------
  238. C HERE NN=N OR NN=0 SINCE NUF=0,NN, OR -1 ON RETURN FROM CUOIK
  239. C IF NUF=NN, THEN CY(I)=CZERO FOR ALL I
  240. C-----------------------------------------------------------------------
  241. IF (NN.EQ.0) GO TO 130
  242. 70 CONTINUE
  243. IF ((XN.LT.0.0E0) .OR. (XN.EQ.0.0E0 .AND. YN.LT.0.0E0 .AND.
  244. * M.EQ.2)) GO TO 80
  245. C-----------------------------------------------------------------------
  246. C RIGHT HALF PLANE COMPUTATION, XN.GE.0. .AND. (XN.NE.0. .OR.
  247. C YN.GE.0. .OR. M=1)
  248. C-----------------------------------------------------------------------
  249. CALL CBKNU(ZN, FNU, KODE, NN, CY, NZ, TOL, ELIM, ALIM)
  250. GO TO 110
  251. C-----------------------------------------------------------------------
  252. C LEFT HALF PLANE COMPUTATION
  253. C-----------------------------------------------------------------------
  254. 80 CONTINUE
  255. MR = -MM
  256. CALL CACON(ZN, FNU, KODE, MR, NN, CY, NW, RL, FNUL, TOL, ELIM,
  257. * ALIM)
  258. IF (NW.LT.0) GO TO 230
  259. NZ=NW
  260. GO TO 110
  261. 90 CONTINUE
  262. C-----------------------------------------------------------------------
  263. C UNIFORM ASYMPTOTIC EXPANSIONS FOR FNU.GT.FNUL
  264. C-----------------------------------------------------------------------
  265. MR = 0
  266. IF ((XN.GE.0.0E0) .AND. (XN.NE.0.0E0 .OR. YN.GE.0.0E0 .OR.
  267. * M.NE.2)) GO TO 100
  268. MR = -MM
  269. IF (XN.EQ.0.0E0 .AND. YN.LT.0.0E0) ZN = -ZN
  270. 100 CONTINUE
  271. CALL CBUNK(ZN, FNU, KODE, MR, NN, CY, NW, TOL, ELIM, ALIM)
  272. IF (NW.LT.0) GO TO 230
  273. NZ = NZ + NW
  274. 110 CONTINUE
  275. C-----------------------------------------------------------------------
  276. C H(M,FNU,Z) = -FMM*(I/HPI)*(ZT**FNU)*K(FNU,-Z*ZT)
  277. C
  278. C ZT=EXP(-FMM*HPI*I) = CMPLX(0.0,-FMM), FMM=3-2*M, M=1,2
  279. C-----------------------------------------------------------------------
  280. SGN = SIGN(HPI,-FMM)
  281. C-----------------------------------------------------------------------
  282. C CALCULATE EXP(FNU*HPI*I) TO MINIMIZE LOSSES OF SIGNIFICANCE
  283. C WHEN FNU IS LARGE
  284. C-----------------------------------------------------------------------
  285. INU = FNU
  286. INUH = INU/2
  287. IR = INU - 2*INUH
  288. ARG = (FNU-(INU-IR))*SGN
  289. RHPI = 1.0E0/SGN
  290. CPN = RHPI*COS(ARG)
  291. SPN = RHPI*SIN(ARG)
  292. C ZN = CMPLX(-SPN,CPN)
  293. CSGN = CMPLX(-SPN,CPN)
  294. C IF (MOD(INUH,2).EQ.1) ZN = -ZN
  295. IF (MOD(INUH,2).EQ.1) CSGN = -CSGN
  296. ZT = CMPLX(0.0E0,-FMM)
  297. RTOL = 1.0E0/TOL
  298. ASCLE = UFL*RTOL
  299. DO 120 I=1,NN
  300. C CY(I) = CY(I)*ZN
  301. C ZN = ZN*ZT
  302. ZN=CY(I)
  303. AA=REAL(ZN)
  304. BB=AIMAG(ZN)
  305. ATOL=1.0E0
  306. IF (MAX(ABS(AA),ABS(BB)).GT.ASCLE) GO TO 125
  307. ZN = ZN*CMPLX(RTOL,0.0E0)
  308. ATOL = TOL
  309. 125 CONTINUE
  310. ZN = ZN*CSGN
  311. CY(I) = ZN*CMPLX(ATOL,0.0E0)
  312. CSGN = CSGN*ZT
  313. 120 CONTINUE
  314. RETURN
  315. 130 CONTINUE
  316. IF (XN.LT.0.0E0) GO TO 220
  317. RETURN
  318. 220 CONTINUE
  319. IERR=2
  320. NZ=0
  321. RETURN
  322. 230 CONTINUE
  323. IF(NW.EQ.(-1)) GO TO 220
  324. NZ=0
  325. IERR=5
  326. RETURN
  327. 240 CONTINUE
  328. NZ=0
  329. IERR=4
  330. RETURN
  331. END