/* nag_monotonic_intg (e01bhc) Example Program. * * Copyright 1991 Numerical Algorithms Group. * * Mark 2, 1991. * Mark 8 revised, 2004. */ #include #include #include #include int main(void) { Integer exit_status = 0, n, r; NagError fail; double a, b, *d = 0, *f = 0, integral, *x = 0; INIT_FAIL(fail); printf("nag_monotonic_intg (e01bhc) Example Program Results\n"); scanf("%*[^\n]"); /* Skip heading in data file */ scanf("%ld", &n); if (n >= 2) { if (!(d = NAG_ALLOC(n, double)) || !(f = NAG_ALLOC(n, double)) || !(x = NAG_ALLOC(n, double))) { printf("Allocation failure\n"); exit_status = -1; goto END; } } else { printf("Invalid n.\n"); exit_status = 1; return exit_status; } for (r = 0; r < n; r++) scanf("%lf%lf%lf", &x[r], &f[r], &d[r]); printf(" Integral\n"); printf(" a b over (a,b)\n"); /* Read a, b pairs until end of file and compute * definite integrals. */ while (scanf("%lf%lf", &a, &b) != EOF) { /* nag_monotonic_intg (e01bhc). * Evaluation of interpolant computed by * nag_monotonic_interpolant (e01bec), definite integral */ nag_monotonic_intg(n, x, f, d, a, b, &integral, &fail); if (fail.code != NE_NOERROR) { printf("Error from nag_monotonic_intg (e01bhc).\n%s\n", fail.message); exit_status = 1; goto END; } printf("%13.4f %13.4f %13.4f\n", a, b, integral); } END: if (d) NAG_FREE(d); if (f) NAG_FREE(f); if (x) NAG_FREE(x); return exit_status; }