gsl_specfunc__bessel_Y0.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* specfunc/bessel_Y0.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_sf_trig.h"
  24. #include "gsl_sf_bessel.h"
  25. #include "gsl_specfunc__error.h"
  26. #include "gsl_specfunc__bessel.h"
  27. #include "gsl_specfunc__bessel_amp_phase.h"
  28. #include "gsl_specfunc__cheb_eval.c"
  29. /*-*-*-*-*-*-*-*-*-*-*-* Private Section *-*-*-*-*-*-*-*-*-*-*-*/
  30. /* based on SLATEC besy0, 1980 version, w. fullerton */
  31. /* chebyshev expansions
  32. series for by0 on the interval 0. to 1.60000d+01
  33. with weighted error 1.20e-17
  34. log weighted error 16.92
  35. significant figures required 16.15
  36. decimal places required 17.48
  37. */
  38. static double by0_data[13] = {
  39. -0.011277839392865573,
  40. -0.128345237560420350,
  41. -0.104378847997942490,
  42. 0.023662749183969695,
  43. -0.002090391647700486,
  44. 0.000103975453939057,
  45. -0.000003369747162423,
  46. 0.000000077293842676,
  47. -0.000000001324976772,
  48. 0.000000000017648232,
  49. -0.000000000000188105,
  50. 0.000000000000001641,
  51. -0.000000000000000011
  52. };
  53. static cheb_series by0_cs = {
  54. by0_data,
  55. 12,
  56. -1, 1,
  57. 8
  58. };
  59. /*-*-*-*-*-*-*-*-*-*-*-* Functions with Error Codes *-*-*-*-*-*-*-*-*-*-*-*/
  60. int gsl_sf_bessel_Y0_e(const double x, gsl_sf_result * result)
  61. {
  62. const double two_over_pi = 2.0/M_PI;
  63. const double xmax = 1.0/GSL_DBL_EPSILON;
  64. /* CHECK_POINTER(result) */
  65. if (x <= 0.0) {
  66. DOMAIN_ERROR(result);
  67. }
  68. else if(x < 4.0) {
  69. gsl_sf_result J0;
  70. gsl_sf_result c;
  71. int stat_J0 = gsl_sf_bessel_J0_e(x, &J0);
  72. cheb_eval_e(&by0_cs, 0.125*x*x-1.0, &c);
  73. result->val = two_over_pi*(-M_LN2 + log(x))*J0.val + 0.375 + c.val;
  74. result->err = 2.0 * GSL_DBL_EPSILON * fabs(result->val) + c.err;
  75. return stat_J0;
  76. }
  77. else if(x < xmax) {
  78. /* Leading behaviour of phase is x, which is exact,
  79. * so the error is bounded.
  80. */
  81. const double z = 32.0/(x*x) - 1.0;
  82. gsl_sf_result c1;
  83. gsl_sf_result c2;
  84. gsl_sf_result sp;
  85. const int stat_c1 = cheb_eval_e(&_gsl_sf_bessel_amp_phase_bm0_cs, z, &c1);
  86. const int stat_c2 = cheb_eval_e(&_gsl_sf_bessel_amp_phase_bth0_cs, z, &c2);
  87. const int stat_sp = gsl_sf_bessel_sin_pi4_e(x, c2.val/x, &sp);
  88. const double sqrtx = sqrt(x);
  89. const double ampl = (0.75 + c1.val) / sqrtx;
  90. result->val = ampl * sp.val;
  91. result->err = fabs(sp.val) * c1.err/sqrtx + fabs(ampl) * sp.err;
  92. result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
  93. return GSL_ERROR_SELECT_3(stat_sp, stat_c1, stat_c2);
  94. }
  95. else {
  96. UNDERFLOW_ERROR(result);
  97. }
  98. }
  99. /*-*-*-*-*-*-*-*-*-* Functions w/ Natural Prototypes *-*-*-*-*-*-*-*-*-*-*/
  100. #include "gsl_specfunc__eval.h"
  101. double gsl_sf_bessel_Y0(const double x)
  102. {
  103. EVAL_RESULT(gsl_sf_bessel_Y0_e(x, &result));
  104. }