/* D01GA_P0W_F C++ Header Example Program.
*
* Copyright 2024 Numerical Algorithms Group.
* Mark 30.3, 2024.
*/
#include <iostream>
#include <dco.hpp>
#include <math.h>
#include <nag.h>
#include <nagad.h>
#include <stdio.h>
using namespace std;
int main()
{
// Scalars
int exit_status = 0;
Integer n = 21;
double a = 1.0;
cout << "D01GA_P0W_F C++ Header Example Program Results\n\n";
// Allocate memory
double *x = 0, *y = 0;
x = new double[n];
y = new double[n];
// Initialize variables
for (int i = 0; i < n; i++)
{
double xr = (1.0 * i) / (1.0 * (n - 1));
double tmp;
x[i] = xr;
tmp = a * x[i];
y[i] = 4.0 / (1.0 + tmp * tmp);
}
// Call the passive routine
Integer ifail = 0;
nag::ad::handle_t ad_handle;
double ans, er;
nag::ad::d01ga(ad_handle, x, y, n, ans, er, ifail);
cout.setf(ios::scientific, ios::floatfield);
cout.setf(ios::right);
cout.precision(4);
cout << "\n Solution, ans = ";
cout.width(12);
cout << ans << endl;
delete[] x;
delete[] y;
return exit_status;
}