zmlri.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /* zmlri.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. int zmlri_(double *zr, double *zi, double const *fnu,
  8. integer const *kode, integer const *n, double *yr, double *yi, integer *
  9. nz, double *tol)
  10. {
  11. /* Initialized data */
  12. static double const zeror = 0.;
  13. static double const zeroi = 0.;
  14. static double const coner = 1.;
  15. static double const conei = 0.;
  16. /* System generated locals */
  17. integer i__1, i__2;
  18. double d__1, d__2, d__3;
  19. /* Local variables */
  20. integer i__, k, m;
  21. double ak, bk, ap, at;
  22. integer kk, km;
  23. double az, p1i, p2i, p1r, p2r, ack, cki, fnf, fkk, ckr;
  24. integer iaz;
  25. double rho;
  26. integer inu;
  27. double pti, raz, sti, rzi, ptr, str, tst, rzr, rho2, flam, fkap, scle,
  28. tfnf;
  29. integer idum;
  30. integer ifnu;
  31. double sumi, sumr;
  32. integer itime;
  33. double cnormi, cnormr;
  34. /* ***BEGIN PROLOGUE ZMLRI */
  35. /* ***SUBSIDIARY */
  36. /* ***PURPOSE Subsidiary to ZBESI and ZBESK */
  37. /* ***LIBRARY SLATEC */
  38. /* ***TYPE ALL (CMLRI-A, ZMLRI-A) */
  39. /* ***AUTHOR Amos, D. E., (SNL) */
  40. /* ***DESCRIPTION */
  41. /* ZMLRI COMPUTES THE I BESSEL FUNCTION FOR RE(Z).GE.0.0 BY THE */
  42. /* MILLER ALGORITHM NORMALIZED BY A NEUMANN SERIES. */
  43. /* ***SEE ALSO ZBESI, ZBESK */
  44. /* ***ROUTINES CALLED D1MACH, DGAMLN, ZABS, ZEXP, ZLOG, ZMLT */
  45. /* ***REVISION HISTORY (YYMMDD) */
  46. /* 830501 DATE WRITTEN */
  47. /* 910415 Prologue converted to Version 4.0 format. (BAB) */
  48. /* 930122 Added ZEXP and ZLOG to EXTERNAL statement. (RWC) */
  49. /* ***END PROLOGUE ZMLRI */
  50. /* COMPLEX CK,CNORM,CONE,CTWO,CZERO,PT,P1,P2,RZ,SUM,Y,Z */
  51. /* Parameter adjustments */
  52. --yi;
  53. --yr;
  54. /* Function Body */
  55. /* ***FIRST EXECUTABLE STATEMENT ZMLRI */
  56. scle = d1mach_(1) / *tol;
  57. *nz = 0;
  58. az = zabs_(zr, zi);
  59. iaz = (integer) az;
  60. ifnu = (integer) (*fnu);
  61. inu = ifnu + *n - 1;
  62. at = iaz + 1.;
  63. raz = 1. / az;
  64. str = *zr * raz;
  65. sti = -(*zi) * raz;
  66. ckr = str * at * raz;
  67. cki = sti * at * raz;
  68. rzr = (str + str) * raz;
  69. rzi = (sti + sti) * raz;
  70. p1r = zeror;
  71. p1i = zeroi;
  72. p2r = coner;
  73. p2i = conei;
  74. ack = (at + 1.) * raz;
  75. rho = ack + sqrt(ack * ack - 1.);
  76. rho2 = rho * rho;
  77. tst = (rho2 + rho2) / ((rho2 - 1.) * (rho - 1.));
  78. tst /= *tol;
  79. /* ----------------------------------------------------------------------- */
  80. /* COMPUTE RELATIVE TRUNCATION ERROR INDEX FOR SERIES */
  81. /* ----------------------------------------------------------------------- */
  82. ak = at;
  83. for (i__ = 1; i__ <= 80; ++i__) {
  84. ptr = p2r;
  85. pti = p2i;
  86. p2r = p1r - (ckr * ptr - cki * pti);
  87. p2i = p1i - (cki * ptr + ckr * pti);
  88. p1r = ptr;
  89. p1i = pti;
  90. ckr += rzr;
  91. cki += rzi;
  92. ap = zabs_(&p2r, &p2i);
  93. if (ap > tst * ak * ak) {
  94. goto L20;
  95. }
  96. ak += 1.;
  97. /* L10: */
  98. }
  99. goto L110;
  100. L20:
  101. ++i__;
  102. k = 0;
  103. if (inu < iaz) {
  104. goto L40;
  105. }
  106. /* ----------------------------------------------------------------------- */
  107. /* COMPUTE RELATIVE TRUNCATION ERROR FOR RATIOS */
  108. /* ----------------------------------------------------------------------- */
  109. p1r = zeror;
  110. p1i = zeroi;
  111. p2r = coner;
  112. p2i = conei;
  113. at = inu + 1.;
  114. str = *zr * raz;
  115. sti = -(*zi) * raz;
  116. ckr = str * at * raz;
  117. cki = sti * at * raz;
  118. ack = at * raz;
  119. tst = sqrt(ack / *tol);
  120. itime = 1;
  121. for (k = 1; k <= 80; ++k) {
  122. ptr = p2r;
  123. pti = p2i;
  124. p2r = p1r - (ckr * ptr - cki * pti);
  125. p2i = p1i - (ckr * pti + cki * ptr);
  126. p1r = ptr;
  127. p1i = pti;
  128. ckr += rzr;
  129. cki += rzi;
  130. ap = zabs_(&p2r, &p2i);
  131. if (ap < tst) {
  132. goto L30;
  133. }
  134. if (itime == 2) {
  135. goto L40;
  136. }
  137. ack = zabs_(&ckr, &cki);
  138. flam = ack + sqrt(ack * ack - 1.);
  139. fkap = ap / zabs_(&p1r, &p1i);
  140. rho = min(flam,fkap);
  141. tst *= sqrt(rho / (rho * rho - 1.));
  142. itime = 2;
  143. L30:
  144. ;
  145. }
  146. goto L110;
  147. L40:
  148. /* ----------------------------------------------------------------------- */
  149. /* BACKWARD RECURRENCE AND SUM NORMALIZING RELATION */
  150. /* ----------------------------------------------------------------------- */
  151. ++k;
  152. /* Computing MAX */
  153. i__1 = i__ + iaz, i__2 = k + inu;
  154. kk = max(i__1,i__2);
  155. fkk = (double) kk;
  156. p1r = zeror;
  157. p1i = zeroi;
  158. /* ----------------------------------------------------------------------- */
  159. /* SCALE P2 AND SUM BY SCLE */
  160. /* ----------------------------------------------------------------------- */
  161. p2r = scle;
  162. p2i = zeroi;
  163. fnf = *fnu - ifnu;
  164. tfnf = fnf + fnf;
  165. d__1 = fkk + tfnf + 1.;
  166. d__2 = fkk + 1.;
  167. d__3 = tfnf + 1.;
  168. bk = dgamln_(&d__1, &idum) - dgamln_(&d__2, &idum) - dgamln_(&d__3, &idum)
  169. ;
  170. bk = exp(bk);
  171. sumr = zeror;
  172. sumi = zeroi;
  173. km = kk - inu;
  174. i__1 = km;
  175. for (i__ = 1; i__ <= i__1; ++i__) {
  176. ptr = p2r;
  177. pti = p2i;
  178. p2r = p1r + (fkk + fnf) * (rzr * ptr - rzi * pti);
  179. p2i = p1i + (fkk + fnf) * (rzi * ptr + rzr * pti);
  180. p1r = ptr;
  181. p1i = pti;
  182. ak = 1. - tfnf / (fkk + tfnf);
  183. ack = bk * ak;
  184. sumr += (ack + bk) * p1r;
  185. sumi += (ack + bk) * p1i;
  186. bk = ack;
  187. fkk += -1.;
  188. /* L50: */
  189. }
  190. yr[*n] = p2r;
  191. yi[*n] = p2i;
  192. if (*n == 1) {
  193. goto L70;
  194. }
  195. i__1 = *n;
  196. for (i__ = 2; i__ <= i__1; ++i__) {
  197. ptr = p2r;
  198. pti = p2i;
  199. p2r = p1r + (fkk + fnf) * (rzr * ptr - rzi * pti);
  200. p2i = p1i + (fkk + fnf) * (rzi * ptr + rzr * pti);
  201. p1r = ptr;
  202. p1i = pti;
  203. ak = 1. - tfnf / (fkk + tfnf);
  204. ack = bk * ak;
  205. sumr += (ack + bk) * p1r;
  206. sumi += (ack + bk) * p1i;
  207. bk = ack;
  208. fkk += -1.;
  209. m = *n - i__ + 1;
  210. yr[m] = p2r;
  211. yi[m] = p2i;
  212. /* L60: */
  213. }
  214. L70:
  215. if (ifnu <= 0) {
  216. goto L90;
  217. }
  218. i__1 = ifnu;
  219. for (i__ = 1; i__ <= i__1; ++i__) {
  220. ptr = p2r;
  221. pti = p2i;
  222. p2r = p1r + (fkk + fnf) * (rzr * ptr - rzi * pti);
  223. p2i = p1i + (fkk + fnf) * (rzr * pti + rzi * ptr);
  224. p1r = ptr;
  225. p1i = pti;
  226. ak = 1. - tfnf / (fkk + tfnf);
  227. ack = bk * ak;
  228. sumr += (ack + bk) * p1r;
  229. sumi += (ack + bk) * p1i;
  230. bk = ack;
  231. fkk += -1.;
  232. /* L80: */
  233. }
  234. L90:
  235. ptr = *zr;
  236. pti = *zi;
  237. if (*kode == 2) {
  238. ptr = zeror;
  239. }
  240. zlog_(&rzr, &rzi, &str, &sti, &idum);
  241. p1r = -fnf * str + ptr;
  242. p1i = -fnf * sti + pti;
  243. d__1 = fnf + 1.;
  244. ap = dgamln_(&d__1, &idum);
  245. ptr = p1r - ap;
  246. pti = p1i;
  247. /* ----------------------------------------------------------------------- */
  248. /* THE DIVISION CEXP(PT)/(SUM+P2) IS ALTERED TO AVOID OVERFLOW */
  249. /* IN THE DENOMINATOR BY SQUARING LARGE QUANTITIES */
  250. /* ----------------------------------------------------------------------- */
  251. p2r += sumr;
  252. p2i += sumi;
  253. ap = zabs_(&p2r, &p2i);
  254. p1r = 1. / ap;
  255. zexp_(&ptr, &pti, &str, &sti);
  256. ckr = str * p1r;
  257. cki = sti * p1r;
  258. ptr = p2r * p1r;
  259. pti = -p2i * p1r;
  260. zmlt_(&ckr, &cki, &ptr, &pti, &cnormr, &cnormi);
  261. i__1 = *n;
  262. for (i__ = 1; i__ <= i__1; ++i__) {
  263. str = yr[i__] * cnormr - yi[i__] * cnormi;
  264. yi[i__] = yr[i__] * cnormi + yi[i__] * cnormr;
  265. yr[i__] = str;
  266. /* L100: */
  267. }
  268. return 0;
  269. L110:
  270. *nz = -2;
  271. return 0;
  272. } /* zmlri_ */