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.
22 gsl_function *function;
25 gsl_integration_qaws_table *table;
28 static double fn_qaws (double t, void *params);
29 static double fn_qaws_L (double x, void *params);
30 static double fn_qaws_R (double x, void *params);
33 compute_result (const double * r, const double * cheb12, const double * cheb24,
34 double * result12, double * result24);
38 qc25s (gsl_function * f, double a, double b, double a1, double b1,
39 gsl_integration_qaws_table * t,
40 double *result, double *abserr, int *err_reliable);
43 qc25s (gsl_function * f, double a, double b, double a1, double b1,
44 gsl_integration_qaws_table * t,
45 double *result, double *abserr, int *err_reliable)
47 gsl_function weighted_function;
48 struct fn_qaws_params fn_params;
50 fn_params.function = f;
55 weighted_function.params = &fn_params;
57 if (a1 == a && (t->alpha != 0.0 || t->mu != 0))
59 double cheb12[13], cheb24[25];
61 double factor = pow(0.5 * (b1 - a1), t->alpha + 1.0);
63 weighted_function.function = &fn_qaws_R;
65 gsl_integration_qcheb (&weighted_function, a1, b1, cheb12, cheb24);
69 double res12 = 0, res24 = 0;
72 compute_result (t->ri, cheb12, cheb24, &res12, &res24);
75 *abserr = fabs(u * (res24 - res12));
79 double res12a = 0, res24a = 0;
80 double res12b = 0, res24b = 0;
82 double u = factor * log(b1 - a1);
85 compute_result (t->ri, cheb12, cheb24, &res12a, &res24a);
86 compute_result (t->rg, cheb12, cheb24, &res12b, &res24b);
88 *result = u * res24a + v * res24b;
89 *abserr = fabs(u * (res24a - res12a)) + fabs(v * (res24b - res12b));
96 else if (b1 == b && (t->beta != 0.0 || t->nu != 0))
98 double cheb12[13], cheb24[25];
99 double factor = pow(0.5 * (b1 - a1), t->beta + 1.0);
101 weighted_function.function = &fn_qaws_L;
103 gsl_integration_qcheb (&weighted_function, a1, b1, cheb12, cheb24);
107 double res12 = 0, res24 = 0;
110 compute_result (t->rj, cheb12, cheb24, &res12, &res24);
113 *abserr = fabs(u * (res24 - res12));
117 double res12a = 0, res24a = 0;
118 double res12b = 0, res24b = 0;
120 double u = factor * log(b1 - a1);
123 compute_result (t->rj, cheb12, cheb24, &res12a, &res24a);
124 compute_result (t->rh, cheb12, cheb24, &res12b, &res24b);
126 *result = u * res24a + v * res24b;
127 *abserr = fabs(u * (res24a - res12a)) + fabs(v * (res24b - res12b));
136 double resabs, resasc;
138 weighted_function.function = &fn_qaws;
140 gsl_integration_qk15 (&weighted_function, a1, b1, result, abserr,
143 if (*abserr == resasc)
158 fn_qaws (double x, void *params)
160 struct fn_qaws_params *p = (struct fn_qaws_params *) params;
161 gsl_function *f = p->function;
162 gsl_integration_qaws_table *t = p->table;
167 factor *= pow(x - p->a, t->alpha);
170 factor *= pow(p->b - x, t->beta);
173 factor *= log(x - p->a);
176 factor *= log(p->b - x);
178 return factor * GSL_FN_EVAL (f, x);
182 fn_qaws_L (double x, void *params)
184 struct fn_qaws_params *p = (struct fn_qaws_params *) params;
185 gsl_function *f = p->function;
186 gsl_integration_qaws_table *t = p->table;
191 factor *= pow(x - p->a, t->alpha);
194 factor *= log(x - p->a);
196 return factor * GSL_FN_EVAL (f, x);
200 fn_qaws_R (double x, void *params)
202 struct fn_qaws_params *p = (struct fn_qaws_params *) params;
203 gsl_function *f = p->function;
204 gsl_integration_qaws_table *t = p->table;
209 factor *= pow(p->b - x, t->beta);
212 factor *= log(p->b - x);
214 return factor * GSL_FN_EVAL (f, x);
219 compute_result (const double * r, const double * cheb12, const double * cheb24,
220 double * result12, double * result24)
226 for (i = 0; i < 13; i++)
228 res12 += r[i] * cheb12[i];
231 for (i = 0; i < 25; i++)
233 res24 += r[i] * cheb24[i];