dbsynu.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. /* dbsynu.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__3 = 3;
  7. static integer const c__2 = 2;
  8. static integer const c__1 = 1;
  9. int dbsynu_(double const *x, double const *fnu, integer const *n, double *y)
  10. {
  11. /* Initialized data */
  12. static double const x1 = 3.;
  13. static double const x2 = 20.;
  14. static double const pi = 3.14159265358979;
  15. static double const rthpi = .797884560802865;
  16. static double const hpi = 1.5707963267949;
  17. static double const cc[8] = { .577215664901533,-.0420026350340952,
  18. -.0421977345555443,.007218943246663,-2.152416741149e-4,
  19. -2.01348547807e-5,1.133027232e-6,6.116095e-9 };
  20. /* System generated locals. Some initialized to avoid -Wmaybe-uninitialized */
  21. integer i__1;
  22. double d__1, d__2;
  23. /* Local variables */
  24. double a[120], f, g;
  25. integer i__, j, k;
  26. double p, q, s, a1, a2, g1, g2, s1 = 0., s2 = 0., t1, t2, cb[120], fc, ak, bk,
  27. ck = 0., fk, fn, rb[120];
  28. integer kk;
  29. double cs, sa, sb, cx;
  30. integer nn;
  31. double tb, fx, tm, pt, rs, ss, st, rx, cp1, cp2, cs1, cs2, rp1, rp2,
  32. rs1, rs2, cbk, cck, arg, rbk, rck, fhs, fks, cpt, dnu, fmu;
  33. integer inu;
  34. double tol, etx, smu, rpt, dnu2, coef, relb, flrx, etest;
  35. /* ***BEGIN PROLOGUE DBSYNU */
  36. /* ***SUBSIDIARY */
  37. /* ***PURPOSE Subsidiary to DBESY */
  38. /* ***LIBRARY SLATEC */
  39. /* ***TYPE DOUBLE PRECISION (BESYNU-S, DBSYNU-D) */
  40. /* ***AUTHOR Amos, D. E., (SNLA) */
  41. /* ***DESCRIPTION */
  42. /* Abstract **** A DOUBLE PRECISION routine **** */
  43. /* DBSYNU computes N member sequences of Y Bessel functions */
  44. /* Y/SUB(FNU+I-1)/(X), I=1,N for non-negative orders FNU and */
  45. /* positive X. Equations of the references are implemented on */
  46. /* small orders DNU for Y/SUB(DNU)/(X) and Y/SUB(DNU+1)/(X). */
  47. /* Forward recursion with the three term recursion relation */
  48. /* generates higher orders FNU+I-1, I=1,...,N. */
  49. /* To start the recursion FNU is normalized to the interval */
  50. /* -0.5.LE.DNU.LT.0.5. A special form of the power series is */
  51. /* implemented on 0.LT.X.LE.X1 while the Miller algorithm for the */
  52. /* K Bessel function in terms of the confluent hypergeometric */
  53. /* function U(FNU+0.5,2*FNU+1,I*X) is implemented on X1.LT.X.LE.X */
  54. /* Here I is the complex number SQRT(-1.). */
  55. /* For X.GT.X2, the asymptotic expansion for large X is used. */
  56. /* When FNU is a half odd integer, a special formula for */
  57. /* DNU=-0.5 and DNU+1.0=0.5 is used to start the recursion. */
  58. /* The maximum number of significant digits obtainable */
  59. /* is the smaller of 14 and the number of digits carried in */
  60. /* DOUBLE PRECISION arithmetic. */
  61. /* DBSYNU assumes that a significant digit SINH function is */
  62. /* available. */
  63. /* Description of Arguments */
  64. /* INPUT */
  65. /* X - X.GT.0.0D0 */
  66. /* FNU - Order of initial Y function, FNU.GE.0.0D0 */
  67. /* N - Number of members of the sequence, N.GE.1 */
  68. /* OUTPUT */
  69. /* Y - A vector whose first N components contain values */
  70. /* for the sequence Y(I)=Y/SUB(FNU+I-1), I=1,N. */
  71. /* Error Conditions */
  72. /* Improper input arguments - a fatal error */
  73. /* Overflow - a fatal error */
  74. /* ***SEE ALSO DBESY */
  75. /* ***REFERENCES N. M. Temme, On the numerical evaluation of the ordinary */
  76. /* Bessel function of the second kind, Journal of */
  77. /* Computational Physics 21, (1976), pp. 343-350. */
  78. /* N. M. Temme, On the numerical evaluation of the modified */
  79. /* Bessel function of the third kind, Journal of */
  80. /* Computational Physics 19, (1975), pp. 324-337. */
  81. /* ***ROUTINES CALLED D1MACH, DGAMMA, XERMSG */
  82. /* ***REVISION HISTORY (YYMMDD) */
  83. /* 800501 DATE WRITTEN */
  84. /* 890531 Changed all specific intrinsics to generic. (WRB) */
  85. /* 890911 Removed unnecessary intrinsics. (WRB) */
  86. /* 891214 Prologue converted to Version 4.0 format. (BAB) */
  87. /* 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ) */
  88. /* 900326 Removed duplicate information from DESCRIPTION section. */
  89. /* (WRB) */
  90. /* 900328 Added TYPE section. (WRB) */
  91. /* 900727 Added EXTERNAL statement. (WRB) */
  92. /* 910408 Updated the AUTHOR and REFERENCES sections. (WRB) */
  93. /* 920501 Reformatted the REFERENCES section. (WRB) */
  94. /* ***END PROLOGUE DBSYNU */
  95. /* Parameter adjustments */
  96. --y;
  97. /* Function Body */
  98. /* ***FIRST EXECUTABLE STATEMENT DBSYNU */
  99. ak = d1mach_(3);
  100. tol = max(ak,1e-15);
  101. if (*x <= 0.) {
  102. goto L270;
  103. }
  104. if (*fnu < 0.) {
  105. goto L280;
  106. }
  107. if (*n < 1) {
  108. goto L290;
  109. }
  110. rx = 2. / *x;
  111. inu = (integer) (*fnu + .5);
  112. dnu = *fnu - inu;
  113. if (abs(dnu) == .5) {
  114. goto L260;
  115. }
  116. dnu2 = 0.;
  117. if (abs(dnu) < tol) {
  118. goto L10;
  119. }
  120. dnu2 = dnu * dnu;
  121. L10:
  122. if (*x > x1) {
  123. goto L120;
  124. }
  125. /* SERIES FOR X.LE.X1 */
  126. a1 = 1. - dnu;
  127. a2 = dnu + 1.;
  128. t1 = 1. / dgamma_(&a1);
  129. t2 = 1. / dgamma_(&a2);
  130. if (abs(dnu) > .1) {
  131. goto L40;
  132. }
  133. /* SERIES FOR F0 TO RESOLVE INDETERMINACY FOR SMALL ABS(DNU) */
  134. s = cc[0];
  135. ak = 1.;
  136. for (k = 2; k <= 8; ++k) {
  137. ak *= dnu2;
  138. tm = cc[k - 1] * ak;
  139. s += tm;
  140. if (abs(tm) < tol) {
  141. goto L30;
  142. }
  143. /* L20: */
  144. }
  145. L30:
  146. g1 = -(s + s);
  147. goto L50;
  148. L40:
  149. g1 = (t1 - t2) / dnu;
  150. L50:
  151. g2 = t1 + t2;
  152. smu = 1.;
  153. fc = 1. / pi;
  154. flrx = log(rx);
  155. fmu = dnu * flrx;
  156. tm = 0.;
  157. if (dnu == 0.) {
  158. goto L60;
  159. }
  160. tm = sin(dnu * hpi) / dnu;
  161. tm = (dnu + dnu) * tm * tm;
  162. fc = dnu / sin(dnu * pi);
  163. if (fmu != 0.) {
  164. smu = sinh(fmu) / fmu;
  165. }
  166. L60:
  167. f = fc * (g1 * cosh(fmu) + g2 * flrx * smu);
  168. fx = exp(fmu);
  169. p = fc * t1 * fx;
  170. q = fc * t2 / fx;
  171. g = f + tm * q;
  172. ak = 1.;
  173. ck = 1.;
  174. bk = 1.;
  175. s1 = g;
  176. s2 = p;
  177. if (inu > 0 || *n > 1) {
  178. goto L90;
  179. }
  180. if (*x < tol) {
  181. goto L80;
  182. }
  183. cx = *x * *x * .25;
  184. L70:
  185. f = (ak * f + p + q) / (bk - dnu2);
  186. p /= ak - dnu;
  187. q /= ak + dnu;
  188. g = f + tm * q;
  189. ck = -ck * cx / ak;
  190. t1 = ck * g;
  191. s1 += t1;
  192. bk = bk + ak + ak + 1.;
  193. ak += 1.;
  194. s = abs(t1) / (abs(s1) + 1.);
  195. if (s > tol) {
  196. goto L70;
  197. }
  198. L80:
  199. y[1] = -s1;
  200. return 0;
  201. L90:
  202. if (*x < tol) {
  203. goto L110;
  204. }
  205. cx = *x * *x * .25;
  206. L100:
  207. f = (ak * f + p + q) / (bk - dnu2);
  208. p /= ak - dnu;
  209. q /= ak + dnu;
  210. g = f + tm * q;
  211. ck = -ck * cx / ak;
  212. t1 = ck * g;
  213. s1 += t1;
  214. t2 = ck * (p - ak * g);
  215. s2 += t2;
  216. bk = bk + ak + ak + 1.;
  217. ak += 1.;
  218. s = abs(t1) / (abs(s1) + 1.) + abs(t2) / (abs(s2) + 1.);
  219. if (s > tol) {
  220. goto L100;
  221. }
  222. L110:
  223. s2 = -s2 * rx;
  224. s1 = -s1;
  225. goto L160;
  226. L120:
  227. coef = rthpi / sqrt(*x);
  228. if (*x > x2) {
  229. goto L210;
  230. }
  231. /* MILLER ALGORITHM FOR X1.LT.X.LE.X2 */
  232. etest = cos(pi * dnu) / (pi * *x * tol);
  233. fks = 1.;
  234. fhs = .25;
  235. fk = 0.;
  236. rck = 2.;
  237. cck = *x + *x;
  238. rp1 = 0.;
  239. cp1 = 0.;
  240. rp2 = 1.;
  241. cp2 = 0.;
  242. k = 0;
  243. L130:
  244. ++k;
  245. fk += 1.;
  246. ak = (fhs - dnu2) / (fks + fk);
  247. pt = fk + 1.;
  248. rbk = rck / pt;
  249. cbk = cck / pt;
  250. rpt = rp2;
  251. cpt = cp2;
  252. rp2 = rbk * rpt - cbk * cpt - ak * rp1;
  253. cp2 = cbk * rpt + rbk * cpt - ak * cp1;
  254. rp1 = rpt;
  255. cp1 = cpt;
  256. rb[k - 1] = rbk;
  257. cb[k - 1] = cbk;
  258. a[k - 1] = ak;
  259. rck += 2.;
  260. fks = fks + fk + fk + 1.;
  261. fhs = fhs + fk + fk;
  262. /* Computing MAX */
  263. d__1 = abs(rp1), d__2 = abs(cp1);
  264. pt = max(d__1,d__2);
  265. /* Computing 2nd power */
  266. d__1 = rp1 / pt;
  267. /* Computing 2nd power */
  268. d__2 = cp1 / pt;
  269. fc = d__1 * d__1 + d__2 * d__2;
  270. pt = pt * sqrt(fc) * fk;
  271. if (etest > pt) {
  272. goto L130;
  273. }
  274. kk = k;
  275. rs = 1.;
  276. cs = 0.;
  277. rp1 = 0.;
  278. cp1 = 0.;
  279. rp2 = 1.;
  280. cp2 = 0.;
  281. i__1 = k;
  282. for (i__ = 1; i__ <= i__1; ++i__) {
  283. rpt = rp2;
  284. cpt = cp2;
  285. rp2 = (rb[kk - 1] * rpt - cb[kk - 1] * cpt - rp1) / a[kk - 1];
  286. cp2 = (cb[kk - 1] * rpt + rb[kk - 1] * cpt - cp1) / a[kk - 1];
  287. rp1 = rpt;
  288. cp1 = cpt;
  289. rs += rp2;
  290. cs += cp2;
  291. --kk;
  292. /* L140: */
  293. }
  294. /* Computing MAX */
  295. d__1 = abs(rs), d__2 = abs(cs);
  296. pt = max(d__1,d__2);
  297. /* Computing 2nd power */
  298. d__1 = rs / pt;
  299. /* Computing 2nd power */
  300. d__2 = cs / pt;
  301. fc = d__1 * d__1 + d__2 * d__2;
  302. pt *= sqrt(fc);
  303. rs1 = (rp2 * (rs / pt) + cp2 * (cs / pt)) / pt;
  304. cs1 = (cp2 * (rs / pt) - rp2 * (cs / pt)) / pt;
  305. fc = hpi * (dnu - .5) - *x;
  306. p = cos(fc);
  307. q = sin(fc);
  308. s1 = (cs1 * q - rs1 * p) * coef;
  309. if (inu > 0 || *n > 1) {
  310. goto L150;
  311. }
  312. y[1] = s1;
  313. return 0;
  314. L150:
  315. /* Computing MAX */
  316. d__1 = abs(rp2), d__2 = abs(cp2);
  317. pt = max(d__1,d__2);
  318. /* Computing 2nd power */
  319. d__1 = rp2 / pt;
  320. /* Computing 2nd power */
  321. d__2 = cp2 / pt;
  322. fc = d__1 * d__1 + d__2 * d__2;
  323. pt *= sqrt(fc);
  324. rpt = dnu + .5 - (rp1 * (rp2 / pt) + cp1 * (cp2 / pt)) / pt;
  325. cpt = *x - (cp1 * (rp2 / pt) - rp1 * (cp2 / pt)) / pt;
  326. cs2 = cs1 * cpt - rs1 * rpt;
  327. rs2 = rpt * cs1 + rs1 * cpt;
  328. s2 = (rs2 * q + cs2 * p) * coef / *x;
  329. /* FORWARD RECURSION ON THE THREE TERM RECURSION RELATION */
  330. L160:
  331. ck = (dnu + dnu + 2.) / *x;
  332. if (*n == 1) {
  333. --inu;
  334. }
  335. if (inu > 0) {
  336. goto L170;
  337. }
  338. if (*n > 1) {
  339. goto L190;
  340. }
  341. s1 = s2;
  342. goto L190;
  343. L170:
  344. i__1 = inu;
  345. for (i__ = 1; i__ <= i__1; ++i__) {
  346. st = s2;
  347. s2 = ck * s2 - s1;
  348. s1 = st;
  349. ck += rx;
  350. /* L180: */
  351. }
  352. if (*n == 1) {
  353. s1 = s2;
  354. }
  355. L190:
  356. y[1] = s1;
  357. if (*n == 1) {
  358. return 0;
  359. }
  360. y[2] = s2;
  361. if (*n == 2) {
  362. return 0;
  363. }
  364. i__1 = *n;
  365. for (i__ = 3; i__ <= i__1; ++i__) {
  366. y[i__] = ck * y[i__ - 1] - y[i__ - 2];
  367. ck += rx;
  368. /* L200: */
  369. }
  370. return 0;
  371. /* ASYMPTOTIC EXPANSION FOR LARGE X, X.GT.X2 */
  372. L210:
  373. nn = 2;
  374. if (inu == 0 && *n == 1) {
  375. nn = 1;
  376. }
  377. dnu2 = dnu + dnu;
  378. fmu = 0.;
  379. if (abs(dnu2) < tol) {
  380. goto L220;
  381. }
  382. fmu = dnu2 * dnu2;
  383. L220:
  384. arg = *x - hpi * (dnu + .5);
  385. sa = sin(arg);
  386. sb = cos(arg);
  387. etx = *x * 8.;
  388. i__1 = nn;
  389. for (k = 1; k <= i__1; ++k) {
  390. s1 = s2;
  391. t2 = (fmu - 1.) / etx;
  392. ss = t2;
  393. relb = tol * abs(t2);
  394. t1 = etx;
  395. s = 1.;
  396. fn = 1.;
  397. ak = 0.;
  398. for (j = 1; j <= 13; ++j) {
  399. t1 += etx;
  400. ak += 8.;
  401. fn += ak;
  402. t2 = -t2 * (fmu - fn) / t1;
  403. s += t2;
  404. t1 += etx;
  405. ak += 8.;
  406. fn += ak;
  407. t2 = t2 * (fmu - fn) / t1;
  408. ss += t2;
  409. if (abs(t2) <= relb) {
  410. goto L240;
  411. }
  412. /* L230: */
  413. }
  414. L240:
  415. s2 = coef * (s * sa + ss * sb);
  416. fmu = fmu + dnu * 8. + 4.;
  417. tb = sa;
  418. sa = -sb;
  419. sb = tb;
  420. /* L250: */
  421. }
  422. if (nn > 1) {
  423. goto L160;
  424. }
  425. s1 = s2;
  426. goto L190;
  427. /* FNU=HALF ODD INTEGER CASE */
  428. L260:
  429. coef = rthpi / sqrt(*x);
  430. s1 = coef * sin(*x);
  431. s2 = -coef * cos(*x);
  432. goto L160;
  433. L270:
  434. xermsg_("SLATEC", "DBSYNU", "X NOT GREATER THAN ZERO", &c__2, &c__1, (
  435. ftnlen)6, (ftnlen)6, (ftnlen)23);
  436. return 0;
  437. L280:
  438. xermsg_("SLATEC", "DBSYNU", "FNU NOT ZERO OR POSITIVE", &c__2, &c__1, (
  439. ftnlen)6, (ftnlen)6, (ftnlen)24);
  440. return 0;
  441. L290:
  442. xermsg_("SLATEC", "DBSYNU", "N NOT GREATER THAN 0", &c__2, &c__1, (ftnlen)
  443. 6, (ftnlen)6, (ftnlen)20);
  444. return 0;
  445. } /* dbsynu_ */