gsl_specfunc__bessel_Y1.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* specfunc/bessel_Y1.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 besy1, 1977 version, w. fullerton */
  31. /* chebyshev expansions
  32. series for by1 on the interval 0. to 1.60000d+01
  33. with weighted error 1.87e-18
  34. log weighted error 17.73
  35. significant figures required 17.83
  36. decimal places required 18.30
  37. */
  38. static double by1_data[14] = {
  39. 0.03208047100611908629,
  40. 1.262707897433500450,
  41. 0.00649996189992317500,
  42. -0.08936164528860504117,
  43. 0.01325088122175709545,
  44. -0.00089790591196483523,
  45. 0.00003647361487958306,
  46. -0.00000100137438166600,
  47. 0.00000001994539657390,
  48. -0.00000000030230656018,
  49. 0.00000000000360987815,
  50. -0.00000000000003487488,
  51. 0.00000000000000027838,
  52. -0.00000000000000000186
  53. };
  54. static cheb_series by1_cs = {
  55. by1_data,
  56. 13,
  57. -1, 1,
  58. 10
  59. };
  60. /*-*-*-*-*-*-*-*-*-*-*-* Functions with Error Codes *-*-*-*-*-*-*-*-*-*-*-*/
  61. int gsl_sf_bessel_Y1_e(const double x, gsl_sf_result * result)
  62. {
  63. const double two_over_pi = 2.0/M_PI;
  64. const double xmin = 1.571*GSL_DBL_MIN; /*exp ( amax1(alog(r1mach(1)), -alog(r1mach(2)))+.01) */
  65. const double x_small = 2.0 * GSL_SQRT_DBL_EPSILON;
  66. const double xmax = 1.0/GSL_DBL_EPSILON;
  67. /* CHECK_POINTER(result) */
  68. if(x <= 0.0) {
  69. DOMAIN_ERROR(result);
  70. }
  71. else if(x < xmin) {
  72. OVERFLOW_ERROR(result);
  73. }
  74. else if(x < x_small) {
  75. const double lnterm = log(0.5*x);
  76. gsl_sf_result J1;
  77. gsl_sf_result c;
  78. int status = gsl_sf_bessel_J1_e(x, &J1);
  79. cheb_eval_e(&by1_cs, -1.0, &c);
  80. result->val = two_over_pi * lnterm * J1.val + (0.5 + c.val)/x;
  81. result->err = fabs(lnterm) * (fabs(GSL_DBL_EPSILON * J1.val) + J1.err) + c.err/x;
  82. return status;
  83. }
  84. else if(x < 4.0) {
  85. const double lnterm = log(0.5*x);
  86. int status;
  87. gsl_sf_result J1;
  88. gsl_sf_result c;
  89. cheb_eval_e(&by1_cs, 0.125*x*x-1.0, &c);
  90. status = gsl_sf_bessel_J1_e(x, &J1);
  91. result->val = two_over_pi * lnterm * J1.val + (0.5 + c.val)/x;
  92. result->err = fabs(lnterm) * (fabs(GSL_DBL_EPSILON * J1.val) + J1.err) + c.err/x;
  93. return status;
  94. }
  95. else if(x < xmax) {
  96. const double z = 32.0/(x*x) - 1.0;
  97. gsl_sf_result ca;
  98. gsl_sf_result ct;
  99. gsl_sf_result cp;
  100. const int stat_ca = cheb_eval_e(&_gsl_sf_bessel_amp_phase_bm1_cs, z, &ca);
  101. const int stat_ct = cheb_eval_e(&_gsl_sf_bessel_amp_phase_bth1_cs, z, &ct);
  102. const int stat_cp = gsl_sf_bessel_cos_pi4_e(x, ct.val/x, &cp);
  103. const double sqrtx = sqrt(x);
  104. const double ampl = (0.75 + ca.val) / sqrtx;
  105. result->val = -ampl * cp.val;
  106. result->err = fabs(cp.val) * ca.err/sqrtx + fabs(ampl) * cp.err;
  107. result->err += GSL_DBL_EPSILON * fabs(result->val);
  108. return GSL_ERROR_SELECT_3(stat_ca, stat_ct, stat_cp);
  109. }
  110. else {
  111. UNDERFLOW_ERROR(result);
  112. }
  113. }
  114. /*-*-*-*-*-*-*-*-*-* Functions w/ Natural Prototypes *-*-*-*-*-*-*-*-*-*-*/
  115. #include "gsl_specfunc__eval.h"
  116. double gsl_sf_bessel_Y1(const double x)
  117. {
  118. EVAL_RESULT(gsl_sf_bessel_Y1_e(x, &result));
  119. }