/// Spherical Bessel functions. double bessel_jl(unsigned int n, double x) { gsl_sf_result result; int stat = gsl_sf_bessel_jl_e(static_cast<int>(n), x, &result); if (stat != GSL_SUCCESS) { std::ostringstream msg("Error in bessel_jl:"); msg << " n=" << n << " x=" << x; throw std::runtime_error(msg.str()); } else return result.val; }
int gsl_sf_bessel_jl_array(const int lmax, const double x, double * result_array) { /* CHECK_POINTER(result_array) */ if(lmax < 0 || x < 0.0) { int j; for(j=0; j<=lmax; j++) result_array[j] = 0.0; GSL_ERROR ("error", GSL_EDOM); } else if(x == 0.0) { int j; for(j=1; j<=lmax; j++) result_array[j] = 0.0; result_array[0] = 1.0; return GSL_SUCCESS; } else { gsl_sf_result r_jellp1; gsl_sf_result r_jell; int stat_0 = gsl_sf_bessel_jl_e(lmax+1, x, &r_jellp1); int stat_1 = gsl_sf_bessel_jl_e(lmax, x, &r_jell); double jellp1 = r_jellp1.val; double jell = r_jell.val; double jellm1; int ell; result_array[lmax] = jell; for(ell = lmax; ell >= 1; ell--) { jellm1 = -jellp1 + (2*ell + 1)/x * jell; jellp1 = jell; jell = jellm1; result_array[ell-1] = jellm1; } return GSL_ERROR_SELECT_2(stat_0, stat_1); } }
double gsl_sf_bessel_jl(const int l, const double x) { EVAL_RESULT(gsl_sf_bessel_jl_e(l, x, &result)); }