cbesj.f 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. *DECK CBESJ
  2. SUBROUTINE CBESJ (Z, FNU, KODE, N, CY, NZ, IERR)
  3. C***BEGIN PROLOGUE CBESJ
  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
  7. C help avoid overflow.
  8. C***LIBRARY SLATEC
  9. C***CATEGORY C10A4
  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)
  14. C***DESCRIPTION
  15. C
  16. C On KODE=1, CBESJ computes an N member sequence of complex
  17. C Bessel functions CY(L)=J(FNU+L-1,Z) for real nonnegative
  18. C orders FNU+L-1, L=1,...,N and complex Z in the cut plane
  19. C -pi<arg(Z)<=pi. On KODE=2, CBESJ returns the scaled functions
  20. C
  21. C CY(L) = exp(-abs(Y))*J(FNU+L-1,Z), L=1,...,N and Y=Im(Z)
  22. C
  23. C which remove the exponential growth in both the upper and
  24. C lower half planes as Z goes to infinity. Definitions and
  25. C notation are found in the NBS Handbook of Mathematical
  26. C Functions (Ref. 1).
  27. C
  28. C Input
  29. C Z - Argument of type COMPLEX
  30. C FNU - Initial order of type REAL, FNU>=0
  31. C KODE - A parameter to indicate the scaling option
  32. C KODE=1 returns
  33. C CY(L)=J(FNU+L-1,Z), L=1,...,N
  34. C =2 returns
  35. C CY(L)=J(FNU+L-1,Z)*exp(-abs(Y)), L=1,...,N
  36. C where Y=Im(Z)
  37. C N - Number of terms in the sequence, N>=1
  38. C
  39. C Output
  40. C CY - Result vector of type COMPLEX
  41. C NZ - Number of underflows set to zero
  42. C NZ=0 Normal return
  43. C NZ>0 CY(L)=0, L=N-NZ+1,...,N
  44. C IERR - Error flag
  45. C IERR=0 Normal return - COMPUTATION COMPLETED
  46. C IERR=1 Input error - NO COMPUTATION
  47. C IERR=2 Overflow - NO COMPUTATION
  48. C (Im(Z) too large on KODE=1)
  49. C IERR=3 Precision warning - COMPUTATION COMPLETED
  50. C (Result has half precision or less
  51. C because abs(Z) or FNU+N-1 is large)
  52. C IERR=4 Precision error - NO COMPUTATION
  53. C (Result has no precision because
  54. C abs(Z) or FNU+N-1 is too large)
  55. C IERR=5 Algorithmic error - NO COMPUTATION
  56. C (Termination condition not met)
  57. C
  58. C *Long Description:
  59. C
  60. C The computation is carried out by the formulae
  61. C
  62. C J(a,z) = exp( a*pi*i/2)*I(a,-i*z), Im(z)>=0
  63. C
  64. C J(a,z) = exp(-a*pi*i/2)*I(a, i*z), Im(z)<0
  65. C
  66. C where the I Bessel function is computed as described in the
  67. C prologue to CBESI.
  68. C
  69. C For negative orders, the formula
  70. C
  71. C J(-a,z) = J(a,z)*cos(a*pi) - Y(a,z)*sin(a*pi)
  72. C
  73. C can be used. However, for large orders close to integers, the
  74. C the function changes radically. When a is a large positive
  75. C integer, the magnitude of J(-a,z)=J(a,z)*cos(a*pi) is a
  76. C large negative power of ten. But when a is not an integer,
  77. C Y(a,z) dominates in magnitude with a large positive power of
  78. C ten and the most that the second term can be reduced is by
  79. C unit roundoff from the coefficient. Thus, wide changes can
  80. C occur within unit roundoff of a large integer for a. Here,
  81. C large means a>abs(z).
  82. C
  83. C In most complex variable computation, one must evaluate ele-
  84. C mentary functions. When the magnitude of Z or FNU+N-1 is
  85. C large, losses of significance by argument reduction occur.
  86. C Consequently, if either one exceeds U1=SQRT(0.5/UR), then
  87. C losses exceeding half precision are likely and an error flag
  88. C IERR=3 is triggered where UR=R1MACH(4)=UNIT ROUNDOFF. Also,
  89. C if either is larger than U2=0.5/UR, then all significance is
  90. C lost and IERR=4. In order to use the INT function, arguments
  91. C must be further restricted not to exceed the largest machine
  92. C integer, U3=I1MACH(9). Thus, the magnitude of Z and FNU+N-1
  93. C is restricted by MIN(U2,U3). In IEEE arithmetic, U1,U2, and
  94. C U3 approximate 2.0E+3, 4.2E+6, 2.1E+9 in single precision
  95. C and 4.7E+7, 2.3E+15 and 2.1E+9 in double precision. This
  96. C makes U2 limiting in single precision and U3 limiting in
  97. C double precision. This means that one can expect to retain,
  98. C in the worst cases on IEEE machines, no digits in single pre-
  99. C cision and only 6 digits in double precision. Similar con-
  100. C siderations hold for other machines.
  101. C
  102. C The approximate relative error in the magnitude of a complex
  103. C Bessel function can be expressed as P*10**S where P=MAX(UNIT
  104. C ROUNDOFF,1.0E-18) is the nominal precision and 10**S repre-
  105. C sents the increase in error due to argument reduction in the
  106. C elementary functions. Here, S=MAX(1,ABS(LOG10(ABS(Z))),
  107. C ABS(LOG10(FNU))) approximately (i.e., S=MAX(1,ABS(EXPONENT OF
  108. C ABS(Z),ABS(EXPONENT OF FNU)) ). However, the phase angle may
  109. C have only absolute accuracy. This is most likely to occur
  110. C when one component (in magnitude) is larger than the other by
  111. C several orders of magnitude. If one component is 10**K larger
  112. C than the other, then one can expect only MAX(ABS(LOG10(P))-K,
  113. C 0) significant digits; or, stated another way, when K exceeds
  114. C the exponent of P, no significant digits remain in the smaller
  115. C component. However, the phase angle retains absolute accuracy
  116. C because, in complex arithmetic with precision P, the smaller
  117. C component will not (as a rule) decrease below P times the
  118. C magnitude of the larger component. In these extreme cases,
  119. C the principal phase angle is on the order of +P, -P, PI/2-P,
  120. C or -PI/2+P.
  121. C
  122. C***REFERENCES 1. M. Abramowitz and I. A. Stegun, Handbook of Mathe-
  123. C matical Functions, National Bureau of Standards
  124. C Applied Mathematics Series 55, U. S. Department
  125. C of Commerce, Tenth Printing (1972) or later.
  126. C 2. D. E. Amos, Computation of Bessel Functions of
  127. C Complex Argument, Report SAND83-0086, Sandia National
  128. C Laboratories, Albuquerque, NM, May 1983.
  129. C 3. D. E. Amos, Computation of Bessel Functions of
  130. C Complex Argument and Large Order, Report SAND83-0643,
  131. C Sandia National Laboratories, Albuquerque, NM, May
  132. C 1983.
  133. C 4. D. E. Amos, A Subroutine Package for Bessel Functions
  134. C of a Complex Argument and Nonnegative Order, Report
  135. C SAND85-1018, Sandia National Laboratory, Albuquerque,
  136. C NM, May 1985.
  137. C 5. D. E. Amos, A portable package for Bessel functions
  138. C of a complex argument and nonnegative order, ACM
  139. C Transactions on Mathematical Software, 12 (September
  140. C 1986), pp. 265-273.
  141. C
  142. C***ROUTINES CALLED CBINU, I1MACH, R1MACH
  143. C***REVISION HISTORY (YYMMDD)
  144. C 830501 DATE WRITTEN
  145. C 890801 REVISION DATE from Version 3.2
  146. C 910415 Prologue converted to Version 4.0 format. (BAB)
  147. C 920128 Category corrected. (WRB)
  148. C 920811 Prologue revised. (DWL)
  149. C***END PROLOGUE CBESJ
  150. C
  151. COMPLEX CI, CSGN, CY, Z, ZN
  152. REAL AA, ALIM, ARG, DIG, ELIM, FNU, FNUL, HPI, RL, R1, R1M5, R2,
  153. * TOL, YY, R1MACH, AZ, FN, BB, ASCLE, RTOL, ATOL
  154. INTEGER I, IERR, INU, INUH, IR, KODE, K1, K2, N, NL, NZ, I1MACH, K
  155. DIMENSION CY(N)
  156. DATA HPI /1.57079632679489662E0/
  157. C
  158. C***FIRST EXECUTABLE STATEMENT CBESJ
  159. IERR = 0
  160. NZ=0
  161. IF (FNU.LT.0.0E0) IERR=1
  162. IF (KODE.LT.1 .OR. KODE.GT.2) IERR=1
  163. IF (N.LT.1) IERR=1
  164. IF (IERR.NE.0) RETURN
  165. C-----------------------------------------------------------------------
  166. C SET PARAMETERS RELATED TO MACHINE CONSTANTS.
  167. C TOL IS THE APPROXIMATE UNIT ROUNDOFF LIMITED TO 1.0E-18.
  168. C ELIM IS THE APPROXIMATE EXPONENTIAL OVER- AND UNDERFLOW LIMIT.
  169. C EXP(-ELIM).LT.EXP(-ALIM)=EXP(-ELIM)/TOL AND
  170. C EXP(ELIM).GT.EXP(ALIM)=EXP(ELIM)*TOL ARE INTERVALS NEAR
  171. C UNDERFLOW AND OVERFLOW LIMITS WHERE SCALED ARITHMETIC IS DONE.
  172. C RL IS THE LOWER BOUNDARY OF THE ASYMPTOTIC EXPANSION FOR LARGE Z.
  173. C DIG = NUMBER OF BASE 10 DIGITS IN TOL = 10**(-DIG).
  174. C FNUL IS THE LOWER BOUNDARY OF THE ASYMPTOTIC SERIES FOR LARGE FNU.
  175. C-----------------------------------------------------------------------
  176. TOL = MAX(R1MACH(4),1.0E-18)
  177. K1 = I1MACH(12)
  178. K2 = I1MACH(13)
  179. R1M5 = R1MACH(5)
  180. K = MIN(ABS(K1),ABS(K2))
  181. ELIM = 2.303E0*(K*R1M5-3.0E0)
  182. K1 = I1MACH(11) - 1
  183. AA = R1M5*K1
  184. DIG = MIN(AA,18.0E0)
  185. AA = AA*2.303E0
  186. ALIM = ELIM + MAX(-AA,-41.45E0)
  187. RL = 1.2E0*DIG + 3.0E0
  188. FNUL = 10.0E0 + 6.0E0*(DIG-3.0E0)
  189. CI = CMPLX(0.0E0,1.0E0)
  190. YY = AIMAG(Z)
  191. AZ = ABS(Z)
  192. C-----------------------------------------------------------------------
  193. C TEST FOR RANGE
  194. C-----------------------------------------------------------------------
  195. AA = 0.5E0/TOL
  196. BB=I1MACH(9)*0.5E0
  197. AA=MIN(AA,BB)
  198. FN=FNU+(N-1)
  199. IF(AZ.GT.AA) GO TO 140
  200. IF(FN.GT.AA) GO TO 140
  201. AA=SQRT(AA)
  202. IF(AZ.GT.AA) IERR=3
  203. IF(FN.GT.AA) IERR=3
  204. C-----------------------------------------------------------------------
  205. C CALCULATE CSGN=EXP(FNU*HPI*I) TO MINIMIZE LOSSES OF SIGNIFICANCE
  206. C WHEN FNU IS LARGE
  207. C-----------------------------------------------------------------------
  208. INU = FNU
  209. INUH = INU/2
  210. IR = INU - 2*INUH
  211. ARG = (FNU-(INU-IR))*HPI
  212. R1 = COS(ARG)
  213. R2 = SIN(ARG)
  214. CSGN = CMPLX(R1,R2)
  215. IF (MOD(INUH,2).EQ.1) CSGN = -CSGN
  216. C-----------------------------------------------------------------------
  217. C ZN IS IN THE RIGHT HALF PLANE
  218. C-----------------------------------------------------------------------
  219. ZN = -Z*CI
  220. IF (YY.GE.0.0E0) GO TO 40
  221. ZN = -ZN
  222. CSGN = CONJG(CSGN)
  223. CI = CONJG(CI)
  224. 40 CONTINUE
  225. CALL CBINU(ZN, FNU, KODE, N, CY, NZ, RL, FNUL, TOL, ELIM, ALIM)
  226. IF (NZ.LT.0) GO TO 120
  227. NL = N - NZ
  228. IF (NL.EQ.0) RETURN
  229. RTOL = 1.0E0/TOL
  230. ASCLE = R1MACH(1)*RTOL*1.0E+3
  231. DO 50 I=1,NL
  232. C CY(I)=CY(I)*CSGN
  233. ZN=CY(I)
  234. AA=REAL(ZN)
  235. BB=AIMAG(ZN)
  236. ATOL=1.0E0
  237. IF (MAX(ABS(AA),ABS(BB)).GT.ASCLE) GO TO 55
  238. ZN = ZN*CMPLX(RTOL,0.0E0)
  239. ATOL = TOL
  240. 55 CONTINUE
  241. ZN = ZN*CSGN
  242. CY(I) = ZN*CMPLX(ATOL,0.0E0)
  243. CSGN = CSGN*CI
  244. 50 CONTINUE
  245. RETURN
  246. 120 CONTINUE
  247. IF(NZ.EQ.(-2)) GO TO 130
  248. NZ = 0
  249. IERR = 2
  250. RETURN
  251. 130 CONTINUE
  252. NZ=0
  253. IERR=5
  254. RETURN
  255. 140 CONTINUE
  256. NZ=0
  257. IERR=4
  258. RETURN
  259. END