/* nag_1d_quad_gen (d01ajc) Example Program. * * Copyright 1991 Numerical Algorithms Group. * * Mark 2, 1991. * Mark 6 revised, 2000. * Mark 7 revised, 2001. */ #include #include #include #include #include #include #ifdef __cplusplus extern "C" { #endif static double NAG_CALL f(double x); #ifdef __cplusplus } #endif int main(void) { Integer exit_status = 0; double a, b; double epsabs, abserr, epsrel, result; Nag_QuadProgress qp; Integer max_num_subint; NagError fail; /* nag_pi (x01aac). * pi */ double pi = nag_pi; INIT_FAIL(fail); printf("nag_1d_quad_gen (d01ajc) Example Program Results\n"); epsabs = 0.0; epsrel = 0.0001; a = 0.0; b = pi*2.0; max_num_subint = 200; /* nag_1d_quad_gen (d01ajc). * One-dimensional adaptive quadrature, allowing for badly * behaved integrands */ nag_1d_quad_gen(f, a, b, epsabs, epsrel, max_num_subint, &result, &abserr, &qp, &fail); printf("a - lower limit of integration = %9.4f\n", a); printf("b - upper limit of integration = %9.4f\n", b); printf("epsabs - absolute accuracy requested = %11.2e\n", epsabs); printf("epsrel - relative accuracy requested = %11.2e\n\n", epsrel); if (fail.code != NE_NOERROR) printf("Error from nag_1d_quad_gen (d01ajc) %s\n", fail.message); if (fail.code != NE_INT_ARG_LT && fail.code != NE_ALLOC_FAIL && fail.code != NE_NO_LICENCE) { printf("result - approximation to the integral = %10.5f\n", result); printf("abserr - estimate of the absolute error = %11.2e\n", abserr); printf("qp.fun_count - number of function evaluations = %4ld\n", qp.fun_count); printf("qp.num_subint - number of subintervals used = %4ld\n", qp.num_subint); /* Free memory used by qp */ NAG_FREE(qp.sub_int_beg_pts); NAG_FREE(qp.sub_int_end_pts); NAG_FREE(qp.sub_int_result); NAG_FREE(qp.sub_int_error); } else { exit_status = 1; goto END; } END: return exit_status; } static double NAG_CALL f(double x) { /* nag_pi (x01aac), see above. */ double pi = nag_pi; return(x*sin(x*30.0)/sqrt(1.0-x*x/(pi*pi*4.0))); }