/* nag_multid_quad_monte_carlo_1(d01xbc) Example Program * * Copyright 1998 Numerical Algorithms Group. * * Mark 5, 1998. * Mark 6 revised, 2000. * Mark 7 revised, 2001. * */ #include #include #include #include #include #ifdef __cplusplus extern "C" { #endif static double f(Integer ndim, double x[], Nag_User *comm); #ifdef __cplusplus } #endif #define NDIM 4 #define MAXCLS 20000 int main(void) { double a[4], b[4]; Integer k, mincls; double finest; double acc, eps; Integer ndim = NDIM; Integer maxcls = MAXCLS; static NagError fail; double *comm_arr = (double *)0; Nag_MCMethod method; Nag_Start cont; Nag_User comm; Vprintf("d01xbc Example Program Results\n"); for (k=0; k<4; ++k) { a[k] = 0.0; b[k] = 1.0; } eps = 0.01; mincls = 1000; method = Nag_ManyIterations; cont = Nag_Cold; d01xbc(ndim, f, method, cont, a, b, &mincls, maxcls, eps, &finest, &acc, &comm_arr, &comm, &fail); if (fail.code != NE_NOERROR) Vprintf("%s\n", fail.message); if (fail.code == NE_NOERROR || fail.code == NE_QUAD_MAX_INTEGRAND_EVAL) { Vprintf("Requested accuracy = %10.2e\n",eps); Vprintf("Estimated value = %10.5f\n", finest); Vprintf("Estimated accuracy = %10.2e\n", acc); Vprintf("Number of evaluations = %5ld\n", mincls); /* Free memory allocated internally */ NAG_FREE(comm_arr); return EXIT_SUCCESS; } else return EXIT_FAILURE; } static double f(Integer ndim, double x[], Nag_User *comm) { return x[0]*4.0*(x[2]*x[2])*exp(x[0]*2.0*x[2])/ ((x[1]+1.0+x[3])*(x[1]+1.0+x[3])); }