/* nag_1d_ratnl_interp (e01rac) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include int main(void) { /* Scalars */ Integer exit_status, i, m, n; NagError fail; /* Arrays */ double *a = 0, *f = 0, *u = 0, *x = 0; exit_status = 0; INIT_FAIL(fail); Vprintf("nag_1d_ratnl_interp (e01rac) Example Program Results\n"); /* Skip heading in data file */ Vscanf("%*[^\n] "); n = 5; /* Allocate memory */ if ( !(a = NAG_ALLOC(n, double)) || !(f = NAG_ALLOC(n, double)) || !(u = NAG_ALLOC(n, double)) || !(x = NAG_ALLOC(n, double)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } for (i = 1; i <= n; ++i) Vscanf("%lf", &x[i-1]); Vscanf("%*[^\n] "); for (i = 1; i <= n; ++i) Vscanf("%lf", &f[i-1]); Vscanf("%*[^\n] "); /* nag_1d_ratnl_interp (e01rac). * Interpolating functions, rational interpolant, one * variable */ nag_1d_ratnl_interp(n, x, f, &m, a, u, &fail); Vprintf("\n"); Vprintf("The values of u[j] are\n"); for (i = 1; i <= m - 1; ++i) { Vprintf("%12.4e", u[i-1]); Vprintf(i%4 == 0 || i == m - 1 ? "\n" : " "); } Vprintf("\n"); Vprintf("The Thiele coefficients a[j] are\n"); for (i = 1; i <= m; ++i) { Vprintf("%12.4e", a[i-1]); Vprintf(i%4 == 0 || i == m ? "\n" : " "); } END: if (a) NAG_FREE(a); if (f) NAG_FREE(f); if (u) NAG_FREE(u); if (x) NAG_FREE(x); return exit_status; }