zbesy.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. /* zbesy.f -- translated by f2c (version 20100827).
  2. This file no longer depends on f2c.
  3. */
  4. #include "slatec-internal.hpp"
  5. /* Table of constant values */
  6. static integer const c__1 = 1;
  7. static integer const c__2 = 2;
  8. static integer const c__4 = 4;
  9. static integer const c__15 = 15;
  10. static integer const c__16 = 16;
  11. static integer const c__5 = 5;
  12. int zbesy_(double *zr, double *zi, double const *fnu,
  13. integer const *kode, integer const *n, double *cyr, double *cyi, integer *
  14. nz, double *cwrkr, double *cwrki, integer *ierr)
  15. {
  16. /* System generated locals */
  17. integer i__1, i__2;
  18. double d__1, d__2;
  19. /* Local variables */
  20. integer i__, k, k1, k2;
  21. double aa, bb, ey, c1i, c2i, c1r, c2r;
  22. integer nz1, nz2;
  23. double exi, r1m5, exr, sti, tay, tol, str, hcii, elim, atol, rtol, ascle;
  24. /* ***BEGIN PROLOGUE ZBESY */
  25. /* ***PURPOSE Compute a sequence of the Bessel functions Y(a,z) for */
  26. /* complex argument z and real nonnegative orders a=b,b+1, */
  27. /* b+2,... where b>0. A scaling option is available to */
  28. /* help avoid overflow. */
  29. /* ***LIBRARY SLATEC */
  30. /* ***CATEGORY C10A4 */
  31. /* ***TYPE COMPLEX (CBESY-C, ZBESY-C) */
  32. /* ***KEYWORDS BESSEL FUNCTIONS OF COMPLEX ARGUMENT, */
  33. /* BESSEL FUNCTIONS OF SECOND KIND, WEBER'S FUNCTION, */
  34. /* Y BESSEL FUNCTIONS */
  35. /* ***AUTHOR Amos, D. E., (SNL) */
  36. /* ***DESCRIPTION */
  37. /* ***A DOUBLE PRECISION ROUTINE*** */
  38. /* On KODE=1, ZBESY computes an N member sequence of complex */
  39. /* Bessel functions CY(L)=Y(FNU+L-1,Z) for real nonnegative */
  40. /* orders FNU+L-1, L=1,...,N and complex Z in the cut plane */
  41. /* -pi<arg(Z)<=pi where Z=ZR+i*ZI. On KODE=2, CBESY returns */
  42. /* the scaled functions */
  43. /* CY(L) = exp(-abs(Y))*Y(FNU+L-1,Z), L=1,...,N, Y=Im(Z) */
  44. /* which remove the exponential growth in both the upper and */
  45. /* lower half planes as Z goes to infinity. Definitions and */
  46. /* notation are found in the NBS Handbook of Mathematical */
  47. /* Functions (Ref. 1). */
  48. /* Input */
  49. /* ZR - DOUBLE PRECISION REAL part of nonzero argument Z */
  50. /* ZI - DOUBLE PRECISION imag part of nonzero argument Z */
  51. /* FNU - DOUBLE PRECISION initial order, FNU>=0 */
  52. /* KODE - A parameter to indicate the scaling option */
  53. /* KODE=1 returns */
  54. /* CY(L)=Y(FNU+L-1,Z), L=1,...,N */
  55. /* =2 returns */
  56. /* CY(L)=Y(FNU+L-1,Z)*exp(-abs(Y)), L=1,...,N */
  57. /* where Y=Im(Z) */
  58. /* N - Number of terms in the sequence, N>=1 */
  59. /* CWRKR - DOUBLE PRECISION work vector of dimension N */
  60. /* CWRKI - DOUBLE PRECISION work vector of dimension N */
  61. /* Output */
  62. /* CYR - DOUBLE PRECISION REAL part of result vector */
  63. /* CYI - DOUBLE PRECISION imag part of result vector */
  64. /* NZ - Number of underflows set to zero */
  65. /* NZ=0 Normal return */
  66. /* NZ>0 CY(L)=0 for NZ values of L, usually on */
  67. /* KODE=2 (the underflows may not be in an */
  68. /* uninterrupted sequence) */
  69. /* IERR - Error flag */
  70. /* IERR=0 Normal return - COMPUTATION COMPLETED */
  71. /* IERR=1 Input error - NO COMPUTATION */
  72. /* IERR=2 Overflow - NO COMPUTATION */
  73. /* (abs(Z) too small and/or FNU+N-1 */
  74. /* too large) */
  75. /* IERR=3 Precision warning - COMPUTATION COMPLETED */
  76. /* (Result has half precision or less */
  77. /* because abs(Z) or FNU+N-1 is large) */
  78. /* IERR=4 Precision error - NO COMPUTATION */
  79. /* (Result has no precision because */
  80. /* abs(Z) or FNU+N-1 is too large) */
  81. /* IERR=5 Algorithmic error - NO COMPUTATION */
  82. /* (Termination condition not met) */
  83. /* *Long Description: */
  84. /* The computation is carried out by the formula */
  85. /* Y(a,z) = (H(1,a,z) - H(2,a,z))/(2*i) */
  86. /* where the Hankel functions are computed as described in CBESH. */
  87. /* For negative orders, the formula */
  88. /* Y(-a,z) = Y(a,z)*cos(a*pi) + J(a,z)*sin(a*pi) */
  89. /* can be used. However, for large orders close to half odd */
  90. /* integers the function changes radically. When a is a large */
  91. /* positive half odd integer, the magnitude of Y(-a,z)=J(a,z)* */
  92. /* sin(a*pi) is a large negative power of ten. But when a is */
  93. /* not a half odd integer, Y(a,z) dominates in magnitude with a */
  94. /* large positive power of ten and the most that the second term */
  95. /* can be reduced is by unit roundoff from the coefficient. */
  96. /* Thus, wide changes can occur within unit roundoff of a large */
  97. /* half odd integer. Here, large means a>abs(z). */
  98. /* In most complex variable computation, one must evaluate ele- */
  99. /* mentary functions. When the magnitude of Z or FNU+N-1 is */
  100. /* large, losses of significance by argument reduction occur. */
  101. /* Consequently, if either one exceeds U1=SQRT(0.5/UR), then */
  102. /* losses exceeding half precision are likely and an error flag */
  103. /* IERR=3 is triggered where UR=MAX(D1MACH(4),1.0D-18) is double */
  104. /* precision unit roundoff limited to 18 digits precision. Also, */
  105. /* if either is larger than U2=0.5/UR, then all significance is */
  106. /* lost and IERR=4. In order to use the INT function, arguments */
  107. /* must be further restricted not to exceed the largest machine */
  108. /* integer, U3=I1MACH(9). Thus, the magnitude of Z and FNU+N-1 */
  109. /* is restricted by MIN(U2,U3). In IEEE arithmetic, U1,U2, and */
  110. /* U3 approximate 2.0E+3, 4.2E+6, 2.1E+9 in single precision */
  111. /* and 4.7E+7, 2.3E+15 and 2.1E+9 in double precision. This */
  112. /* makes U2 limiting in single precision and U3 limiting in */
  113. /* double precision. This means that one can expect to retain, */
  114. /* in the worst cases on IEEE machines, no digits in single pre- */
  115. /* cision and only 6 digits in double precision. Similar con- */
  116. /* siderations hold for other machines. */
  117. /* The approximate relative error in the magnitude of a complex */
  118. /* Bessel function can be expressed as P*10**S where P=MAX(UNIT */
  119. /* ROUNDOFF,1.0E-18) is the nominal precision and 10**S repre- */
  120. /* sents the increase in error due to argument reduction in the */
  121. /* elementary functions. Here, S=MAX(1,ABS(LOG10(ABS(Z))), */
  122. /* ABS(LOG10(FNU))) approximately (i.e., S=MAX(1,ABS(EXPONENT OF */
  123. /* ABS(Z),ABS(EXPONENT OF FNU)) ). However, the phase angle may */
  124. /* have only absolute accuracy. This is most likely to occur */
  125. /* when one component (in magnitude) is larger than the other by */
  126. /* several orders of magnitude. If one component is 10**K larger */
  127. /* than the other, then one can expect only MAX(ABS(LOG10(P))-K, */
  128. /* 0) significant digits; or, stated another way, when K exceeds */
  129. /* the exponent of P, no significant digits remain in the smaller */
  130. /* component. However, the phase angle retains absolute accuracy */
  131. /* because, in complex arithmetic with precision P, the smaller */
  132. /* component will not (as a rule) decrease below P times the */
  133. /* magnitude of the larger component. In these extreme cases, */
  134. /* the principal phase angle is on the order of +P, -P, PI/2-P, */
  135. /* or -PI/2+P. */
  136. /* ***REFERENCES 1. M. Abramowitz and I. A. Stegun, Handbook of Mathe- */
  137. /* matical Functions, National Bureau of Standards */
  138. /* Applied Mathematics Series 55, U. S. Department */
  139. /* of Commerce, Tenth Printing (1972) or later. */
  140. /* 2. D. E. Amos, Computation of Bessel Functions of */
  141. /* Complex Argument, Report SAND83-0086, Sandia National */
  142. /* Laboratories, Albuquerque, NM, May 1983. */
  143. /* 3. D. E. Amos, Computation of Bessel Functions of */
  144. /* Complex Argument and Large Order, Report SAND83-0643, */
  145. /* Sandia National Laboratories, Albuquerque, NM, May */
  146. /* 1983. */
  147. /* 4. D. E. Amos, A Subroutine Package for Bessel Functions */
  148. /* of a Complex Argument and Nonnegative Order, Report */
  149. /* SAND85-1018, Sandia National Laboratory, Albuquerque, */
  150. /* NM, May 1985. */
  151. /* 5. D. E. Amos, A portable package for Bessel functions */
  152. /* of a complex argument and nonnegative order, ACM */
  153. /* Transactions on Mathematical Software, 12 (September */
  154. /* 1986), pp. 265-273. */
  155. /* ***ROUTINES CALLED D1MACH, I1MACH, ZBESH */
  156. /* ***REVISION HISTORY (YYMMDD) */
  157. /* 830501 DATE WRITTEN */
  158. /* 890801 REVISION DATE from Version 3.2 */
  159. /* 910415 Prologue converted to Version 4.0 format. (BAB) */
  160. /* 920128 Category corrected. (WRB) */
  161. /* 920811 Prologue revised. (DWL) */
  162. /* ***END PROLOGUE ZBESY */
  163. /* COMPLEX CWRK,CY,C1,C2,EX,HCI,Z,ZU,ZV */
  164. /* ***FIRST EXECUTABLE STATEMENT ZBESY */
  165. /* Parameter adjustments */
  166. --cwrki;
  167. --cwrkr;
  168. --cyi;
  169. --cyr;
  170. /* Function Body */
  171. *ierr = 0;
  172. *nz = 0;
  173. if (*zr == 0. && *zi == 0.) {
  174. *ierr = 1;
  175. }
  176. if (*fnu < 0.) {
  177. *ierr = 1;
  178. }
  179. if (*kode < 1 || *kode > 2) {
  180. *ierr = 1;
  181. }
  182. if (*n < 1) {
  183. *ierr = 1;
  184. }
  185. if (*ierr != 0) {
  186. return 0;
  187. }
  188. hcii = .5;
  189. zbesh_(zr, zi, fnu, kode, &c__1, n, &cyr[1], &cyi[1], &nz1, ierr);
  190. if (*ierr != 0 && *ierr != 3) {
  191. goto L170;
  192. }
  193. zbesh_(zr, zi, fnu, kode, &c__2, n, &cwrkr[1], &cwrki[1], &nz2, ierr);
  194. if (*ierr != 0 && *ierr != 3) {
  195. goto L170;
  196. }
  197. *nz = min(nz1,nz2);
  198. if (*kode == 2) {
  199. goto L60;
  200. }
  201. i__1 = *n;
  202. for (i__ = 1; i__ <= i__1; ++i__) {
  203. str = cwrkr[i__] - cyr[i__];
  204. sti = cwrki[i__] - cyi[i__];
  205. cyr[i__] = -sti * hcii;
  206. cyi[i__] = str * hcii;
  207. /* L50: */
  208. }
  209. return 0;
  210. L60:
  211. /* Computing MAX */
  212. d__1 = d1mach_(4);
  213. tol = max(d__1,1e-18);
  214. k1 = i1mach_(15);
  215. k2 = i1mach_(16);
  216. /* Computing MIN */
  217. i__1 = abs(k1), i__2 = abs(k2);
  218. k = min(i__1,i__2);
  219. r1m5 = d1mach_(5);
  220. /* ----------------------------------------------------------------------- */
  221. /* ELIM IS THE APPROXIMATE EXPONENTIAL UNDER- AND OVERFLOW LIMIT */
  222. /* ----------------------------------------------------------------------- */
  223. elim = (k * r1m5 - 3.) * 2.303;
  224. exr = cos(*zr);
  225. exi = sin(*zr);
  226. ey = 0.;
  227. tay = (d__1 = *zi + *zi, abs(d__1));
  228. if (tay < elim) {
  229. ey = exp(-tay);
  230. }
  231. if (*zi < 0.) {
  232. goto L90;
  233. }
  234. c1r = exr * ey;
  235. c1i = exi * ey;
  236. c2r = exr;
  237. c2i = -exi;
  238. L70:
  239. *nz = 0;
  240. rtol = 1. / tol;
  241. ascle = d1mach_(1) * rtol * 1e3;
  242. i__1 = *n;
  243. for (i__ = 1; i__ <= i__1; ++i__) {
  244. /* STR = C1R*CYR(I) - C1I*CYI(I) */
  245. /* STI = C1R*CYI(I) + C1I*CYR(I) */
  246. /* STR = -STR + C2R*CWRKR(I) - C2I*CWRKI(I) */
  247. /* STI = -STI + C2R*CWRKI(I) + C2I*CWRKR(I) */
  248. /* CYR(I) = -STI*HCII */
  249. /* CYI(I) = STR*HCII */
  250. aa = cwrkr[i__];
  251. bb = cwrki[i__];
  252. atol = 1.;
  253. /* Computing MAX */
  254. d__1 = abs(aa), d__2 = abs(bb);
  255. if (max(d__1,d__2) > ascle) {
  256. goto L75;
  257. }
  258. aa *= rtol;
  259. bb *= rtol;
  260. atol = tol;
  261. L75:
  262. str = (aa * c2r - bb * c2i) * atol;
  263. sti = (aa * c2i + bb * c2r) * atol;
  264. aa = cyr[i__];
  265. bb = cyi[i__];
  266. atol = 1.;
  267. /* Computing MAX */
  268. d__1 = abs(aa), d__2 = abs(bb);
  269. if (max(d__1,d__2) > ascle) {
  270. goto L85;
  271. }
  272. aa *= rtol;
  273. bb *= rtol;
  274. atol = tol;
  275. L85:
  276. str -= (aa * c1r - bb * c1i) * atol;
  277. sti -= (aa * c1i + bb * c1r) * atol;
  278. cyr[i__] = -sti * hcii;
  279. cyi[i__] = str * hcii;
  280. if (str == 0. && sti == 0. && ey == 0.) {
  281. ++(*nz);
  282. }
  283. /* L80: */
  284. }
  285. return 0;
  286. L90:
  287. c1r = exr;
  288. c1i = exi;
  289. c2r = exr * ey;
  290. c2i = -exi * ey;
  291. goto L70;
  292. L170:
  293. *nz = 0;
  294. return 0;
  295. } /* zbesy_ */