/* nag_1d_quad_wt_trig (d01anc) Example Program. * * Copyright 1991 Numerical Algorithms Group. * * Mark 2, 1991. * Mark 6 revised, 2000. * Mark 7 revised, 2001. */ #include #include #include #include #include #include #include #ifdef __cplusplus extern "C" { #endif static double NAG_CALL g(double x); #ifdef __cplusplus } #endif int main(int argc, char *argv[]) { FILE *fpout; Integer exit_status = 0; double a, b; double omega; double epsabs, abserr, epsrel, result; Nag_TrigTransform wt_func; Nag_QuadProgress qp; Integer max_num_subint; NagError fail; INIT_FAIL(fail); /* Check for command-line IO options */ fpout = nag_example_file_io(argc, argv, "-results", NULL); fprintf(fpout, "nag_1d_quad_wt_trig (d01anc) Example Program Results\n"); epsrel = 0.0001; epsabs = 0.0; a = 0.0; b = 1.0; /* nag_pi (x01aac). * pi */ omega = X01AAC * 10.0; wt_func = Nag_Sine; max_num_subint = 200; /* nag_1d_quad_wt_trig (d01anc). * One-dimensional adaptive quadrature, finite interval, * sine or cosine weight functions */ nag_1d_quad_wt_trig(g, a, b, omega, wt_func, epsabs, epsrel, max_num_subint, &result, &abserr, &qp, &fail); fprintf(fpout, "a - lower limit of integration = %9.4f\n", a); fprintf(fpout, "b - upper limit of integration = %9.4f\n", b); fprintf(fpout, "epsabs - absolute accuracy requested = %11.2e\n", epsabs); fprintf(fpout, "epsrel - relative accuracy requested = %11.2e\n\n", epsrel); if (fail.code != NE_NOERROR) fprintf(fpout, "Error from nag_1d_quad_wt_trig (d01anc) %s\n", fail.message); if (fail.code != NE_INT_ARG_LT && fail.code != NE_BAD_PARAM && fail.code != NE_ALLOC_FAIL && fail.code != NE_NO_LICENCE) { fprintf(fpout, "result - approximation to the integral = %10.5f\n", result); fprintf(fpout, "abserr - estimate of the absolute error = %11.2e\n", abserr); fprintf(fpout, "qp.fun_count - number of function evaluations = %4ld\n", qp.fun_count); fprintf(fpout, "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: if (fpout != stdout) fclose(fpout); return exit_status; } static double NAG_CALL g(double x) { return (x > 0.0)?log(x):0.0; }