1 /* specfunc/bessel_K1.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_exp.h>
26 #include <gsl/gsl_sf_bessel.h>
30 #include "chebyshev.h"
31 #include "cheb_eval.c"
33 /*-*-*-*-*-*-*-*-*-*-*-* Private Section *-*-*-*-*-*-*-*-*-*-*-*/
35 /* based on SLATEC besk1(), besk1e() */
37 /* chebyshev expansions
39 series for bk1 on the interval 0. to 4.00000d+00
40 with weighted error 7.02e-18
41 log weighted error 17.15
42 significant figures required 16.73
43 decimal places required 17.67
45 series for ak1 on the interval 1.25000d-01 to 5.00000d-01
46 with weighted error 6.06e-17
47 log weighted error 16.22
48 significant figures required 15.41
49 decimal places required 16.83
51 series for ak12 on the interval 0. to 1.25000d-01
52 with weighted error 2.58e-17
53 log weighted error 16.59
54 significant figures required 15.22
55 decimal places required 17.16
58 static double bk1_data[11] = {
59 0.0253002273389477705,
60 -0.3531559607765448760,
61 -0.1226111808226571480,
62 -0.0069757238596398643,
63 -0.0001730288957513052,
64 -0.0000024334061415659,
65 -0.0000000221338763073,
66 -0.0000000001411488392,
67 -0.0000000000006666901,
68 -0.0000000000000024274,
69 -0.0000000000000000070
72 static cheb_series bk1_cs = {
79 static double ak1_data[17] = {
98 static cheb_series ak1_cs = {
105 static double ak12_data[14] = {
108 -0.00024753706739052,
110 -0.00000020689392195,
112 -0.00000000055853361,
114 -0.00000000000282505,
116 -0.00000000000002176,
118 -0.00000000000000022,
121 static cheb_series ak12_cs = {
129 /*-*-*-*-*-*-*-*-*-*-*-* Functions with Error Codes *-*-*-*-*-*-*-*-*-*-*-*/
131 int gsl_sf_bessel_K1_scaled_e(const double x, gsl_sf_result * result)
133 /* CHECK_POINTER(result) */
136 DOMAIN_ERROR(result);
138 else if(x < 2.0*GSL_DBL_MIN) {
139 OVERFLOW_ERROR(result);
142 const double lx = log(x);
143 const double ex = exp(x);
147 cheb_eval_e(&bk1_cs, 0.5*x*x-1.0, &c);
148 stat_I1 = gsl_sf_bessel_I1_e(x, &I1);
149 result->val = ex * ((lx-M_LN2)*I1.val + (0.75 + c.val)/x);
150 result->err = ex * (c.err/x + fabs(lx)*I1.err);
151 result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
155 const double sx = sqrt(x);
157 cheb_eval_e(&ak1_cs, (16.0/x-5.0)/3.0, &c);
158 result->val = (1.25 + c.val) / sx;
159 result->err = c.err / sx;
160 result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
164 const double sx = sqrt(x);
166 cheb_eval_e(&ak12_cs, 16.0/x-1.0, &c);
167 result->val = (1.25 + c.val) / sx;
168 result->err = c.err / sx;
169 result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
175 int gsl_sf_bessel_K1_e(const double x, gsl_sf_result * result)
177 /* CHECK_POINTER(result) */
180 DOMAIN_ERROR(result);
182 else if(x < 2.0*GSL_DBL_MIN) {
183 OVERFLOW_ERROR(result);
186 const double lx = log(x);
190 cheb_eval_e(&bk1_cs, 0.5*x*x-1.0, &c);
191 stat_I1 = gsl_sf_bessel_I1_e(x, &I1);
192 result->val = (lx-M_LN2)*I1.val + (0.75 + c.val)/x;
193 result->err = c.err/x + fabs(lx)*I1.err;
194 result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
198 gsl_sf_result K1_scaled;
199 int stat_K1 = gsl_sf_bessel_K1_scaled_e(x, &K1_scaled);
200 int stat_e = gsl_sf_exp_mult_err_e(-x, 0.0,
201 K1_scaled.val, K1_scaled.err,
203 result->err = fabs(result->val) * (GSL_DBL_EPSILON*fabs(x) + K1_scaled.err/K1_scaled.val);
204 return GSL_ERROR_SELECT_2(stat_e, stat_K1);
208 /*-*-*-*-*-*-*-*-*-* Functions w/ Natural Prototypes *-*-*-*-*-*-*-*-*-*-*/
212 double gsl_sf_bessel_K1_scaled(const double x)
214 EVAL_RESULT(gsl_sf_bessel_K1_scaled_e(x, &result));
217 double gsl_sf_bessel_K1(const double x)
219 EVAL_RESULT(gsl_sf_bessel_K1_e(x, &result));