/* nag_fit_dim1_cheb_integ (e02ajc) Example Program.
*
* Copyright 2022 Numerical Algorithms Group.
*
* Mark 28.6, 2022.
*/
#include <nag.h>
#include <stdio.h>
int main(void) {
/* Initialized data */
const double xmin = -0.5;
const double xmax = 2.5;
const double a[7] = {2.53213, 1.13032, 0.2715, 0.04434,
0.00547, 5.4e-4, 4e-5};
/* Scalars */
double ra, rb, result, xa, xb, zero;
Integer exit_status, n, one;
NagError fail;
/* Arrays */
double *aint = 0;
INIT_FAIL(fail);
exit_status = 0;
printf("nag_fit_dim1_cheb_integ (e02ajc) Example Program Results\n");
n = 6;
zero = 0.0;
one = 1;
/* Allocate memory */
if (!(aint = NAG_ALLOC(n + 2, double))) {
printf("Allocation failure\n");
exit_status = -1;
goto END;
}
/* nag_fit_dim1_cheb_integ (e02ajc).
* Integral of fitted polynomial in Chebyshev series form
*/
nag_fit_dim1_cheb_integ(n, xmin, xmax, a, one, zero, aint, one, &fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_fit_dim1_cheb_integ (e02ajc).\n%s\n", fail.message);
exit_status = 1;
goto END;
}
xa = 0.0;
xb = 2.0;
/* nag_fit_dim1_cheb_eval2 (e02akc).
* Evaluation of fitted polynomial in one variable from
* Chebyshev series form
*/
nag_fit_dim1_cheb_eval2(n + 1, xmin, xmax, aint, one, xa, &ra, &fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_fit_dim1_cheb_eval2 (e02akc).\n%s\n", fail.message);
exit_status = 1;
goto END;
}
/* nag_fit_dim1_cheb_eval2 (e02akc), see above. */
nag_fit_dim1_cheb_eval2(n + 1, xmin, xmax, aint, one, xb, &rb, &fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_fit_dim1_cheb_eval2 (e02akc).\n%s\n", fail.message);
exit_status = 1;
goto END;
}
result = rb - ra;
printf("\n");
printf("Value of definite integral is %10.4f\n", result);
END:
NAG_FREE(aint);
return exit_status;
}