NAG Library Manual, Mark 27.2
Interfaces:  FL   CL   CPP   AD 

NAG AD Library Introduction
Example description
/* E01BE_P0W_F C++ Header Example Program.
 *
 * Copyright 2021 Numerical Algorithms Group.
 * Mark 27.2, 2021.
 */

#include <iostream>
#include <math.h>
#include <nag.h>
#include <nagad.h>
#include <stdio.h>
#include <string>
using namespace std;

int main(void)
{
  // Scalars
  int exit_status = 0;

  cout << "E01BE_P0W_F C++ Header Example Program Results\n\n";

  // Skip first line of data file
  string mystr;
  getline(cin, mystr);
  // Read number of data points
  Integer n;
  cin >> n;

  // Allocate arrays for data and interpolant
  double *x = 0, *f = 0, *d = 0;
  x = new double[n];
  f = new double[n];
  d = new double[n];

  // Read data variables
  for (int i = 0; i < n; i++)
    {
      cin >> x[i] >> f[i];
    }

  // Call the passive routine
  Integer ifail     = 0;
  void *  ad_handle = 0;
  nag::ad::e01be(ad_handle, n, x, f, d, ifail);

  const Integer m = 1;
  double        px[m], pf[m], pd[m];
  px[0] = 0.5 * (x[n / 2 - 1] + x[n / 2]);
  ifail = 0;
  nag::ad::e01bg(ad_handle, n, x, f, d, m, px, pf, pd, ifail);

  cout << "\n Value of interpolant at x = " << px[0];
  cout.precision(5);
  cout << " is: " << pf[0] << endl;

  delete[] x;
  delete[] f;
  delete[] d;
  return exit_status;
}