| 1 |
/* specfunc/bessel_Ynu.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_bessel.h" |
| 26 |
|
| 27 |
#include "gsl_specfunc__error.h" |
| 28 |
|
| 29 |
#include "gsl_specfunc__bessel.h" |
| 30 |
#include "gsl_specfunc__bessel_olver.h" |
| 31 |
#include "gsl_specfunc__bessel_temme.h" |
| 32 |
|
| 33 |
/* Perform forward recurrence for Y_nu(x) and Y'_nu(x) |
| 34 |
* |
| 35 |
* Y_{nu+1} = nu/x Y_nu - Y'_nu |
| 36 |
* Y'_{nu+1} = -(nu+1)/x Y_{nu+1} + Y_nu |
| 37 |
*/ |
| 38 |
#if 0 |
| 39 |
static |
| 40 |
int |
| 41 |
bessel_Y_recur(const double nu_min, const double x, const int kmax, |
| 42 |
const double Y_start, const double Yp_start, |
| 43 |
double * Y_end, double * Yp_end) |
| 44 |
{ |
| 45 |
double x_inv = 1.0/x; |
| 46 |
double nu = nu_min; |
| 47 |
double Y_nu = Y_start; |
| 48 |
double Yp_nu = Yp_start; |
| 49 |
int k; |
| 50 |
|
| 51 |
for(k=1; k<=kmax; k++) { |
| 52 |
double nuox = nu*x_inv; |
| 53 |
double Y_nu_save = Y_nu; |
| 54 |
Y_nu = -Yp_nu + nuox * Y_nu; |
| 55 |
Yp_nu = Y_nu_save - (nuox+x_inv) * Y_nu; |
| 56 |
nu += 1.0; |
| 57 |
} |
| 58 |
*Y_end = Y_nu; |
| 59 |
*Yp_end = Yp_nu; |
| 60 |
return GSL_SUCCESS; |
| 61 |
} |
| 62 |
#endif |
| 63 |
|
| 64 |
|
| 65 |
/*-*-*-*-*-*-*-*-*-*-*-* Functions with Error Codes *-*-*-*-*-*-*-*-*-*-*-*/ |
| 66 |
|
| 67 |
int |
| 68 |
gsl_sf_bessel_Ynu_e(double nu, double x, gsl_sf_result * result) |
| 69 |
{ |
| 70 |
/* CHECK_POINTER(result) */ |
| 71 |
|
| 72 |
if(x <= 0.0 || nu < 0.0) { |
| 73 |
DOMAIN_ERROR(result); |
| 74 |
} |
| 75 |
else if(nu > 50.0) { |
| 76 |
return gsl_sf_bessel_Ynu_asymp_Olver_e(nu, x, result); |
| 77 |
} |
| 78 |
else { |
| 79 |
/* -1/2 <= mu <= 1/2 */ |
| 80 |
int N = (int)(nu + 0.5); |
| 81 |
double mu = nu - N; |
| 82 |
|
| 83 |
gsl_sf_result Y_mu, Y_mup1; |
| 84 |
int stat_mu; |
| 85 |
double Ynm1; |
| 86 |
double Yn; |
| 87 |
double Ynp1; |
| 88 |
int n; |
| 89 |
|
| 90 |
if(x < 2.0) { |
| 91 |
/* Determine Ymu, Ymup1 directly. This is really |
| 92 |
* an optimization since this case could as well |
| 93 |
* be handled by a call to gsl_sf_bessel_JY_mu_restricted(), |
| 94 |
* as below. |
| 95 |
*/ |
| 96 |
stat_mu = gsl_sf_bessel_Y_temme(mu, x, &Y_mu, &Y_mup1); |
| 97 |
} |
| 98 |
else { |
| 99 |
/* Determine Ymu, Ymup1 and Jmu, Jmup1. |
| 100 |
*/ |
| 101 |
gsl_sf_result J_mu, J_mup1; |
| 102 |
stat_mu = gsl_sf_bessel_JY_mu_restricted(mu, x, &J_mu, &J_mup1, &Y_mu, &Y_mup1); |
| 103 |
} |
| 104 |
|
| 105 |
/* Forward recursion to get Ynu, Ynup1. |
| 106 |
*/ |
| 107 |
Ynm1 = Y_mu.val; |
| 108 |
Yn = Y_mup1.val; |
| 109 |
for(n=1; n<=N; n++) { |
| 110 |
Ynp1 = 2.0*(mu+n)/x * Yn - Ynm1; |
| 111 |
Ynm1 = Yn; |
| 112 |
Yn = Ynp1; |
| 113 |
} |
| 114 |
|
| 115 |
result->val = Ynm1; /* Y_nu */ |
| 116 |
result->err = (N + 1.0) * fabs(Ynm1) * (fabs(Y_mu.err/Y_mu.val) + fabs(Y_mup1.err/Y_mup1.val)); |
| 117 |
result->err += 2.0 * GSL_DBL_EPSILON * fabs(Ynm1); |
| 118 |
|
| 119 |
return stat_mu; |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
/*-*-*-*-*-*-*-*-*-* Functions w/ Natural Prototypes *-*-*-*-*-*-*-*-*-*-*/ |
| 125 |
|
| 126 |
#include "gsl_specfunc__eval.h" |
| 127 |
|
| 128 |
double gsl_sf_bessel_Ynu(const double nu, const double x) |
| 129 |
{ |
| 130 |
EVAL_RESULT(gsl_sf_bessel_Ynu_e(nu, x, &result)); |
| 131 |
} |