/* nag_1d_quad_gauss (d01bac) Example Program. * * Copyright 1991 Numerical Algorithms Group. * * Mark 2, 1991. * Mark 7 revised, 2001. * */ #include #include #include #include #include #ifdef __cplusplus extern "C" { #endif static double fun1(double x); static double fun2(double x); static double fun3(double x); static double fun4(double x); #ifdef __cplusplus } #endif int main(void) { static Integer nstor[3] = {4, 8, 16}; double a, b; Integer i; static NagError fail; double ans; Nag_GaussFormulae gaussformula; Nag_Boolean success = Nag_TRUE; fail.print = Nag_TRUE; Vprintf("nag_1d_quad_gauss (d01bac) Example Program Results\n"); Vprintf("\nGauss-Legendre example\n\n"); for (i=0; i<3; ++i) { a = 0.0; b = 1.0; gaussformula = Nag_Legendre; /* nag_1d_quad_gauss (d01bac). * One-dimensional Gaussian quadrature rule evaluation */ ans = nag_1d_quad_gauss(gaussformula, fun1, a, b, nstor[i], &fail); if (fail.code == NE_NOERROR || fail.code == NE_QUAD_GAUSS_NPTS_RULE) Vprintf("%ld Points Answer = %10.5f\n\n", nstor[i], ans); else { Vprintf("%s\n", fail.message); success = Nag_FALSE; } } Vprintf("\nGauss-Rational example\n\n"); for (i=0; i<3; ++i) { a = 2.0; b = 0.0; gaussformula = Nag_Rational; /* nag_1d_quad_gauss (d01bac), see above. */ ans = nag_1d_quad_gauss(gaussformula, fun2, a, b, nstor[i], &fail); if (fail.code == NE_NOERROR || fail.code == NE_QUAD_GAUSS_NPTS_RULE) Vprintf("%ld Points Answer = %10.5f\n\n", nstor[i], ans); else { Vprintf("%s\n", fail.message); success = Nag_FALSE; } } Vprintf("\nGauss-Laguerre example\n\n"); for (i=0; i<3; ++i) { a = 2.0; b = 1.0; gaussformula = Nag_Laguerre; /* nag_1d_quad_gauss (d01bac), see above. */ ans = nag_1d_quad_gauss(gaussformula, fun3, a, b, nstor[i], &fail); if (fail.code == NE_NOERROR || fail.code == NE_QUAD_GAUSS_NPTS_RULE) Vprintf("%ld Points Answer = %10.5f\n\n", nstor[i], ans); else { Vprintf("%s\n", fail.message); success = Nag_FALSE; } } Vprintf("\nGauss-Hermite example\n\n"); for (i=0; i<3; ++i) { a = -1.0; b = 3.0; gaussformula = Nag_Hermite; /* nag_1d_quad_gauss (d01bac), see above. */ ans = nag_1d_quad_gauss(gaussformula, fun4, a, b, nstor[i], &fail); if (fail.code == NE_NOERROR || fail.code == NE_QUAD_GAUSS_NPTS_RULE) Vprintf("%ld Points Answer = %10.5f\n\n", nstor[i], ans); else { Vprintf("%s\n", fail.message); success = Nag_FALSE; } } if (success) return EXIT_SUCCESS; else return EXIT_FAILURE; } static double fun1(double x) { return 4.0/(x*x+1.0); } static double fun2(double x) { return 1.0/(x*x*log(x)); } static double fun3(double x) { return exp(-x)/x; } static double fun4(double x) { return exp(x*(-3.0)*x-x*4.0-1.0); }