/* nag_1d_quad_brkpts_1 (d01slc) 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(double x, Nag_User *comm); #ifdef __cplusplus } #endif int main(void) { double a, b; double epsabs, abserr, epsrel, brkpts[1], result; Integer nbrkpts; Nag_QuadProgress qp; Integer max_num_subint; static NagError fail; Nag_User comm; Vprintf("nag_1d_quad_brkpts_1 (d01slc) Example Program Results\n"); nbrkpts = 1; epsabs = 0.0; epsrel = 0.001; a = 0.0; b = 1.0; max_num_subint = 200; brkpts[0] = 1.0/7.0; /* nag_1d_quad_brkpts_1 (d01slc). * One-dimensional adaptive quadrature, allowing for * singularities at specified points, thread-safe */ nag_1d_quad_brkpts_1(f, a, b, nbrkpts, brkpts, epsabs, epsrel, max_num_subint, &result, &abserr, &qp, &comm, &fail); Vprintf("a - lower limit of integration = %10.4f\n", a); Vprintf("b - upper limit of integration = %10.4f\n", b); Vprintf("epsabs - absolute accuracy requested = %9.2e\n", epsabs); Vprintf("epsrel - relative accuracy requested = %9.2e\n\n", epsrel); Vprintf("brkpts[0] - given break-point = %10.4f\n", brkpts[0]); if (fail.code != NE_NOERROR) Vprintf("%s\n", fail.message); if (fail.code != NE_INT_ARG_LT && fail.code != NE_2_INT_ARG_LE && fail.code != NE_ALLOC_FAIL && fail.code != NE_NO_LICENCE) { /* 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); } if (fail.code != NE_INT_ARG_LT && fail.code != NE_2_INT_ARG_LE && fail.code != NE_QUAD_BRKPTS_INVAL && fail.code != NE_ALLOC_FAIL) { Vprintf("result - approximation to the integral = %9.5f\n", result); Vprintf("abserr - estimate of the absolute error = %9.2e\n", abserr); Vprintf("qp.fun_count - number of function evaluations = %4ld\n", qp.fun_count); Vprintf("qp.num_subint - number of subintervals used = %4ld\n", qp.num_subint); return EXIT_SUCCESS; } return EXIT_FAILURE; } static double f(double x, Nag_User *comm) { double a; a = FABS(x-1.0/7.0); return (a != 0.0) ? pow(a, -0.5): 0.0; }