1 /* specfunc/bessel_Jnu.c
3 * Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman
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.
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.
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.
20 /* Author: G. Jungman */
23 #include <gsl/gsl_math.h>
24 #include <gsl/gsl_errno.h>
25 #include <gsl/gsl_sf_bessel.h>
30 #include "bessel_olver.h"
31 #include "bessel_temme.h"
34 /* Evaluate at large enough nu to apply asymptotic
35 * results and apply backward recurrence.
40 bessel_J_recur_asymp(const double nu, const double x,
41 gsl_sf_result * Jnu, gsl_sf_result * Jnup1)
43 const double nu_cut = 25.0;
45 int steps = ceil(nu_cut - nu) + 1;
49 int stat_O1 = gsl_sf_bessel_Jnu_asymp_Olver_e(nu + steps + 1.0, x, &r_Jnp1);
50 int stat_O2 = gsl_sf_bessel_Jnu_asymp_Olver_e(nu + steps, x, &r_Jn);
51 double r_fe = fabs(r_Jnp1.err/r_Jnp1.val) + fabs(r_Jn.err/r_Jn.val);
52 double Jnp1 = r_Jnp1.val;
57 for(n=steps; n>0; n--) {
58 Jnm1 = 2.0*(nu+n)/x * Jn - Jnp1;
65 Jnu->err = (r_fe + GSL_DBL_EPSILON * (steps + 1.0)) * fabs(Jn);
66 Jnup1->val = Jnp1_save;
67 Jnup1->err = (r_fe + GSL_DBL_EPSILON * (steps + 1.0)) * fabs(Jnp1_save);
69 return GSL_ERROR_SELECT_2(stat_O1, stat_O2);
74 /*-*-*-*-*-*-*-*-*-*-*-* Functions with Error Codes *-*-*-*-*-*-*-*-*-*-*-*/
77 gsl_sf_bessel_Jnu_e(const double nu, const double x, gsl_sf_result * result)
79 /* CHECK_POINTER(result) */
81 if(x < 0.0 || nu < 0.0) {
95 else if(x*x < 10.0*(nu+1.0)) {
96 return gsl_sf_bessel_IJ_taylor_e(nu, x, -1, 100, GSL_DBL_EPSILON, result);
99 return gsl_sf_bessel_Jnu_asymp_Olver_e(nu, x, result);
103 /* We need this to avoid feeding large x to CF1; note that
104 * due to the above check, we know that n <= 50. See similar
105 * block in bessel_Jn.c.
107 return gsl_sf_bessel_Jnu_asympx_e(nu, x, result);
110 /* -1/2 <= mu <= 1/2 */
111 int N = (int)(nu + 0.5);
114 /* Determine the J ratio at nu.
118 const int stat_CF1 = gsl_sf_bessel_J_CF1(nu, x, &Jnup1_Jnu, &sgn_Jnu);
121 /* Determine Y_mu, Y_mup1 directly and recurse forward to nu.
122 * Then use the CF1 information to solve for J_nu and J_nup1.
124 gsl_sf_result Y_mu, Y_mup1;
125 const int stat_mu = gsl_sf_bessel_Y_temme(mu, x, &Y_mu, &Y_mup1);
127 double Ynm1 = Y_mu.val;
128 double Yn = Y_mup1.val;
132 Ynp1 = 2.0*(mu+n)/x * Yn - Ynm1;
137 result->val = 2.0/(M_PI*x) / (Jnup1_Jnu*Yn - Ynp1);
138 result->err = GSL_DBL_EPSILON * (N + 2.0) * fabs(result->val);
139 return GSL_ERROR_SELECT_2(stat_mu, stat_CF1);
142 /* Recurse backward from nu to mu, determining the J ratio
143 * at mu. Use this together with a Steed method CF2 to
144 * determine the actual J_mu, and thus obtain the normalization.
151 const int stat_CF2 = gsl_sf_bessel_JY_steed_CF2(mu, x, &P, &Q);
154 double Jnp1 = sgn_Jnu * GSL_SQRT_DBL_MIN * Jnup1_Jnu;
155 double Jn = sgn_Jnu * GSL_SQRT_DBL_MIN;
159 Jnm1 = 2.0*(mu+n)/x * Jn - Jnp1;
164 sgn_Jmu = GSL_SIGN(Jn);
165 Jmuprime_Jmu = mu/x - Jmup1_Jmu;
167 gamma = (P - Jmuprime_Jmu)/Q;
168 Jmu = sgn_Jmu * sqrt(2.0/(M_PI*x) / (Q + gamma*(P-Jmuprime_Jmu)));
170 result->val = Jmu * (sgn_Jnu * GSL_SQRT_DBL_MIN) / Jn;
171 result->err = 2.0 * GSL_DBL_EPSILON * (N + 2.0) * fabs(result->val);
173 return GSL_ERROR_SELECT_2(stat_CF2, stat_CF1);
178 /*-*-*-*-*-*-*-*-*-* Functions w/ Natural Prototypes *-*-*-*-*-*-*-*-*-*-*/
182 double gsl_sf_bessel_Jnu(const double nu, const double x)
184 EVAL_RESULT(gsl_sf_bessel_Jnu_e(nu, x, &result));