int gsl_sf_bessel_Jn_array(int nmin, int nmax, double x, double * result_array) { /* CHECK_POINTER(result_array) */ if(nmin < 0 || nmax < nmin) { int n; for(n=nmax; n>=nmin; n--) { result_array[n-nmin] = 0.0; } GSL_ERROR ("domain error", GSL_EDOM); } else if(x == 0.0) { int n; for(n=nmax; n>=nmin; n--) { result_array[n-nmin] = 0.0; } if(nmin == 0) result_array[0] = 1.0; return GSL_SUCCESS; } else { gsl_sf_result r_Jnp1; gsl_sf_result r_Jn; int stat_np1 = gsl_sf_bessel_Jn_e(nmax+1, x, &r_Jnp1); int stat_n = gsl_sf_bessel_Jn_e(nmax, x, &r_Jn); int stat = GSL_ERROR_SELECT_2(stat_np1, stat_n); double Jnp1 = r_Jnp1.val; double Jn = r_Jn.val; double Jnm1; int n; if(stat == GSL_SUCCESS) { for(n=nmax; n>=nmin; n--) { result_array[n-nmin] = Jn; Jnm1 = -Jnp1 + 2.0*n/x * Jn; Jnp1 = Jn; Jn = Jnm1; } } else { for(n=nmax; n>=nmin; n--) { result_array[n-nmin] = 0.0; } } return stat; } }
int gsl_sf_legendre_Pl_e(const int l, const double x, gsl_sf_result * result) { /* CHECK_POINTER(result) */ if(l < 0 || x < -1.0 || x > 1.0) { DOMAIN_ERROR(result); } else if(l == 0) { result->val = 1.0; result->err = 0.0; return GSL_SUCCESS; } else if(l == 1) { result->val = x; result->err = 0.0; return GSL_SUCCESS; } else if(l == 2) { result->val = 0.5 * (3.0*x*x - 1.0); result->err = 3.0 * GSL_DBL_EPSILON * fabs(result->val); return GSL_SUCCESS; } else if(x == 1.0) { result->val = 1.0; result->err = 0.0; return GSL_SUCCESS; } else if(x == -1.0) { result->val = ( GSL_IS_ODD(l) ? -1.0 : 1.0 ); result->err = 0.0; return GSL_SUCCESS; } else if(l < 100000) { /* Compute by upward recurrence on l. */ double p_mm = 1.0; /* P_0(x) */ double p_mmp1 = x; /* P_1(x) */ double p_ell = p_mmp1; int ell; for(ell=2; ell <= l; ell++){ p_ell = (x*(2*ell-1)*p_mmp1 - (ell-1)*p_mm) / ell; p_mm = p_mmp1; p_mmp1 = p_ell; } result->val = p_ell; result->err = (0.5 * ell + 1.0) * GSL_DBL_EPSILON * fabs(p_ell); return GSL_SUCCESS; } else { /* Asymptotic expansion. * [Olver, p. 473] */ double u = l + 0.5; double th = acos(x); gsl_sf_result J0; gsl_sf_result Jm1; int stat_J0 = gsl_sf_bessel_J0_e(u*th, &J0); int stat_Jm1 = gsl_sf_bessel_Jn_e(-1, u*th, &Jm1); double pre; double B00; double c1; /* B00 = 1/8 (1 - th cot(th) / th^2 * pre = sqrt(th/sin(th)) */ if(th < GSL_ROOT4_DBL_EPSILON) { B00 = (1.0 + th*th/15.0)/24.0; pre = 1.0 + th*th/12.0; } else { double sin_th = sqrt(1.0 - x*x); double cot_th = x / sin_th; B00 = 1.0/8.0 * (1.0 - th * cot_th) / (th*th); pre = sqrt(th/sin_th); } c1 = th/u * B00; result->val = pre * (J0.val + c1 * Jm1.val); result->err = pre * (J0.err + fabs(c1) * Jm1.err); result->err += GSL_SQRT_DBL_EPSILON * fabs(result->val); return GSL_ERROR_SELECT_2(stat_J0, stat_Jm1); } }
double gsl_sf_bessel_Jn(const int n, const double x) { EVAL_RESULT(gsl_sf_bessel_Jn_e(n, x, &result)); }