/* nag_interp_dim1_ratnl (e01rac) Example Program.
*
* Copyright 2024 Numerical Algorithms Group.
*
* Mark 30.1, 2024.
*/
#include <nag.h>
#include <stdio.h>
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);
printf("nag_interp_dim1_ratnl (e01rac) Example Program Results\n");
/* Skip heading in data file */
scanf("%*[^\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))) {
printf("Allocation failure\n");
exit_status = -1;
goto END;
}
for (i = 1; i <= n; ++i)
scanf("%lf", &x[i - 1]);
scanf("%*[^\n] ");
for (i = 1; i <= n; ++i)
scanf("%lf", &f[i - 1]);
scanf("%*[^\n] ");
/* nag_interp_dim1_ratnl (e01rac).
* Interpolating functions, rational interpolant, one
* variable
*/
nag_interp_dim1_ratnl(n, x, f, &m, a, u, &fail);
if (fail.code != NE_NOERROR) {
exit_status = 1;
printf("Error from nag_interp_dim1_ratnl (e01rac).\n%s\n", fail.message);
goto END;
}
printf("\n");
printf("The values of u[j] are\n");
for (i = 1; i <= m - 1; ++i) {
printf("%13.4e", u[i - 1]);
printf(i % 4 == 0 || i == m - 1 ? "\n" : " ");
}
printf("\n");
printf("The Thiele coefficients a[j] are\n");
for (i = 1; i <= m; ++i) {
printf("%13.4e", a[i - 1]);
printf(i % 4 == 0 || i == m ? "\n" : " ");
}
END:
NAG_FREE(a);
NAG_FREE(f);
NAG_FREE(u);
NAG_FREE(x);
return exit_status;
}