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>
26 /* These are the test functions from table 4.1 of the QUADPACK book */
28 /* f1(x) = x^alpha * log(1/x) */
29 /* integ(f1,x,0,1) = 1/(alpha + 1)^2 */
31 double f1 (double x, void * params) {
32 double alpha = *(double *) params ;
33 return pow(x,alpha) * log(1/x) ;
36 /* f2(x) = 4^-alpha / ((x-pi/4)^2 + 16^-alpha) */
37 /* integ(f2,x,0,1) = arctan((4-pi)4^(alpha-1)) + arctan(pi 4^(alpha-1)) */
39 double f2 (double x, void * params) {
40 double alpha = *(double *) params ;
41 return pow(4.0,-alpha) / (pow((x-M_PI/4.0),2.0) + pow(16.0,-alpha)) ;
44 /* f3(x) = cos(2^alpha * sin(x)) */
45 /* integ(f3,x,0,pi) = pi J_0(2^alpha) */
47 double f3 (double x, void * params) {
48 double alpha = *(double *) params ;
49 return cos(pow(2.0,alpha) * sin(x)) ;
52 /* Functions 4, 5 and 6 are duplicates of functions 1, 2 and 3 */
55 /* f7(x) = |x - 1/3|^alpha */
56 /* integ(f7,x,0,1) = ((2/3)^(alpha+1) + (1/3)^(alpha+1))/(alpha + 1) */
58 double f7 (double x, void * params) {
59 double alpha = *(double *) params ;
60 return pow(fabs(x - (1.0/3.0)),alpha) ;
63 /* f8(x) = |x - pi/4|^alpha */
65 ((1 - pi/4)^(alpha+1) + (pi/4)^(alpha+1))/(alpha + 1) */
67 double f8 (double x, void * params) {
68 double alpha = *(double *) params ;
69 return pow(fabs(x - (M_PI/4.0)),alpha) ;
72 /* f9(x) = sqrt(1 - x^2) / (x + 1 + 2^-alpha) */
73 /* integ(f9,x,-1,1) = pi/sqrt((1+2^-alpha)^2-1) */
75 double f9 (double x, void * params) {
76 double alpha = *(double *) params ;
77 return 1 / ((x + 1 + pow(2.0,-alpha)) * sqrt(1-x*x)) ;
80 /* f10(x) = sin(x)^(alpha - 1) */
81 /* integ(f10,x,0,pi/2) = 2^(alpha-2) ((Gamma(alpha/2))^2)/Gamma(alpha) */
83 double f10 (double x, void * params) {
84 double alpha = *(double *) params ;
85 return pow(sin(x), alpha-1) ;
88 /* f11(x) = log(1/x)^(alpha - 1) */
89 /* integ(f11,x,0,1) = Gamma(alpha) */
91 double f11 (double x, void * params) {
92 double alpha = *(double *) params ;
93 return pow(log(1/x), alpha-1) ;
96 /* f12(x) = exp(20*(x-1)) * sin(2^alpha * x) */
98 (20 sin(2^alpha) - 2^alpha cos(2^alpha) + 2^alpha exp(-20))
101 double f12 (double x, void * params) {
102 double alpha = *(double *) params ;
103 return exp(20*(x-1)) * sin(pow(2.0,alpha) * x) ;
106 /* f13(x) = cos(2^alpha * x)/sqrt(x(1 - x)) */
107 /* integ(f13,x,0,1) = pi cos(2^(alpha-1)) J_0(2^(alpha-1)) */
109 double f13 (double x, void * params) {
110 double alpha = *(double *) params ;
111 return cos(pow(2.0,alpha)*x)/sqrt(x*(1-x)) ;
114 double f14 (double x, void * params) {
115 double alpha = *(double *) params ;
116 return exp(-pow(2.0,-alpha)*x)*cos(x)/sqrt(x) ;
119 double f15 (double x, void * params) {
120 double alpha = *(double *) params ;
121 return x*x * exp(-pow(2.0,-alpha)*x) ;
124 double f16 (double x, void * params) {
125 double alpha = *(double *) params ;
126 if (x==0 && alpha == 1) return 1 ; /* make the function continuous in x */
127 if (x==0 && alpha > 1) return 0 ; /* avoid problems with pow(0,1) */
128 return pow(x,alpha-1)/pow((1+10*x),2.0) ;
131 double f17 (double x, void * params) {
132 double alpha = *(double *) params ;
133 return pow(2.0,-alpha)/(((x-1)*(x-1)+pow(4.0,-alpha))*(x-2)) ;
136 /* f454(x) = x^3 log|(x^2-1)(x^2-2)| */
137 /* integ(f454,x,0,inf) = 61 log(2) + (77/4) log(7) - 27 */
139 double f454 (double x, void * params) {
143 return x3 * log(fabs((x2 - 1.0) * (x2 - 2.0))) ;
146 /* f455(x) = log(x)/(1+100*x^2) */
147 /* integ(f455,x,0,inf) = -log(10)/20 */
149 double f455 (double x, void * params) {
151 return log(x) / (1.0 + 100.0 * x * x) ;
154 /* f456(x) = log(x) */
155 /* integ(f456*sin(10 pi x),x,0,1) = -(gamma + log(10pi) - Ci(10pi))/(10pi) */
157 double f456 (double x, void * params) {
166 /* f457(x) = 1/sqrt(x) */
167 /* integ(f457*cos(pi x / 2),x,0,+inf) = 1 */
169 double f457 (double x, void * params) {
178 /* f458(x) = 1/(1 + log(x)^2)^2 */
179 /* integ(log(x) f458(x),x,0,1) = (Ci(1) sin(1) + (pi/2 - Si(1)) cos(1))/pi
182 double f458 (double x, void * params) {
192 double v = 1 + u * u;
194 return 1.0 / (v * v) ;
198 /* f459(x) = 1/(5 x^3 + 6) */
199 /* integ(f459/(x-0),x,-1,5) = log(125/631)/18 */
201 double f459 (double x, void * params) {
203 return 1.0 / (5.0 * x * x * x + 6.0) ;
206 /* myfn1(x) = exp(-x - x^2) */
207 /* integ(myfn1,x,-inf,inf) = sqrt(pi) exp(-1/4) */
209 double myfn1 (double x, void * params) {
211 return exp(-x - x*x) ;
214 /* myfn2(x) = exp(alpha*x) */
215 /* integ(myfn2,x,-inf,b) = exp(alpha*b)/alpha */
217 double myfn2 (double x, void * params) {
218 double alpha = *(double *) params ;
219 return exp(alpha*x) ;