| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Each integration function requires a random number generator to be supplied, and returns an estimate of the integral and its standard deviation. The accuracy of the result is determined by the number of function calls specified by the user. If a known level of accuracy is required this can be achieved by calling the integrator several times and averaging the individual results until the desired accuracy is obtained.
Random sample points used within the Monte Carlo routines are always chosen strictly within the integration region, so that endpoint singularities are automatically avoided.
The function to be integrated has its own datatype, defined in the header file `gsl_monte.h'.
This data type defines a general function with parameters for Monte Carlo integration.
double (* function) (double * x, size_t dim, void * params)
size_t dim
void * params
f(x,y) = a x^2 + b x y + c y^2 |
gsl_monte_function F which you could pass to an
integrator:
struct my_f_params { double a; double b; double c; };
double
my_f (double x, size_t dim, void * p) {
struct my_f_params * fp = (struct my_f_params *)p;
if (dim != 2)
{
fprintf(stderr, "error: dim != 2");
abort();
}
return fp->a * x[0] * x[0]
+ fp->b * x[0] * x[1]
+ fp->c * x[1] * x[1];
}
gsl_monte_function F;
struct my_f_params params = { 3.0, 2.0, 1.0 };
F.function = &my_f;
F.dim = 2;
F.params = ¶ms;
|
#define GSL_MONTE_FN_EVAL(F,x)
(*((F)->function))(x,(F)->dim,(F)->params)
|
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |