#include #include #include #include /* Do Monte Carlo integral of a function over distance (0,1) */ #include "mersenne.h" char usage[] = " usage: mc_integrate N N2\n\ Integrates function using N mc-hits, repeats N2 times\n\ Prints all results (with errors) to standard output\n"; /* Integration range from XMIN to XMAX */ #define XMIN 0.0 #define XMAX 1.0 /* the function to be integrated defined here */ double f(double x) { return(1.5 * (1.0 - x*x)); //return(1.0/sqrt(x)); //return ( pow( x, (-1.0/3.0) ) + 0.1*x ); //return( x*x ); } /* * This routine does one monte carlo integration. * Returns the mc-estimate of the value integral, and err * contains the estimate of the error. */ double mcint(int n, double *err) { register int i; register double s,s2,t; s = s2 = 0; for (i=0; i