|
Packit |
67cb25 |
/* specfunc/bessel_Jnu.c
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
* Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman, 2017 Konrad Griessinger
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
* This program is free software; you can redistribute it and/or modify
|
|
Packit |
67cb25 |
* it under the terms of the GNU General Public License as published by
|
|
Packit |
67cb25 |
* the Free Software Foundation; either version 3 of the License, or (at
|
|
Packit |
67cb25 |
* your option) any later version.
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
* This program is distributed in the hope that it will be useful, but
|
|
Packit |
67cb25 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
67cb25 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
67cb25 |
* General Public License for more details.
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
* You should have received a copy of the GNU General Public License
|
|
Packit |
67cb25 |
* along with this program; if not, write to the Free Software
|
|
Packit |
67cb25 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
Packit |
67cb25 |
*/
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
/* Author: G. Jungman */
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
#include <config.h>
|
|
Packit |
67cb25 |
#include <gsl/gsl_math.h>
|
|
Packit |
67cb25 |
#include <gsl/gsl_errno.h>
|
|
Packit |
67cb25 |
#include <gsl/gsl_sf_bessel.h>
|
|
Packit |
67cb25 |
#include <gsl/gsl_sf_sincos_pi.h>
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
#include "error.h"
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
#include "bessel.h"
|
|
Packit |
67cb25 |
#include "bessel_olver.h"
|
|
Packit |
67cb25 |
#include "bessel_temme.h"
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
/* Evaluate at large enough nu to apply asymptotic
|
|
Packit |
67cb25 |
* results and apply backward recurrence.
|
|
Packit |
67cb25 |
*/
|
|
Packit |
67cb25 |
#if 0
|
|
Packit |
67cb25 |
static
|
|
Packit |
67cb25 |
int
|
|
Packit |
67cb25 |
bessel_J_recur_asymp(const double nu, const double x,
|
|
Packit |
67cb25 |
gsl_sf_result * Jnu, gsl_sf_result * Jnup1)
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
const double nu_cut = 25.0;
|
|
Packit |
67cb25 |
int n;
|
|
Packit |
67cb25 |
int steps = ceil(nu_cut - nu) + 1;
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
gsl_sf_result r_Jnp1;
|
|
Packit |
67cb25 |
gsl_sf_result r_Jn;
|
|
Packit |
67cb25 |
int stat_O1 = gsl_sf_bessel_Jnu_asymp_Olver_e(nu + steps + 1.0, x, &r_Jnp1);
|
|
Packit |
67cb25 |
int stat_O2 = gsl_sf_bessel_Jnu_asymp_Olver_e(nu + steps, x, &r_Jn);
|
|
Packit |
67cb25 |
double r_fe = fabs(r_Jnp1.err/r_Jnp1.val) + fabs(r_Jn.err/r_Jn.val);
|
|
Packit |
67cb25 |
double Jnp1 = r_Jnp1.val;
|
|
Packit |
67cb25 |
double Jn = r_Jn.val;
|
|
Packit |
67cb25 |
double Jnm1;
|
|
Packit |
67cb25 |
double Jnp1_save;
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
for(n=steps; n>0; n--) {
|
|
Packit |
67cb25 |
Jnm1 = 2.0*(nu+n)/x * Jn - Jnp1;
|
|
Packit |
67cb25 |
Jnp1 = Jn;
|
|
Packit |
67cb25 |
Jnp1_save = Jn;
|
|
Packit |
67cb25 |
Jn = Jnm1;
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
Jnu->val = Jn;
|
|
Packit |
67cb25 |
Jnu->err = (r_fe + GSL_DBL_EPSILON * (steps + 1.0)) * fabs(Jn);
|
|
Packit |
67cb25 |
Jnup1->val = Jnp1_save;
|
|
Packit |
67cb25 |
Jnup1->err = (r_fe + GSL_DBL_EPSILON * (steps + 1.0)) * fabs(Jnp1_save);
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
return GSL_ERROR_SELECT_2(stat_O1, stat_O2);
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
#endif
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
/*-*-*-*-*-*-*-*-*-*-*-* Functions with Error Codes *-*-*-*-*-*-*-*-*-*-*-*/
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
int
|
|
Packit |
67cb25 |
gsl_sf_bessel_Jnupos_e(const double nu, const double x, gsl_sf_result * result)
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
/* CHECK_POINTER(result) */
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
if(x == 0.0) {
|
|
Packit |
67cb25 |
if(nu == 0.0) {
|
|
Packit |
67cb25 |
result->val = 1.0;
|
|
Packit |
67cb25 |
result->err = 0.0;
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
else {
|
|
Packit |
67cb25 |
result->val = 0.0;
|
|
Packit |
67cb25 |
result->err = 0.0;
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
return GSL_SUCCESS;
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
else if(x*x < 10.0*(nu+1.0)) {
|
|
Packit |
67cb25 |
return gsl_sf_bessel_IJ_taylor_e(nu, x, -1, 100, GSL_DBL_EPSILON, result);
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
else if(nu > 50.0) {
|
|
Packit |
67cb25 |
return gsl_sf_bessel_Jnu_asymp_Olver_e(nu, x, result);
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
else if(x > 1000.0)
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
/* We need this to avoid feeding large x to CF1; note that
|
|
Packit |
67cb25 |
* due to the above check, we know that n <= 50. See similar
|
|
Packit |
67cb25 |
* block in bessel_Jn.c.
|
|
Packit |
67cb25 |
*/
|
|
Packit |
67cb25 |
return gsl_sf_bessel_Jnu_asympx_e(nu, x, result);
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
else {
|
|
Packit |
67cb25 |
/* -1/2 <= mu <= 1/2 */
|
|
Packit |
67cb25 |
int N = (int)(nu + 0.5);
|
|
Packit |
67cb25 |
double mu = nu - N;
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
/* Determine the J ratio at nu.
|
|
Packit |
67cb25 |
*/
|
|
Packit |
67cb25 |
double Jnup1_Jnu;
|
|
Packit |
67cb25 |
double sgn_Jnu;
|
|
Packit |
67cb25 |
const int stat_CF1 = gsl_sf_bessel_J_CF1(nu, x, &Jnup1_Jnu, &sgn_Jnu);
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
if(x < 2.0) {
|
|
Packit |
67cb25 |
/* Determine Y_mu, Y_mup1 directly and recurse forward to nu.
|
|
Packit |
67cb25 |
* Then use the CF1 information to solve for J_nu and J_nup1.
|
|
Packit |
67cb25 |
*/
|
|
Packit |
67cb25 |
gsl_sf_result Y_mu, Y_mup1;
|
|
Packit |
67cb25 |
const int stat_mu = gsl_sf_bessel_Y_temme(mu, x, &Y_mu, &Y_mup1);
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
double Ynm1 = Y_mu.val;
|
|
Packit |
67cb25 |
double Yn = Y_mup1.val;
|
|
Packit |
67cb25 |
double Ynp1 = 0.0;
|
|
Packit |
67cb25 |
int n;
|
|
Packit |
67cb25 |
for(n=1; n
|
|
Packit |
67cb25 |
Ynp1 = 2.0*(mu+n)/x * Yn - Ynm1;
|
|
Packit |
67cb25 |
Ynm1 = Yn;
|
|
Packit |
67cb25 |
Yn = Ynp1;
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
result->val = 2.0/(M_PI*x) / (Jnup1_Jnu*Yn - Ynp1);
|
|
Packit |
67cb25 |
result->err = GSL_DBL_EPSILON * (N + 2.0) * fabs(result->val);
|
|
Packit |
67cb25 |
return GSL_ERROR_SELECT_2(stat_mu, stat_CF1);
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
else {
|
|
Packit |
67cb25 |
/* Recurse backward from nu to mu, determining the J ratio
|
|
Packit |
67cb25 |
* at mu. Use this together with a Steed method CF2 to
|
|
Packit |
67cb25 |
* determine the actual J_mu, and thus obtain the normalization.
|
|
Packit |
67cb25 |
*/
|
|
Packit |
67cb25 |
double Jmu;
|
|
Packit |
67cb25 |
double Jmup1_Jmu;
|
|
Packit |
67cb25 |
double sgn_Jmu;
|
|
Packit |
67cb25 |
double Jmuprime_Jmu;
|
|
Packit |
67cb25 |
double P, Q;
|
|
Packit |
67cb25 |
const int stat_CF2 = gsl_sf_bessel_JY_steed_CF2(mu, x, &P, &Q);
|
|
Packit |
67cb25 |
double gamma;
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
double Jnp1 = sgn_Jnu * GSL_SQRT_DBL_MIN * Jnup1_Jnu;
|
|
Packit |
67cb25 |
double Jn = sgn_Jnu * GSL_SQRT_DBL_MIN;
|
|
Packit |
67cb25 |
double Jnm1;
|
|
Packit |
67cb25 |
int n;
|
|
Packit |
67cb25 |
for(n=N; n>0; n--) {
|
|
Packit |
67cb25 |
Jnm1 = 2.0*(mu+n)/x * Jn - Jnp1;
|
|
Packit |
67cb25 |
Jnp1 = Jn;
|
|
Packit |
67cb25 |
Jn = Jnm1;
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
Jmup1_Jmu = Jnp1/Jn;
|
|
Packit |
67cb25 |
sgn_Jmu = GSL_SIGN(Jn);
|
|
Packit |
67cb25 |
Jmuprime_Jmu = mu/x - Jmup1_Jmu;
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
gamma = (P - Jmuprime_Jmu)/Q;
|
|
Packit |
67cb25 |
Jmu = sgn_Jmu * sqrt(2.0/(M_PI*x) / (Q + gamma*(P-Jmuprime_Jmu)));
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
result->val = Jmu * (sgn_Jnu * GSL_SQRT_DBL_MIN) / Jn;
|
|
Packit |
67cb25 |
result->err = 2.0 * GSL_DBL_EPSILON * (N + 2.0) * fabs(result->val);
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
return GSL_ERROR_SELECT_2(stat_CF2, stat_CF1);
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
int
|
|
Packit |
67cb25 |
gsl_sf_bessel_Jnu_e(const double nu, const double x, gsl_sf_result * result)
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
/* CHECK_POINTER(result) */
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
if(x <= 0.0) {
|
|
Packit |
67cb25 |
DOMAIN_ERROR(result);
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
else if (nu < 0.0) {
|
|
Packit |
67cb25 |
int Jstatus = gsl_sf_bessel_Jnupos_e(-nu, x, result);
|
|
Packit |
67cb25 |
double Jval = result->val;
|
|
Packit |
67cb25 |
double Jerr = result->err;
|
|
Packit |
67cb25 |
int Ystatus = gsl_sf_bessel_Ynupos_e(-nu, x, result);
|
|
Packit |
67cb25 |
double Yval = result->val;
|
|
Packit |
67cb25 |
double Yerr = result->err;
|
|
Packit |
67cb25 |
/* double s = sin(M_PI*nu), c = cos(M_PI*nu); */
|
|
Packit |
67cb25 |
int sinstatus = gsl_sf_sin_pi_e(nu, result);
|
|
Packit |
67cb25 |
double s = result->val;
|
|
Packit |
67cb25 |
double serr = result->err;
|
|
Packit |
67cb25 |
int cosstatus = gsl_sf_cos_pi_e(nu, result);
|
|
Packit |
67cb25 |
double c = result->val;
|
|
Packit |
67cb25 |
double cerr = result->err;
|
|
Packit |
67cb25 |
result->val = s*Yval + c*Jval;
|
|
Packit |
67cb25 |
result->err = fabs(c*Yerr) + fabs(s*Jerr) + fabs(cerr*Yval) + fabs(serr*Jval);
|
|
Packit |
67cb25 |
return GSL_ERROR_SELECT_4(Jstatus, Ystatus, sinstatus, cosstatus);
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
else return gsl_sf_bessel_Jnupos_e(nu, x, result);
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
/*-*-*-*-*-*-*-*-*-* Functions w/ Natural Prototypes *-*-*-*-*-*-*-*-*-*-*/
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
#include "eval.h"
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
double gsl_sf_bessel_Jnu(const double nu, const double x)
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
EVAL_RESULT(gsl_sf_bessel_Jnu_e(nu, x, &result));
|
|
Packit |
67cb25 |
}
|