1 /* specfunc/bessel_Yn.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_gamma.h>
26 #include <gsl/gsl_sf_psi.h>
27 #include <gsl/gsl_sf_bessel.h>
32 #include "bessel_amp_phase.h"
33 #include "bessel_olver.h"
35 /*-*-*-*-*-*-*-*-*-*-*-* Private Section *-*-*-*-*-*-*-*-*-*-*-*/
38 static int bessel_Yn_small_x(const int n, const double x, gsl_sf_result * result)
41 double y = 0.25 * x * x;
42 double ln_x_2 = log(0.5*x);
43 gsl_sf_result ln_nm1_fact;
45 double term1, sum1, ln_pre1;
46 double term2, sum2, pre2;
48 gsl_sf_lnfact_e((unsigned int)(n-1), &ln_nm1_fact);
50 ln_pre1 = -n*ln_x_2 + ln_nm1_fact.val;
51 if(ln_pre1 > GSL_LOG_DBL_MAX - 3.0) GSL_ERROR ("error", GSL_EOVRFLW);
55 for(k=1; k<=n-1; k++) {
56 k_term *= y/(k * (n-k));
59 term1 = -exp(ln_pre1) * sum1 / M_PI;
61 pre2 = -exp(n*ln_x_2) / M_PI;
62 if(fabs(pre2) > 0.0) {
65 gsl_sf_result npk_fact;
68 double psi_kp1 = -M_EULER;
70 gsl_sf_psi_int_e(n, &psi_n);
71 gsl_sf_fact_e((unsigned int)n, &npk_fact);
72 psi_npkp1 = psi_n.val + 1.0/n;
73 sum2 = (psi_kp1 + psi_npkp1 - 2.0*ln_x_2)/npk_fact.val;
74 for(k=1; k<KMAX; k++) {
76 psi_npkp1 += 1./(n+k);
80 k_term = yk*(psi_kp1 + psi_npkp1 - 2.0*ln_x_2)/(k_fact*npk_fact.val);
89 result->val = term1 + term2;
90 result->err = GSL_DBL_EPSILON * (fabs(ln_pre1)*fabs(term1) + fabs(term2));
91 result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
97 /*-*-*-*-*-*-*-*-*-*-*-* Functions with Error Codes *-*-*-*-*-*-*-*-*-*-*-*/
101 gsl_sf_bessel_Yn_e(int n, const double x, gsl_sf_result * result)
106 /* reduce to case n >= 0 */
108 if(GSL_IS_ODD(n)) sign = -1;
111 /* CHECK_POINTER(result) */
114 int status = gsl_sf_bessel_Y0_e(x, result);
119 int status = gsl_sf_bessel_Y1_e(x, result);
125 DOMAIN_ERROR(result);
128 int status = bessel_Yn_small_x(n, x, result);
132 else if(GSL_ROOT3_DBL_EPSILON * x > (n*n + 1.0)) {
133 int status = gsl_sf_bessel_Ynu_asympx_e((double)n, x, result);
138 int status = gsl_sf_bessel_Ynu_asymp_Olver_e((double)n, x, result);
143 double two_over_x = 2.0/x;
146 int stat_1 = gsl_sf_bessel_Y1_e(x, &r_by);
147 int stat_0 = gsl_sf_bessel_Y0_e(x, &r_bym);
148 double bym = r_bym.val;
149 double by = r_by.val;
154 byp = j*two_over_x*by - bym;
158 result->val = sign * by;
159 result->err = fabs(result->val) * (fabs(r_by.err/r_by.val) + fabs(r_bym.err/r_bym.val));
160 result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
162 return GSL_ERROR_SELECT_2(stat_1, stat_0);
169 gsl_sf_bessel_Yn_array(const int nmin, const int nmax, const double x, double * result_array)
171 /* CHECK_POINTER(result_array) */
173 if(nmin < 0 || nmax < nmin || x <= 0.0) {
175 for(j=0; j<=nmax-nmin; j++) result_array[j] = 0.0;
176 GSL_ERROR ("error", GSL_EDOM);
179 gsl_sf_result r_Ynm1;
181 int stat_nm1 = gsl_sf_bessel_Yn_e(nmin, x, &r_Ynm1);
182 int stat_n = gsl_sf_bessel_Yn_e(nmin+1, x, &r_Yn);
184 double Yn = r_Yn.val;
185 double Ynm1 = r_Ynm1.val;
188 int stat = GSL_ERROR_SELECT_2(stat_nm1, stat_n);
190 if(stat == GSL_SUCCESS) {
191 for(n=nmin+1; n<=nmax+1; n++) {
192 result_array[n-nmin-1] = Ynm1;
193 Ynp1 = -Ynm1 + 2.0*n/x * Yn;
199 for(n=nmin; n<=nmax; n++) {
200 result_array[n-nmin] = 0.0;
209 /*-*-*-*-*-*-*-*-*-* Functions w/ Natural Prototypes *-*-*-*-*-*-*-*-*-*-*/
213 double gsl_sf_bessel_Yn(const int n, const double x)
215 EVAL_RESULT(gsl_sf_bessel_Yn_e(n, x, &result));