14 #include <gsl/gsl_math.h>
18 const double radius = 0.50124145262344534123412;
20 double f_test(
unsigned dim,
const double *x,
void *data)
28 for (i = 0; i < dim; ++i)
34 for (i = 0; i < dim; ++i)
40 for (i = 0; i < dim; ++i) {
41 double z = (1 - x[i]) / x[i];
43 scale *= M_2_SQRTPI / (x[i] * x[i]);
45 val = exp(-val) * scale;
58 static double S(
unsigned n)
63 val = 2 * pow(M_PI,
n * 0.5);
65 while (
n > 1) fact *= (
n -= 1);
69 val = (1 << (
n/2 + 1)) * pow(M_PI,
n/2);
70 while (
n > 2) fact *= (
n -= 2);
81 val = dim == 0 ? 1 :
S(dim) * pow(
radius * 0.5, dim) / dim;
85 for (i = 0; i < dim; ++i)
98 int main(
int argc,
char **argv)
101 double tol, val, err;
102 unsigned i, dim, maxEval;
104 dim = argc > 1 ? atoi(argv[1]) : 2;
105 tol = argc > 2 ? atof(argv[2]) : 1e-2;
107 maxEval = argc > 4 ? atoi(argv[4]) : 0;
109 xmin = (
double *) malloc(dim *
sizeof(
double));
110 xmax = (
double *) malloc(dim *
sizeof(
double));
111 for (i = 0; i < dim; ++i) {
116 printf(
"%u-dim integral, tolerance = %g, integrand = %d\n",
119 printf(
"integration val = %g, est. err = %g, true err = %g\n",
int adapt_integrate(integrand f, void *fdata, unsigned dim, const double *xmin, const double *xmax, unsigned maxEval, double reqAbsError, double reqRelError, double *val, double *estimated_error)
std::string printf(const char *format,...)
static double S(unsigned n)
int main(int argc, char **argv)
static double exact_integral(unsigned dim, const double *xmax)
double f_test(unsigned dim, const double *x, void *data)