/* nag_1d_cheb_eval (e02aec) Example Program. * * Copyright 1998 Numerical Algorithms Group. * * Mark 5, 1998. * Mark 8 revised, 2004. * */ #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; Integer exit_status = 0, i, m, n, r; NagError fail; double *a = 0, p, xcap; INIT_FAIL(fail); /* Check for command-line IO options */ fpin = nag_example_file_io(argc, argv, "-data", NULL); fpout = nag_example_file_io(argc, argv, "-results", NULL); fprintf(fpout, "nag_1d_cheb_eval (e02aec) Example Program Results \n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n]"); while ((fscanf(fpin, "%ld", &m) != EOF)) { if (m > 0) { fscanf(fpin, "%ld", &n); if (n >= 0) { if (!(a = NAG_ALLOC(n+1, double))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } } else { fprintf(fpout, "Invalid n.\n"); exit_status = 1; return exit_status; } for (i = 0; i < n+1; ++i) fscanf(fpin, "%lf", &a[i]); fprintf(fpout, "\n R Argument Value of polynomial \n"); for (r = 1; r <= m; ++r) { xcap = (double)(2*r - m - 1) / (double)(m - 1); /* nag_1d_cheb_eval (e02aec). * Evaluates the coefficients of a Chebyshev series * polynomial */ nag_1d_cheb_eval(n+1, a, xcap, &p, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_1d_cheb_eval (e02aec).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, " %3ld%14.4f %14.4f\n", r, xcap, p); } } END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (a) NAG_FREE(a); } return exit_status; }