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 #include <gsl/gsl_math.h>
23 #include <gsl/gsl_integration.h>
26 /* This function computes the 12-th order and 24-th order Chebyshev
27 approximations to f(x) on [a,b] */
30 gsl_integration_qcheb (gsl_function * f, double a, double b, double *cheb12, double *cheb24)
33 double fval[25], v[12];
35 /* These are the values of cos(pi*k/24) for k=1..11 needed for the
36 Chebyshev expansion of f(x) */
38 const double x[11] = { 0.9914448613738104,
50 const double center = 0.5 * (b + a);
51 const double half_length = 0.5 * (b - a);
53 fval[0] = 0.5 * GSL_FN_EVAL (f, b);
54 fval[12] = GSL_FN_EVAL (f, center);
55 fval[24] = 0.5 * GSL_FN_EVAL (f, a);
57 for (i = 1; i < 12; i++)
59 const size_t j = 24 - i;
60 const double u = half_length * x[i-1];
61 fval[i] = GSL_FN_EVAL(f, center + u);
62 fval[j] = GSL_FN_EVAL(f, center - u);
65 for (i = 0; i < 12; i++)
67 const size_t j = 24 - i;
68 v[i] = fval[i] - fval[j];
69 fval[i] = fval[i] + fval[j];
73 const double alam1 = v[0] - v[8];
74 const double alam2 = x[5] * (v[2] - v[6] - v[10]);
76 cheb12[3] = alam1 + alam2;
77 cheb12[9] = alam1 - alam2;
81 const double alam1 = v[1] - v[7] - v[9];
82 const double alam2 = v[3] - v[5] - v[11];
84 const double alam = x[2] * alam1 + x[8] * alam2;
86 cheb24[3] = cheb12[3] + alam;
87 cheb24[21] = cheb12[3] - alam;
91 const double alam = x[8] * alam1 - x[2] * alam2;
92 cheb24[9] = cheb12[9] + alam;
93 cheb24[15] = cheb12[9] - alam;
98 const double part1 = x[3] * v[4];
99 const double part2 = x[7] * v[8];
100 const double part3 = x[5] * v[6];
103 const double alam1 = v[0] + part1 + part2;
104 const double alam2 = x[1] * v[2] + part3 + x[9] * v[10];
106 cheb12[1] = alam1 + alam2;
107 cheb12[11] = alam1 - alam2;
111 const double alam1 = v[0] - part1 + part2;
112 const double alam2 = x[9] * v[2] - part3 + x[1] * v[10];
113 cheb12[5] = alam1 + alam2;
114 cheb12[7] = alam1 - alam2;
119 const double alam = (x[0] * v[1] + x[2] * v[3] + x[4] * v[5]
120 + x[6] * v[7] + x[8] * v[9] + x[10] * v[11]);
121 cheb24[1] = cheb12[1] + alam;
122 cheb24[23] = cheb12[1] - alam;
126 const double alam = (x[10] * v[1] - x[8] * v[3] + x[6] * v[5]
127 - x[4] * v[7] + x[2] * v[9] - x[0] * v[11]);
128 cheb24[11] = cheb12[11] + alam;
129 cheb24[13] = cheb12[11] - alam;
133 const double alam = (x[4] * v[1] - x[8] * v[3] - x[0] * v[5]
134 - x[10] * v[7] + x[2] * v[9] + x[6] * v[11]);
135 cheb24[5] = cheb12[5] + alam;
136 cheb24[19] = cheb12[5] - alam;
140 const double alam = (x[6] * v[1] - x[2] * v[3] - x[10] * v[5]
141 + x[0] * v[7] - x[8] * v[9] - x[4] * v[11]);
142 cheb24[7] = cheb12[7] + alam;
143 cheb24[17] = cheb12[7] - alam;
146 for (i = 0; i < 6; i++)
148 const size_t j = 12 - i;
149 v[i] = fval[i] - fval[j];
150 fval[i] = fval[i] + fval[j];
154 const double alam1 = v[0] + x[7] * v[4];
155 const double alam2 = x[3] * v[2];
157 cheb12[2] = alam1 + alam2;
158 cheb12[10] = alam1 - alam2;
161 cheb12[6] = v[0] - v[4];
164 const double alam = x[1] * v[1] + x[5] * v[3] + x[9] * v[5];
165 cheb24[2] = cheb12[2] + alam;
166 cheb24[22] = cheb12[2] - alam;
170 const double alam = x[5] * (v[1] - v[3] - v[5]);
171 cheb24[6] = cheb12[6] + alam;
172 cheb24[18] = cheb12[6] - alam;
176 const double alam = x[9] * v[1] - x[5] * v[3] + x[1] * v[5];
177 cheb24[10] = cheb12[10] + alam;
178 cheb24[14] = cheb12[10] - alam;
181 for (i = 0; i < 3; i++)
183 const size_t j = 6 - i;
184 v[i] = fval[i] - fval[j];
185 fval[i] = fval[i] + fval[j];
188 cheb12[4] = v[0] + x[7] * v[2];
189 cheb12[8] = fval[0] - x[7] * fval[2];
192 const double alam = x[3] * v[1];
193 cheb24[4] = cheb12[4] + alam;
194 cheb24[20] = cheb12[4] - alam;
198 const double alam = x[7] * fval[1] - fval[3];
199 cheb24[8] = cheb12[8] + alam;
200 cheb24[16] = cheb12[8] - alam;
203 cheb12[0] = fval[0] + fval[2];
206 const double alam = fval[1] + fval[3];
207 cheb24[0] = cheb12[0] + alam;
208 cheb24[24] = cheb12[0] - alam;
211 cheb12[12] = v[0] - v[2];
212 cheb24[12] = cheb12[12];
214 for (i = 1; i < 12; i++)
216 cheb12[i] *= 1.0 / 6.0;
219 cheb12[0] *= 1.0 / 12.0;
220 cheb12[12] *= 1.0 / 12.0;
222 for (i = 1; i < 24; i++)
224 cheb24[i] *= 1.0 / 12.0;
227 cheb24[0] *= 1.0 / 24.0;
228 cheb24[24] *= 1.0 / 24.0;