/* nag_2d_cheb_eval (e02cbc) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. * Mark 7b revised, 2004. */ #include #include #include #include int main(void) { /* Scalars */ double x1, xm, xmax, xmin, y, ymax, ymin; Integer exit_status, i, j, k, l, m, n, ncoef, one; NagError fail; /* Arrays */ double *a = 0, *ff = 0, *x = 0; INIT_FAIL(fail); exit_status = 0; Vprintf("nag_2d_cheb_eval (e02cbc) Example Program Results\n"); /* Skip heading in data file */ Vscanf("%*[^\n] "); while (scanf("%ld%ld%ld%*[^\n] ", &n, &k, &l) != EOF) { /* Allocate array a */ ncoef = (k + 1) * (l + 1); if ( !(a = NAG_ALLOC(ncoef, double))) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } for (i = 0; i < ncoef; ++i) Vscanf("%lf", &a[i]); Vscanf("%*[^\n] "); Vscanf("%lf%lf%*[^\n] ", &ymin, &ymax); for (i = 0; i < n; ++i) { Vscanf("%lf%ld%lf%lf%lf%lf%*[^\n] ", &y, &m, &xmin, &xmax, &x1, &xm); /* Allocate arrays x and ff */ if ( !(x = NAG_ALLOC(m, double)) || !(ff = NAG_ALLOC(m, double)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } for (j = 0; j < m; ++j) x[j] = x1 + (xm - x1) * (double)j / (double)(m - 1); one = 1; /* nag_2d_cheb_eval (e02cbc). * Evaluation of fitted polynomial in two variables */ nag_2d_cheb_eval(one, m, k, l, x, xmin, xmax, y, ymin, ymax, ff, a, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_2d_cheb_eval (e02cbc).\n%s\n", fail.message); exit_status = 1; goto END; } Vprintf("\n"); Vprintf("y = %13.4e\n", y); Vprintf("\n"); Vprintf(" i x(i) Poly(x(i),y)\n"); for (j = 0; j < m; ++j) Vprintf("%3ld%13.4e%13.4e\n", j, x[j], ff[j]); if (ff) NAG_FREE(ff); if (x) NAG_FREE(x); } if (a) NAG_FREE(a); } END: if (a) NAG_FREE(a); if (ff) NAG_FREE(ff); if (x) NAG_FREE(x); return exit_status; }