/* nag_1d_cheb_intg (e02ajc) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpout; /* Initialized data */ const double xmin = -0.5; const double xmax = 2.5; const double a[7] = { 2.53213, 1.13032, 0.2715, 0.04434, 0.00547, 5.4e-4, 4e-5 }; /* Scalars */ double ra, rb, result, xa, xb, zero; Integer exit_status, n, one; NagError fail; /* Arrays */ double *aint = 0; INIT_FAIL(fail); /* Check for command-line IO options */ fpout = nag_example_file_io(argc, argv, "-results", NULL); exit_status = 0; fprintf(fpout, "nag_1d_cheb_intg (e02ajc) Example Program Results\n"); n = 6; zero = 0.0; one = 1; /* Allocate memory */ if (!(aint = NAG_ALLOC(n + 2, double))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } /* nag_1d_cheb_intg (e02ajc). * Integral of fitted polynomial in Chebyshev series form */ nag_1d_cheb_intg(n, xmin, xmax, a, one, zero, aint, one, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_1d_cheb_intg (e02ajc).\n%s\n", fail.message); exit_status = 1; goto END; } xa = 0.0; xb = 2.0; /* nag_1d_cheb_eval2 (e02akc). * Evaluation of fitted polynomial in one variable from * Chebyshev series form */ nag_1d_cheb_eval2(n+1, xmin, xmax, aint, one, xa, &ra, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_1d_cheb_eval2 (e02akc).\n%s\n", fail.message); exit_status = 1; goto END; } /* nag_1d_cheb_eval2 (e02akc), see above. */ nag_1d_cheb_eval2(n+1, xmin, xmax, aint, one, xb, &rb, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_1d_cheb_eval2 (e02akc).\n%s\n", fail.message); exit_status = 1; goto END; } result = rb - ra; fprintf(fpout, "\n"); fprintf(fpout, "Value of definite integral is %10.4f\n", result); END: if (fpout != stdout) fclose(fpout); if (aint) NAG_FREE(aint); return exit_status; }