gsl_specfunc__bessel_J0.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* specfunc/bessel_J0.c
  2. *
  3. * Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. */
  19. /* Author: G. Jungman */
  20. #include "gsl__config.h"
  21. #include "gsl_math.h"
  22. #include "gsl_errno.h"
  23. #include "gsl_mode.h"
  24. #include "gsl_specfunc__bessel.h"
  25. #include "gsl_specfunc__bessel_amp_phase.h"
  26. #include "gsl_sf_trig.h"
  27. #include "gsl_sf_bessel.h"
  28. #include "gsl_specfunc__cheb_eval.c"
  29. /*-*-*-*-*-*-*-*-*-*-*-* Private Section *-*-*-*-*-*-*-*-*-*-*-*/
  30. /* based on SLATEC besj0, 1977 version, w. fullerton */
  31. /* chebyshev expansions for Bessel functions
  32. series for bj0 on the interval 0. to 1.60000d+01
  33. with weighted error 7.47e-18
  34. log weighted error 17.13
  35. significant figures required 16.98
  36. decimal places required 17.68
  37. */
  38. static double bj0_data[13] = {
  39. 0.100254161968939137,
  40. -0.665223007764405132,
  41. 0.248983703498281314,
  42. -0.0332527231700357697,
  43. 0.0023114179304694015,
  44. -0.0000991127741995080,
  45. 0.0000028916708643998,
  46. -0.0000000612108586630,
  47. 0.0000000009838650793,
  48. -0.0000000000124235515,
  49. 0.0000000000001265433,
  50. -0.0000000000000010619,
  51. 0.0000000000000000074,
  52. };
  53. static cheb_series bj0_cs = {
  54. bj0_data,
  55. 12,
  56. -1, 1,
  57. 9
  58. };
  59. /*-*-*-*-*-*-*-*-*-*-*-* Functions with Error Codes *-*-*-*-*-*-*-*-*-*-*-*/
  60. int gsl_sf_bessel_J0_e(const double x, gsl_sf_result * result)
  61. {
  62. double y = fabs(x);
  63. /* CHECK_POINTER(result) */
  64. if(y < 2.0*GSL_SQRT_DBL_EPSILON) {
  65. result->val = 1.0;
  66. result->err = y*y;
  67. return GSL_SUCCESS;
  68. }
  69. else if(y <= 4.0) {
  70. return cheb_eval_e(&bj0_cs, 0.125*y*y - 1.0, result);
  71. }
  72. else {
  73. const double z = 32.0/(y*y) - 1.0;
  74. gsl_sf_result ca;
  75. gsl_sf_result ct;
  76. gsl_sf_result cp;
  77. const int stat_ca = cheb_eval_e(&_gsl_sf_bessel_amp_phase_bm0_cs, z, &ca);
  78. const int stat_ct = cheb_eval_e(&_gsl_sf_bessel_amp_phase_bth0_cs, z, &ct);
  79. const int stat_cp = gsl_sf_bessel_cos_pi4_e(y, ct.val/y, &cp);
  80. const double sqrty = sqrt(y);
  81. const double ampl = (0.75 + ca.val) / sqrty;
  82. result->val = ampl * cp.val;
  83. result->err = fabs(cp.val) * ca.err/sqrty + fabs(ampl) * cp.err;
  84. result->err += GSL_DBL_EPSILON * fabs(result->val);
  85. return GSL_ERROR_SELECT_3(stat_ca, stat_ct, stat_cp);
  86. }
  87. }
  88. /*-*-*-*-*-*-*-*-*-* Functions w/ Natural Prototypes *-*-*-*-*-*-*-*-*-*-*/
  89. #include "gsl_specfunc__eval.h"
  90. double gsl_sf_bessel_J0(const double x)
  91. {
  92. EVAL_RESULT(gsl_sf_bessel_J0_e(x, &result));
  93. }