jvf.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848
  1. /* jvf.c
  2. *
  3. * Bessel function of noninteger order
  4. *
  5. *
  6. *
  7. * SYNOPSIS:
  8. *
  9. * float v, x, y, jvf();
  10. *
  11. * y = jvf( v, x );
  12. *
  13. *
  14. *
  15. * DESCRIPTION:
  16. *
  17. * Returns Bessel function of order v of the argument,
  18. * where v is real. Negative x is allowed if v is an integer.
  19. *
  20. * Several expansions are included: the ascending power
  21. * series, the Hankel expansion, and two transitional
  22. * expansions for large v. If v is not too large, it
  23. * is reduced by recurrence to a region of best accuracy.
  24. *
  25. * The single precision routine accepts negative v, but with
  26. * reduced accuracy.
  27. *
  28. *
  29. *
  30. * ACCURACY:
  31. * Results for integer v are indicated by *.
  32. * Error criterion is absolute, except relative when |jv()| > 1.
  33. *
  34. * arithmetic domain # trials peak rms
  35. * v x
  36. * IEEE 0,125 0,125 30000 2.0e-6 2.0e-7
  37. * IEEE -17,0 0,125 30000 1.1e-5 4.0e-7
  38. * IEEE -100,0 0,125 3000 1.5e-4 7.8e-6
  39. */
  40. /*
  41. Cephes Math Library Release 2.2: June, 1992
  42. Copyright 1984, 1987, 1989, 1992 by Stephen L. Moshier
  43. Direct inquiries to 30 Frost Street, Cambridge, MA 02140
  44. */
  45. #include <math.h>
  46. #define DEBUG 0
  47. extern float MAXNUMF, MACHEPF, MINLOGF, MAXLOGF, PIF;
  48. extern int sgngamf;
  49. /* BIG = 1/MACHEPF */
  50. #define BIG 16777216.
  51. #ifdef ANSIC
  52. float floorf(float), j0f(float), j1f(float);
  53. static float jnxf(float, float);
  54. static float jvsf(float, float);
  55. static float hankelf(float, float);
  56. static float jntf(float, float);
  57. static float recurf( float *, float, float * );
  58. float sqrtf(float), sinf(float), cosf(float);
  59. float lgamf(float), expf(float), logf(float), powf(float, float);
  60. float gammaf(float), cbrtf(float), acosf(float);
  61. int airyf(float, float *, float *, float *, float *);
  62. float polevlf(float, float *, int);
  63. #else
  64. float floorf(), j0f(), j1f();
  65. float sqrtf(), sinf(), cosf();
  66. float lgamf(), expf(), logf(), powf(), gammaf();
  67. float cbrtf(), polevlf(), acosf();
  68. void airyf();
  69. static float recurf(), jvsf(), hankelf(), jnxf(), jntf(), jvsf();
  70. #endif
  71. #define fabsf(x) ( (x) < 0 ? -(x) : (x) )
  72. float jvf( float nn, float xx )
  73. {
  74. float n, x, k, q, t, y, an, sign;
  75. int i, nint;
  76. n = nn;
  77. x = xx;
  78. nint = 0; /* Flag for integer n */
  79. sign = 1.0; /* Flag for sign inversion */
  80. an = fabsf( n );
  81. y = floorf( an );
  82. if( y == an )
  83. {
  84. nint = 1;
  85. i = an - 16384.0 * floorf( an/16384.0 );
  86. if( n < 0.0 )
  87. {
  88. if( i & 1 )
  89. sign = -sign;
  90. n = an;
  91. }
  92. if( x < 0.0 )
  93. {
  94. if( i & 1 )
  95. sign = -sign;
  96. x = -x;
  97. }
  98. if( n == 0.0 )
  99. return( j0f(x) );
  100. if( n == 1.0 )
  101. return( sign * j1f(x) );
  102. }
  103. if( (x < 0.0) && (y != an) )
  104. {
  105. mtherr( "jvf", DOMAIN );
  106. y = 0.0;
  107. goto done;
  108. }
  109. y = fabsf(x);
  110. if( y < MACHEPF )
  111. goto underf;
  112. /* Easy cases - x small compared to n */
  113. t = 3.6 * sqrtf(an);
  114. if( y < t )
  115. return( sign * jvsf(n,x) );
  116. /* x large compared to n */
  117. k = 3.6 * sqrtf(y);
  118. if( (an < k) && (y > 6.0) )
  119. return( sign * hankelf(n,x) );
  120. if( (n > -100) && (n < 14.0) )
  121. {
  122. /* Note: if x is too large, the continued
  123. * fraction will fail; but then the
  124. * Hankel expansion can be used.
  125. */
  126. if( nint != 0 )
  127. {
  128. k = 0.0;
  129. q = recurf( &n, x, &k );
  130. if( k == 0.0 )
  131. {
  132. y = j0f(x)/q;
  133. goto done;
  134. }
  135. if( k == 1.0 )
  136. {
  137. y = j1f(x)/q;
  138. goto done;
  139. }
  140. }
  141. if( n >= 0.0 )
  142. {
  143. /* Recur backwards from a larger value of n
  144. */
  145. if( y > 1.3 * an )
  146. goto recurdwn;
  147. if( an > 1.3 * y )
  148. goto recurdwn;
  149. k = n;
  150. y = 2.0*(y+an+1.0);
  151. if( (y - n) > 33.0 )
  152. y = n + 33.0;
  153. y = n + floorf(y-n);
  154. q = recurf( &y, x, &k );
  155. y = jvsf(y,x) * q;
  156. goto done;
  157. }
  158. recurdwn:
  159. if( an > (k + 3.0) )
  160. {
  161. /* Recur backwards from n to k
  162. */
  163. if( n < 0.0 )
  164. k = -k;
  165. q = n - floorf(n);
  166. k = floorf(k) + q;
  167. if( n > 0.0 )
  168. q = recurf( &n, x, &k );
  169. else
  170. {
  171. t = k;
  172. k = n;
  173. q = recurf( &t, x, &k );
  174. k = t;
  175. }
  176. if( q == 0.0 )
  177. {
  178. underf:
  179. y = 0.0;
  180. goto done;
  181. }
  182. }
  183. else
  184. {
  185. k = n;
  186. q = 1.0;
  187. }
  188. /* boundary between convergence of
  189. * power series and Hankel expansion
  190. */
  191. t = fabsf(k);
  192. if( t < 26.0 )
  193. t = (0.0083*t + 0.09)*t + 12.9;
  194. else
  195. t = 0.9 * t;
  196. if( y > t ) /* y = |x| */
  197. y = hankelf(k,x);
  198. else
  199. y = jvsf(k,x);
  200. #if DEBUG
  201. printf( "y = %.16e, q = %.16e\n", y, q );
  202. #endif
  203. if( n > 0.0 )
  204. y /= q;
  205. else
  206. y *= q;
  207. }
  208. else
  209. {
  210. /* For large positive n, use the uniform expansion
  211. * or the transitional expansion.
  212. * But if x is of the order of n**2,
  213. * these may blow up, whereas the
  214. * Hankel expansion will then work.
  215. */
  216. if( n < 0.0 )
  217. {
  218. mtherr( "jvf", TLOSS );
  219. y = 0.0;
  220. goto done;
  221. }
  222. t = y/an;
  223. t /= an;
  224. if( t > 0.3 )
  225. y = hankelf(n,x);
  226. else
  227. y = jnxf(n,x);
  228. }
  229. done: return( sign * y);
  230. }
  231. /* Reduce the order by backward recurrence.
  232. * AMS55 #9.1.27 and 9.1.73.
  233. */
  234. static float recurf( float *n, float xx, float *newn )
  235. {
  236. float x, pkm2, pkm1, pk, pkp1, qkm2, qkm1;
  237. float k, ans, qk, xk, yk, r, t, kf, xinv;
  238. static float big = BIG;
  239. int nflag, ctr;
  240. x = xx;
  241. /* continued fraction for Jn(x)/Jn-1(x) */
  242. if( *n < 0.0 )
  243. nflag = 1;
  244. else
  245. nflag = 0;
  246. fstart:
  247. #if DEBUG
  248. printf( "n = %.6e, newn = %.6e, cfrac = ", *n, *newn );
  249. #endif
  250. pkm2 = 0.0;
  251. qkm2 = 1.0;
  252. pkm1 = x;
  253. qkm1 = *n + *n;
  254. xk = -x * x;
  255. yk = qkm1;
  256. ans = 1.0;
  257. ctr = 0;
  258. do
  259. {
  260. yk += 2.0;
  261. pk = pkm1 * yk + pkm2 * xk;
  262. qk = qkm1 * yk + qkm2 * xk;
  263. pkm2 = pkm1;
  264. pkm1 = pk;
  265. qkm2 = qkm1;
  266. qkm1 = qk;
  267. if( qk != 0 )
  268. r = pk/qk;
  269. else
  270. r = 0.0;
  271. if( r != 0 )
  272. {
  273. t = fabsf( (ans - r)/r );
  274. ans = r;
  275. }
  276. else
  277. t = 1.0;
  278. if( t < MACHEPF )
  279. goto done;
  280. if( fabsf(pk) > big )
  281. {
  282. pkm2 *= MACHEPF;
  283. pkm1 *= MACHEPF;
  284. qkm2 *= MACHEPF;
  285. qkm1 *= MACHEPF;
  286. }
  287. }
  288. while( t > MACHEPF );
  289. done:
  290. #if DEBUG
  291. printf( "%.6e\n", ans );
  292. #endif
  293. /* Change n to n-1 if n < 0 and the continued fraction is small
  294. */
  295. if( nflag > 0 )
  296. {
  297. if( fabsf(ans) < 0.125 )
  298. {
  299. nflag = -1;
  300. *n = *n - 1.0;
  301. goto fstart;
  302. }
  303. }
  304. kf = *newn;
  305. /* backward recurrence
  306. * 2k
  307. * J (x) = --- J (x) - J (x)
  308. * k-1 x k k+1
  309. */
  310. pk = 1.0;
  311. pkm1 = 1.0/ans;
  312. k = *n - 1.0;
  313. r = 2 * k;
  314. xinv = 1.0/x;
  315. do
  316. {
  317. pkm2 = (pkm1 * r - pk * x) * xinv;
  318. pkp1 = pk;
  319. pk = pkm1;
  320. pkm1 = pkm2;
  321. r -= 2.0;
  322. #if 0
  323. t = fabsf(pkp1) + fabsf(pk);
  324. if( (k > (kf + 2.5)) && (fabsf(pkm1) < 0.25*t) )
  325. {
  326. k -= 1.0;
  327. t = x*x;
  328. pkm2 = ( (r*(r+2.0)-t)*pk - r*x*pkp1 )/t;
  329. pkp1 = pk;
  330. pk = pkm1;
  331. pkm1 = pkm2;
  332. r -= 2.0;
  333. }
  334. #endif
  335. k -= 1.0;
  336. }
  337. while( k > (kf + 0.5) );
  338. #if 0
  339. /* Take the larger of the last two iterates
  340. * on the theory that it may have less cancellation error.
  341. */
  342. if( (kf >= 0.0) && (fabsf(pk) > fabsf(pkm1)) )
  343. {
  344. k += 1.0;
  345. pkm2 = pk;
  346. }
  347. #endif
  348. *newn = k;
  349. #if DEBUG
  350. printf( "newn %.6e\n", k );
  351. #endif
  352. return( pkm2 );
  353. }
  354. /* Ascending power series for Jv(x).
  355. * AMS55 #9.1.10.
  356. */
  357. static float jvsf( float nn, float xx )
  358. {
  359. float n, x, t, u, y, z, k, ay;
  360. #if DEBUG
  361. printf( "jvsf: " );
  362. #endif
  363. n = nn;
  364. x = xx;
  365. z = -0.25 * x * x;
  366. u = 1.0;
  367. y = u;
  368. k = 1.0;
  369. t = 1.0;
  370. while( t > MACHEPF )
  371. {
  372. u *= z / (k * (n+k));
  373. y += u;
  374. k += 1.0;
  375. t = fabsf(u);
  376. if( (ay = fabsf(y)) > 1.0 )
  377. t /= ay;
  378. }
  379. if( x < 0.0 )
  380. {
  381. y = y * powf( 0.5 * x, n ) / gammaf( n + 1.0 );
  382. }
  383. else
  384. {
  385. t = n * logf(0.5*x) - lgamf(n + 1.0);
  386. if( t < -MAXLOGF )
  387. {
  388. return( 0.0 );
  389. }
  390. if( t > MAXLOGF )
  391. {
  392. t = logf(y) + t;
  393. if( t > MAXLOGF )
  394. {
  395. mtherr( "jvf", OVERFLOW );
  396. return( MAXNUMF );
  397. }
  398. else
  399. {
  400. y = sgngamf * expf(t);
  401. return(y);
  402. }
  403. }
  404. y = sgngamf * y * expf( t );
  405. }
  406. #if DEBUG
  407. printf( "y = %.8e\n", y );
  408. #endif
  409. return(y);
  410. }
  411. /* Hankel's asymptotic expansion
  412. * for large x.
  413. * AMS55 #9.2.5.
  414. */
  415. static float hankelf( float nn, float xx )
  416. {
  417. float n, x, t, u, z, k, sign, conv;
  418. float p, q, j, m, pp, qq;
  419. int flag;
  420. #if DEBUG
  421. printf( "hankelf: " );
  422. #endif
  423. n = nn;
  424. x = xx;
  425. m = 4.0*n*n;
  426. j = 1.0;
  427. z = 8.0 * x;
  428. k = 1.0;
  429. p = 1.0;
  430. u = (m - 1.0)/z;
  431. q = u;
  432. sign = 1.0;
  433. conv = 1.0;
  434. flag = 0;
  435. t = 1.0;
  436. pp = 1.0e38;
  437. qq = 1.0e38;
  438. while( t > MACHEPF )
  439. {
  440. k += 2.0;
  441. j += 1.0;
  442. sign = -sign;
  443. u *= (m - k * k)/(j * z);
  444. p += sign * u;
  445. k += 2.0;
  446. j += 1.0;
  447. u *= (m - k * k)/(j * z);
  448. q += sign * u;
  449. t = fabsf(u/p);
  450. if( t < conv )
  451. {
  452. conv = t;
  453. qq = q;
  454. pp = p;
  455. flag = 1;
  456. }
  457. /* stop if the terms start getting larger */
  458. if( (flag != 0) && (t > conv) )
  459. {
  460. #if DEBUG
  461. printf( "Hankel: convergence to %.4E\n", conv );
  462. #endif
  463. goto hank1;
  464. }
  465. }
  466. hank1:
  467. u = x - (0.5*n + 0.25) * PIF;
  468. t = sqrtf( 2.0/(PIF*x) ) * ( pp * cosf(u) - qq * sinf(u) );
  469. return( t );
  470. }
  471. /* Asymptotic expansion for large n.
  472. * AMS55 #9.3.35.
  473. */
  474. static float lambda[] = {
  475. 1.0,
  476. 1.041666666666666666666667E-1,
  477. 8.355034722222222222222222E-2,
  478. 1.282265745563271604938272E-1,
  479. 2.918490264641404642489712E-1,
  480. 8.816272674437576524187671E-1,
  481. 3.321408281862767544702647E+0,
  482. 1.499576298686255465867237E+1,
  483. 7.892301301158651813848139E+1,
  484. 4.744515388682643231611949E+2,
  485. 3.207490090890661934704328E+3
  486. };
  487. static float mu[] = {
  488. 1.0,
  489. -1.458333333333333333333333E-1,
  490. -9.874131944444444444444444E-2,
  491. -1.433120539158950617283951E-1,
  492. -3.172272026784135480967078E-1,
  493. -9.424291479571202491373028E-1,
  494. -3.511203040826354261542798E+0,
  495. -1.572726362036804512982712E+1,
  496. -8.228143909718594444224656E+1,
  497. -4.923553705236705240352022E+2,
  498. -3.316218568547972508762102E+3
  499. };
  500. static float P1[] = {
  501. -2.083333333333333333333333E-1,
  502. 1.250000000000000000000000E-1
  503. };
  504. static float P2[] = {
  505. 3.342013888888888888888889E-1,
  506. -4.010416666666666666666667E-1,
  507. 7.031250000000000000000000E-2
  508. };
  509. static float P3[] = {
  510. -1.025812596450617283950617E+0,
  511. 1.846462673611111111111111E+0,
  512. -8.912109375000000000000000E-1,
  513. 7.324218750000000000000000E-2
  514. };
  515. static float P4[] = {
  516. 4.669584423426247427983539E+0,
  517. -1.120700261622299382716049E+1,
  518. 8.789123535156250000000000E+0,
  519. -2.364086914062500000000000E+0,
  520. 1.121520996093750000000000E-1
  521. };
  522. static float P5[] = {
  523. -2.8212072558200244877E1,
  524. 8.4636217674600734632E1,
  525. -9.1818241543240017361E1,
  526. 4.2534998745388454861E1,
  527. -7.3687943594796316964E0,
  528. 2.27108001708984375E-1
  529. };
  530. static float P6[] = {
  531. 2.1257013003921712286E2,
  532. -7.6525246814118164230E2,
  533. 1.0599904525279998779E3,
  534. -6.9957962737613254123E2,
  535. 2.1819051174421159048E2,
  536. -2.6491430486951555525E1,
  537. 5.7250142097473144531E-1
  538. };
  539. static float P7[] = {
  540. -1.9194576623184069963E3,
  541. 8.0617221817373093845E3,
  542. -1.3586550006434137439E4,
  543. 1.1655393336864533248E4,
  544. -5.3056469786134031084E3,
  545. 1.2009029132163524628E3,
  546. -1.0809091978839465550E2,
  547. 1.7277275025844573975E0
  548. };
  549. static float jnxf( float nn, float xx )
  550. {
  551. float n, x, zeta, sqz, zz, zp, np;
  552. float cbn, n23, t, z, sz;
  553. float pp, qq, z32i, zzi;
  554. float ak, bk, akl, bkl;
  555. int sign, doa, dob, nflg, k, s, tk, tkp1, m;
  556. static float u[8];
  557. static float ai, aip, bi, bip;
  558. n = nn;
  559. x = xx;
  560. /* Test for x very close to n.
  561. * Use expansion for transition region if so.
  562. */
  563. cbn = cbrtf(n);
  564. z = (x - n)/cbn;
  565. if( (fabsf(z) <= 0.7) || (n < 0.0) )
  566. return( jntf(n,x) );
  567. z = x/n;
  568. zz = 1.0 - z*z;
  569. if( zz == 0.0 )
  570. return(0.0);
  571. if( zz > 0.0 )
  572. {
  573. sz = sqrtf( zz );
  574. t = 1.5 * (logf( (1.0+sz)/z ) - sz ); /* zeta ** 3/2 */
  575. zeta = cbrtf( t * t );
  576. nflg = 1;
  577. }
  578. else
  579. {
  580. sz = sqrtf(-zz);
  581. t = 1.5 * (sz - acosf(1.0/z));
  582. zeta = -cbrtf( t * t );
  583. nflg = -1;
  584. }
  585. z32i = fabsf(1.0/t);
  586. sqz = cbrtf(t);
  587. /* Airy function */
  588. n23 = cbrtf( n * n );
  589. t = n23 * zeta;
  590. #if DEBUG
  591. printf("zeta %.5E, Airyf(%.5E)\n", zeta, t );
  592. #endif
  593. airyf( t, &ai, &aip, &bi, &bip );
  594. /* polynomials in expansion */
  595. u[0] = 1.0;
  596. zzi = 1.0/zz;
  597. u[1] = polevlf( zzi, P1, 1 )/sz;
  598. u[2] = polevlf( zzi, P2, 2 )/zz;
  599. u[3] = polevlf( zzi, P3, 3 )/(sz*zz);
  600. pp = zz*zz;
  601. u[4] = polevlf( zzi, P4, 4 )/pp;
  602. u[5] = polevlf( zzi, P5, 5 )/(pp*sz);
  603. pp *= zz;
  604. u[6] = polevlf( zzi, P6, 6 )/pp;
  605. u[7] = polevlf( zzi, P7, 7 )/(pp*sz);
  606. #if DEBUG
  607. for( k=0; k<=7; k++ )
  608. printf( "u[%d] = %.5E\n", k, u[k] );
  609. #endif
  610. pp = 0.0;
  611. qq = 0.0;
  612. np = 1.0;
  613. /* flags to stop when terms get larger */
  614. doa = 1;
  615. dob = 1;
  616. akl = MAXNUMF;
  617. bkl = MAXNUMF;
  618. for( k=0; k<=3; k++ )
  619. {
  620. tk = 2 * k;
  621. tkp1 = tk + 1;
  622. zp = 1.0;
  623. ak = 0.0;
  624. bk = 0.0;
  625. for( s=0; s<=tk; s++ )
  626. {
  627. if( doa )
  628. {
  629. if( (s & 3) > 1 )
  630. sign = nflg;
  631. else
  632. sign = 1;
  633. ak += sign * mu[s] * zp * u[tk-s];
  634. }
  635. if( dob )
  636. {
  637. m = tkp1 - s;
  638. if( ((m+1) & 3) > 1 )
  639. sign = nflg;
  640. else
  641. sign = 1;
  642. bk += sign * lambda[s] * zp * u[m];
  643. }
  644. zp *= z32i;
  645. }
  646. if( doa )
  647. {
  648. ak *= np;
  649. t = fabsf(ak);
  650. if( t < akl )
  651. {
  652. akl = t;
  653. pp += ak;
  654. }
  655. else
  656. doa = 0;
  657. }
  658. if( dob )
  659. {
  660. bk += lambda[tkp1] * zp * u[0];
  661. bk *= -np/sqz;
  662. t = fabsf(bk);
  663. if( t < bkl )
  664. {
  665. bkl = t;
  666. qq += bk;
  667. }
  668. else
  669. dob = 0;
  670. }
  671. #if DEBUG
  672. printf("a[%d] %.5E, b[%d] %.5E\n", k, ak, k, bk );
  673. #endif
  674. if( np < MACHEPF )
  675. break;
  676. np /= n*n;
  677. }
  678. /* normalizing factor ( 4*zeta/(1 - z**2) )**1/4 */
  679. t = 4.0 * zeta/zz;
  680. t = sqrtf( sqrtf(t) );
  681. t *= ai*pp/cbrtf(n) + aip*qq/(n23*n);
  682. return(t);
  683. }
  684. /* Asymptotic expansion for transition region,
  685. * n large and x close to n.
  686. * AMS55 #9.3.23.
  687. */
  688. static float PF2[] = {
  689. -9.0000000000000000000e-2,
  690. 8.5714285714285714286e-2
  691. };
  692. static float PF3[] = {
  693. 1.3671428571428571429e-1,
  694. -5.4920634920634920635e-2,
  695. -4.4444444444444444444e-3
  696. };
  697. static float PF4[] = {
  698. 1.3500000000000000000e-3,
  699. -1.6036054421768707483e-1,
  700. 4.2590187590187590188e-2,
  701. 2.7330447330447330447e-3
  702. };
  703. static float PG1[] = {
  704. -2.4285714285714285714e-1,
  705. 1.4285714285714285714e-2
  706. };
  707. static float PG2[] = {
  708. -9.0000000000000000000e-3,
  709. 1.9396825396825396825e-1,
  710. -1.1746031746031746032e-2
  711. };
  712. static float PG3[] = {
  713. 1.9607142857142857143e-2,
  714. -1.5983694083694083694e-1,
  715. 6.3838383838383838384e-3
  716. };
  717. static float jntf( float nn, float xx )
  718. {
  719. float n, x, z, zz, z3;
  720. float cbn, n23, cbtwo;
  721. float ai, aip, bi, bip; /* Airy functions */
  722. float nk, fk, gk, pp, qq;
  723. float F[5], G[4];
  724. int k;
  725. n = nn;
  726. x = xx;
  727. cbn = cbrtf(n);
  728. z = (x - n)/cbn;
  729. cbtwo = cbrtf( 2.0 );
  730. /* Airy function */
  731. zz = -cbtwo * z;
  732. airyf( zz, &ai, &aip, &bi, &bip );
  733. /* polynomials in expansion */
  734. zz = z * z;
  735. z3 = zz * z;
  736. F[0] = 1.0;
  737. F[1] = -z/5.0;
  738. F[2] = polevlf( z3, PF2, 1 ) * zz;
  739. F[3] = polevlf( z3, PF3, 2 );
  740. F[4] = polevlf( z3, PF4, 3 ) * z;
  741. G[0] = 0.3 * zz;
  742. G[1] = polevlf( z3, PG1, 1 );
  743. G[2] = polevlf( z3, PG2, 2 ) * z;
  744. G[3] = polevlf( z3, PG3, 2 ) * zz;
  745. #if DEBUG
  746. for( k=0; k<=4; k++ )
  747. printf( "F[%d] = %.5E\n", k, F[k] );
  748. for( k=0; k<=3; k++ )
  749. printf( "G[%d] = %.5E\n", k, G[k] );
  750. #endif
  751. pp = 0.0;
  752. qq = 0.0;
  753. nk = 1.0;
  754. n23 = cbrtf( n * n );
  755. for( k=0; k<=4; k++ )
  756. {
  757. fk = F[k]*nk;
  758. pp += fk;
  759. if( k != 4 )
  760. {
  761. gk = G[k]*nk;
  762. qq += gk;
  763. }
  764. #if DEBUG
  765. printf("fk[%d] %.5E, gk[%d] %.5E\n", k, fk, k, gk );
  766. #endif
  767. nk /= n23;
  768. }
  769. fk = cbtwo * ai * pp/cbn + cbrtf(4.0) * aip * qq/n;
  770. return(fk);
  771. }