zbesi.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. /* zbesi.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__4 = 4;
  7. static integer const c__15 = 15;
  8. static integer const c__16 = 16;
  9. static integer const c__5 = 5;
  10. static integer const c__14 = 14;
  11. static integer const c__9 = 9;
  12. static integer const c__1 = 1;
  13. int zbesi_(double *zr, double *zi, double const *fnu,
  14. integer const *kode, integer const *n, double *cyr, double *cyi, integer *
  15. nz, integer *ierr)
  16. {
  17. /* Initialized data */
  18. static double const pi = 3.14159265358979324;
  19. static double const coner = 1.;
  20. static double const conei = 0.;
  21. /* System generated locals */
  22. integer i__1, i__2;
  23. double d__1, d__2;
  24. /* Local variables */
  25. integer i__, k, k1, k2;
  26. double aa, bb, fn, az;
  27. integer nn;
  28. double rl, dig, arg, r1m5;
  29. integer inu;
  30. double tol, sti, zni, str, znr, alim, elim;
  31. double atol, fnul, rtol, ascle, csgni, csgnr;
  32. /* ***BEGIN PROLOGUE ZBESI */
  33. /* ***PURPOSE Compute a sequence of the Bessel functions I(a,z) for */
  34. /* complex argument z and real nonnegative orders a=b,b+1, */
  35. /* b+2,... where b>0. A scaling option is available to */
  36. /* help avoid overflow. */
  37. /* ***LIBRARY SLATEC */
  38. /* ***CATEGORY C10B4 */
  39. /* ***TYPE COMPLEX (CBESI-C, ZBESI-C) */
  40. /* ***KEYWORDS BESSEL FUNCTIONS OF COMPLEX ARGUMENT, I BESSEL FUNCTIONS, */
  41. /* MODIFIED BESSEL FUNCTIONS */
  42. /* ***AUTHOR Amos, D. E., (SNL) */
  43. /* ***DESCRIPTION */
  44. /* ***A DOUBLE PRECISION ROUTINE*** */
  45. /* On KODE=1, ZBESI computes an N-member sequence of complex */
  46. /* Bessel functions CY(L)=I(FNU+L-1,Z) for real nonnegative */
  47. /* orders FNU+L-1, L=1,...,N and complex Z in the cut plane */
  48. /* -pi<arg(Z)<=pi where Z=ZR+i*ZI. On KODE=2, CBESI returns */
  49. /* the scaled functions */
  50. /* CY(L) = exp(-abs(X))*I(FNU+L-1,Z), L=1,...,N and X=Re(Z) */
  51. /* which removes the exponential growth in both the left and */
  52. /* right half-planes as Z goes to infinity. */
  53. /* Input */
  54. /* ZR - DOUBLE PRECISION REAL part of argument Z */
  55. /* ZI - DOUBLE PRECISION imag part of argument Z */
  56. /* FNU - DOUBLE PRECISION initial order, FNU>=0 */
  57. /* KODE - A parameter to indicate the scaling option */
  58. /* KODE=1 returns */
  59. /* CY(L)=I(FNU+L-1,Z), L=1,...,N */
  60. /* =2 returns */
  61. /* CY(L)=exp(-abs(X))*I(FNU+L-1,Z), L=1,...,N */
  62. /* where X=Re(Z) */
  63. /* N - Number of terms in the sequence, N>=1 */
  64. /* Output */
  65. /* CYR - DOUBLE PRECISION REAL part of result vector */
  66. /* CYI - DOUBLE PRECISION imag part of result vector */
  67. /* NZ - Number of underflows set to zero */
  68. /* NZ=0 Normal return */
  69. /* NZ>0 CY(L)=0, L=N-NZ+1,...,N */
  70. /* IERR - Error flag */
  71. /* IERR=0 Normal return - COMPUTATION COMPLETED */
  72. /* IERR=1 Input error - NO COMPUTATION */
  73. /* IERR=2 Overflow - NO COMPUTATION */
  74. /* (Re(Z) too large on KODE=1) */
  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 of I(a,z) is carried out by the power series */
  85. /* for small abs(z), the asymptotic expansion for large abs(z), */
  86. /* the Miller algorithm normalized by the Wronskian and a */
  87. /* Neumann series for intermediate magnitudes of z, and the */
  88. /* uniform asymptotic expansions for I(a,z) and J(a,z) for */
  89. /* large orders a. Backward recurrence is used to generate */
  90. /* sequences or reduce orders when necessary. */
  91. /* The calculations above are done in the right half plane and */
  92. /* continued into the left half plane by the formula */
  93. /* I(a,z*exp(t)) = exp(t*a)*I(a,z), Re(z)>0 */
  94. /* t = i*pi or -i*pi */
  95. /* For negative orders, the formula */
  96. /* I(-a,z) = I(a,z) + (2/pi)*sin(pi*a)*K(a,z) */
  97. /* can be used. However, for large orders close to integers the */
  98. /* the function changes radically. When a is a large positive */
  99. /* integer, the magnitude of I(-a,z)=I(a,z) is a large */
  100. /* negative power of ten. But when a is not an integer, */
  101. /* K(a,z) dominates in magnitude with a large positive power of */
  102. /* ten and the most that the second term can be reduced is by */
  103. /* unit roundoff from the coefficient. Thus, wide changes can */
  104. /* occur within unit roundoff of a large integer for a. Here, */
  105. /* large means a>abs(z). */
  106. /* In most complex variable computation, one must evaluate ele- */
  107. /* mentary functions. When the magnitude of Z or FNU+N-1 is */
  108. /* large, losses of significance by argument reduction occur. */
  109. /* Consequently, if either one exceeds U1=SQRT(0.5/UR), then */
  110. /* losses exceeding half precision are likely and an error flag */
  111. /* IERR=3 is triggered where UR=MAX(D1MACH(4),1.0D-18) is double */
  112. /* precision unit roundoff limited to 18 digits precision. Also, */
  113. /* if either is larger than U2=0.5/UR, then all significance is */
  114. /* lost and IERR=4. In order to use the INT function, arguments */
  115. /* must be further restricted not to exceed the largest machine */
  116. /* integer, U3=I1MACH(9). Thus, the magnitude of Z and FNU+N-1 */
  117. /* is restricted by MIN(U2,U3). In IEEE arithmetic, U1,U2, and */
  118. /* U3 approximate 2.0E+3, 4.2E+6, 2.1E+9 in single precision */
  119. /* and 4.7E+7, 2.3E+15 and 2.1E+9 in double precision. This */
  120. /* makes U2 limiting in single precision and U3 limiting in */
  121. /* double precision. This means that one can expect to retain, */
  122. /* in the worst cases on IEEE machines, no digits in single pre- */
  123. /* cision and only 6 digits in double precision. Similar con- */
  124. /* siderations hold for other machines. */
  125. /* The approximate relative error in the magnitude of a complex */
  126. /* Bessel function can be expressed as P*10**S where P=MAX(UNIT */
  127. /* ROUNDOFF,1.0E-18) is the nominal precision and 10**S repre- */
  128. /* sents the increase in error due to argument reduction in the */
  129. /* elementary functions. Here, S=MAX(1,ABS(LOG10(ABS(Z))), */
  130. /* ABS(LOG10(FNU))) approximately (i.e., S=MAX(1,ABS(EXPONENT OF */
  131. /* ABS(Z),ABS(EXPONENT OF FNU)) ). However, the phase angle may */
  132. /* have only absolute accuracy. This is most likely to occur */
  133. /* when one component (in magnitude) is larger than the other by */
  134. /* several orders of magnitude. If one component is 10**K larger */
  135. /* than the other, then one can expect only MAX(ABS(LOG10(P))-K, */
  136. /* 0) significant digits; or, stated another way, when K exceeds */
  137. /* the exponent of P, no significant digits remain in the smaller */
  138. /* component. However, the phase angle retains absolute accuracy */
  139. /* because, in complex arithmetic with precision P, the smaller */
  140. /* component will not (as a rule) decrease below P times the */
  141. /* magnitude of the larger component. In these extreme cases, */
  142. /* the principal phase angle is on the order of +P, -P, PI/2-P, */
  143. /* or -PI/2+P. */
  144. /* ***REFERENCES 1. M. Abramowitz and I. A. Stegun, Handbook of Mathe- */
  145. /* matical Functions, National Bureau of Standards */
  146. /* Applied Mathematics Series 55, U. S. Department */
  147. /* of Commerce, Tenth Printing (1972) or later. */
  148. /* 2. D. E. Amos, Computation of Bessel Functions of */
  149. /* Complex Argument, Report SAND83-0086, Sandia National */
  150. /* Laboratories, Albuquerque, NM, May 1983. */
  151. /* 3. D. E. Amos, Computation of Bessel Functions of */
  152. /* Complex Argument and Large Order, Report SAND83-0643, */
  153. /* Sandia National Laboratories, Albuquerque, NM, May */
  154. /* 1983. */
  155. /* 4. D. E. Amos, A Subroutine Package for Bessel Functions */
  156. /* of a Complex Argument and Nonnegative Order, Report */
  157. /* SAND85-1018, Sandia National Laboratory, Albuquerque, */
  158. /* NM, May 1985. */
  159. /* 5. D. E. Amos, A portable package for Bessel functions */
  160. /* of a complex argument and nonnegative order, ACM */
  161. /* Transactions on Mathematical Software, 12 (September */
  162. /* 1986), pp. 265-273. */
  163. /* ***ROUTINES CALLED D1MACH, I1MACH, ZABS, ZBINU */
  164. /* ***REVISION HISTORY (YYMMDD) */
  165. /* 830501 DATE WRITTEN */
  166. /* 890801 REVISION DATE from Version 3.2 */
  167. /* 910415 Prologue converted to Version 4.0 format. (BAB) */
  168. /* 920128 Category corrected. (WRB) */
  169. /* 920811 Prologue revised. (DWL) */
  170. /* ***END PROLOGUE ZBESI */
  171. /* COMPLEX CONE,CSGN,CW,CY,CZERO,Z,ZN */
  172. /* Parameter adjustments */
  173. --cyi;
  174. --cyr;
  175. /* Function Body */
  176. /* ***FIRST EXECUTABLE STATEMENT ZBESI */
  177. *ierr = 0;
  178. *nz = 0;
  179. if (*fnu < 0.) {
  180. *ierr = 1;
  181. }
  182. if (*kode < 1 || *kode > 2) {
  183. *ierr = 1;
  184. }
  185. if (*n < 1) {
  186. *ierr = 1;
  187. }
  188. if (*ierr != 0) {
  189. return 0;
  190. }
  191. /* ----------------------------------------------------------------------- */
  192. /* SET PARAMETERS RELATED TO MACHINE CONSTANTS. */
  193. /* TOL IS THE APPROXIMATE UNIT ROUNDOFF LIMITED TO 1.0E-18. */
  194. /* ELIM IS THE APPROXIMATE EXPONENTIAL OVER- AND UNDERFLOW LIMIT. */
  195. /* EXP(-ELIM).LT.EXP(-ALIM)=EXP(-ELIM)/TOL AND */
  196. /* EXP(ELIM).GT.EXP(ALIM)=EXP(ELIM)*TOL ARE INTERVALS NEAR */
  197. /* UNDERFLOW AND OVERFLOW LIMITS WHERE SCALED ARITHMETIC IS DONE. */
  198. /* RL IS THE LOWER BOUNDARY OF THE ASYMPTOTIC EXPANSION FOR LARGE Z. */
  199. /* DIG = NUMBER OF BASE 10 DIGITS IN TOL = 10**(-DIG). */
  200. /* FNUL IS THE LOWER BOUNDARY OF THE ASYMPTOTIC SERIES FOR LARGE FNU. */
  201. /* ----------------------------------------------------------------------- */
  202. /* Computing MAX */
  203. d__1 = d1mach_(4);
  204. tol = max(d__1,1e-18);
  205. k1 = i1mach_(15);
  206. k2 = i1mach_(16);
  207. r1m5 = d1mach_(5);
  208. /* Computing MIN */
  209. i__1 = abs(k1), i__2 = abs(k2);
  210. k = min(i__1,i__2);
  211. elim = (k * r1m5 - 3.) * 2.303;
  212. k1 = i1mach_(14) - 1;
  213. aa = r1m5 * k1;
  214. dig = min(aa,18.);
  215. aa *= 2.303;
  216. /* Computing MAX */
  217. d__1 = -aa;
  218. alim = elim + max(d__1,-41.45);
  219. rl = dig * 1.2 + 3.;
  220. fnul = (dig - 3.) * 6. + 10.;
  221. /* ----------------------------------------------------------------------- */
  222. /* TEST FOR PROPER RANGE */
  223. /* ----------------------------------------------------------------------- */
  224. az = zabs_(zr, zi);
  225. fn = *fnu + (*n - 1);
  226. aa = .5 / tol;
  227. bb = i1mach_(9) * .5;
  228. aa = min(aa,bb);
  229. if (az > aa) {
  230. goto L260;
  231. }
  232. if (fn > aa) {
  233. goto L260;
  234. }
  235. aa = sqrt(aa);
  236. if (az > aa) {
  237. *ierr = 3;
  238. }
  239. if (fn > aa) {
  240. *ierr = 3;
  241. }
  242. znr = *zr;
  243. zni = *zi;
  244. csgnr = coner;
  245. csgni = conei;
  246. if (*zr >= 0.) {
  247. goto L40;
  248. }
  249. znr = -(*zr);
  250. zni = -(*zi);
  251. /* ----------------------------------------------------------------------- */
  252. /* CALCULATE CSGN=EXP(FNU*PI*I) TO MINIMIZE LOSSES OF SIGNIFICANCE */
  253. /* WHEN FNU IS LARGE */
  254. /* ----------------------------------------------------------------------- */
  255. inu = (integer) (*fnu);
  256. arg = (*fnu - inu) * pi;
  257. if (*zi < 0.) {
  258. arg = -arg;
  259. }
  260. csgnr = cos(arg);
  261. csgni = sin(arg);
  262. if (inu % 2 == 0) {
  263. goto L40;
  264. }
  265. csgnr = -csgnr;
  266. csgni = -csgni;
  267. L40:
  268. zbinu_(&znr, &zni, fnu, kode, n, &cyr[1], &cyi[1], nz, &rl, &fnul, &tol, &
  269. elim, &alim);
  270. if (*nz < 0) {
  271. goto L120;
  272. }
  273. if (*zr >= 0.) {
  274. return 0;
  275. }
  276. /* ----------------------------------------------------------------------- */
  277. /* ANALYTIC CONTINUATION TO THE LEFT HALF PLANE */
  278. /* ----------------------------------------------------------------------- */
  279. nn = *n - *nz;
  280. if (nn == 0) {
  281. return 0;
  282. }
  283. rtol = 1. / tol;
  284. ascle = d1mach_(1) * rtol * 1e3;
  285. i__1 = nn;
  286. for (i__ = 1; i__ <= i__1; ++i__) {
  287. /* STR = CYR(I)*CSGNR - CYI(I)*CSGNI */
  288. /* CYI(I) = CYR(I)*CSGNI + CYI(I)*CSGNR */
  289. /* CYR(I) = STR */
  290. aa = cyr[i__];
  291. bb = cyi[i__];
  292. atol = 1.;
  293. /* Computing MAX */
  294. d__1 = abs(aa), d__2 = abs(bb);
  295. if (max(d__1,d__2) > ascle) {
  296. goto L55;
  297. }
  298. aa *= rtol;
  299. bb *= rtol;
  300. atol = tol;
  301. L55:
  302. str = aa * csgnr - bb * csgni;
  303. sti = aa * csgni + bb * csgnr;
  304. cyr[i__] = str * atol;
  305. cyi[i__] = sti * atol;
  306. csgnr = -csgnr;
  307. csgni = -csgni;
  308. /* L50: */
  309. }
  310. return 0;
  311. L120:
  312. if (*nz == -2) {
  313. goto L130;
  314. }
  315. *nz = 0;
  316. *ierr = 2;
  317. return 0;
  318. L130:
  319. *nz = 0;
  320. *ierr = 5;
  321. return 0;
  322. L260:
  323. *nz = 0;
  324. *ierr = 4;
  325. return 0;
  326. } /* zbesi_ */