/* nag_sum_cheby_series (c06dcc) Example Program. * * Copyright 2011 Numerical Algorithms Group. * * Mark 23, 2011. */ #include #include #include int main(void) { /* Scalars */ Integer exit_status = 0, i, lx, n; double xmax, xmin; /* Arrays */ char sstr[30]; double *c = 0, *res = 0, *x = 0; /* NAG types */ Nag_Series s; NagError fail; INIT_FAIL(fail); printf("nag_sum_cheby_series (c06dcc) Example Program Results\n"); /* Skip heading in data file */ scanf("%*[^\n]"); scanf("%ld%*[^\n]%ld%*[^\n]", &n, &lx); if (!(c = NAG_ALLOC(n, double)) || !(res = NAG_ALLOC(lx, double)) || !(x = NAG_ALLOC(lx, double))) { printf("Allocation failure\n"); exit_status = -1; goto END; } for (i = 0; i < lx; i++) scanf("%lf", &x[i]); scanf("%*[^\n]"); scanf("%lf%lf%*[^\n]", &xmin, &xmax); scanf("%s%*[^\n]", sstr); /* * nag_enum_name_to_value (x04nac). * Converts NAG enum member name to value */ s = (Nag_Series) nag_enum_name_to_value(sstr); for (i = 0; i < n; i++) scanf("%lf", &c[i]); /* * nag_sum_cheby_series (c06dcc) * Evaluates a polynomial from its Chebyshev series representation. */ nag_sum_cheby_series(x,lx,xmin,xmax,c,n,s,res,&fail); if (fail.code != NE_NOERROR) { printf("Error from nag_sum_cheby_series (c06dcc).\n%s\n", fail.message); exit_status = 1; goto END; } printf("\n%8s%16s\n","x","sum at x"); for (i = 0; i < lx; i++) printf("%11.4f%13.4f\n", x[i], res[i]); END: if (c) NAG_FREE(c); if (res) NAG_FREE(res); if (x) NAG_FREE(x); return exit_status; }