3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough
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 struct fn_cauchy_params
22 gsl_function *function;
26 static double fn_cauchy (double t, void *params);
28 static void compute_moments (double cc, double *moment);
31 qc25c (gsl_function * f, double a, double b, double c,
32 double *result, double *abserr, int *err_reliable);
35 qc25c (gsl_function * f, double a, double b, double c,
36 double *result, double *abserr, int *err_reliable)
38 double cc = (2 * c - b - a) / (b - a);
42 double resabs, resasc;
44 gsl_function weighted_function;
45 struct fn_cauchy_params fn_params;
47 fn_params.function = f;
48 fn_params.singularity = c;
50 weighted_function.function = &fn_cauchy;
51 weighted_function.params = &fn_params;
53 gsl_integration_qk15 (&weighted_function, a, b, result, abserr,
56 if (*abserr == resasc)
69 double cheb12[13], cheb24[25], moment[25];
70 double res12 = 0, res24 = 0;
72 gsl_integration_qcheb (f, a, b, cheb12, cheb24);
73 compute_moments (cc, moment);
75 for (i = 0; i < 13; i++)
77 res12 += cheb12[i] * moment[i];
80 for (i = 0; i < 25; i++)
82 res24 += cheb24[i] * moment[i];
86 *abserr = fabs(res24 - res12) ;
94 fn_cauchy (double x, void *params)
96 struct fn_cauchy_params *p = (struct fn_cauchy_params *) params;
97 gsl_function *f = p->function;
98 double c = p->singularity;
99 return GSL_FN_EVAL (f, x) / (x - c);
103 compute_moments (double cc, double *moment)
107 double a0 = log (fabs ((1.0 - cc) / (1.0 + cc)));
108 double a1 = 2 + a0 * cc;
113 for (k = 2; k < 25; k++)
119 a2 = 2.0 * cc * a1 - a0;
123 const double km1 = k - 1.0;
124 a2 = 2.0 * cc * a1 - a0 - 4.0 / (km1 * km1 - 1.0);