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