/* nag_5d_shep_interp (e01tmc) Example Program. * * Copyright 2011 Numerical Algorithms Group. * * Mark 23, 2010. */ #include #include #include #include #define X(I, J) x[I *5 + J] #define XE(I, J) xe[I *5 + J] int main(void) { /* Scalars */ Integer exit_status, i, j, m, n, nq, nw, liq, lrq; NagError fail; /* Arrays */ double *f = 0, *q = 0, *qx = 0, *rq = 0, *xe = 0, *x = 0; Integer *iq = 0; exit_status = 0; INIT_FAIL(fail); printf("nag_5d_shep_interp (e01tmc) Example Program Results\n"); /* Skip heading in data file */ scanf("%*[^\n] "); /* Input the number of nodes. */ scanf("%ld%*[^\n] ", &m); /* Allocate memory */ lrq = 21 * m + 11; liq = 2 * m + 1; if (!(f = NAG_ALLOC(m, double)) || !(x = NAG_ALLOC(m*5, double)) || !(rq = NAG_ALLOC(lrq, double)) || !(iq = NAG_ALLOC(liq, Integer))) { printf("Allocation failure\n"); exit_status = -1; goto END; } /* Input the data points X and F. */ for (i = 0; i < m; ++i) { for (j = 0; j < 5; ++j) { scanf("%lf", &X(i, j)); } scanf("%lf%*[^\n] ", &f[i]); } /* Generate the interpolant. */ nq = 0; nw = 0; /* nag_5d_shep_interp (e01tmc). * Interpolating functions, modified Shepard's method, five * variables */ nag_5d_shep_interp(m, x, f, nw, nq, iq, rq, &fail); if (fail.code != NE_NOERROR) { printf("Error from nag_5d_shep_interp (e01tmc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Input the number of evaluation points. */ scanf("%ld%*[^\n] ", &n); /* Allocate memory for nag_5d_shep_eval (e01tnc) */ if (!(q = NAG_ALLOC(n, double)) || !(qx = NAG_ALLOC(n*5, double)) || !(xe = NAG_ALLOC(n*5, double))) { printf("Allocation failure\n"); exit_status = -1; goto END; } /* Input the evaluation points. */ for (i = 0; i < n; ++i) { for (j = 0; j < 5; ++j) { scanf("%lf", &XE(i, j)); } scanf("%*[^\n] "); } /* nag_5d_shep_eval (e01tnc). * Evaluate interpolant and first derivatives computed by * nag_5d_shep_interp (e01tmc). */ fail.print = Nag_TRUE; nag_5d_shep_eval(m, x, f, iq, rq, n, xe, q, qx, &fail); if (fail.code != NE_NOERROR) { printf("Error from nag_5d_shep_eval (e01tnc).\n%s\n", fail.message); exit_status = 1; goto END; } printf("\n Evaluation of interpolant at various (5D) points\n"); printf("\n%6s%30s%17s\n"," pt.no.","point coordinates","value"); for (i = 0; i < n; ++i) printf("%5ld%8.2f%8.2f%8.2f%8.2f%8.2f%10.4f\n", i, XE(i,0), XE(i,1), XE(i,2), XE(i,3), XE(i,4), q[i]); END: if (f) NAG_FREE(f); if (q) NAG_FREE(q); if (qx) NAG_FREE(qx); if (rq) NAG_FREE(rq); if (xe) NAG_FREE(xe); if (x) NAG_FREE(x); if (iq) NAG_FREE(iq); return exit_status; }