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

NAG AD Library Introduction
Example description
/* E01AA_P0W_F C++ Header Example Program.
 *
 * Copyright 2024 Numerical Algorithms Group.
 * Mark 30.0, 2024.
 */

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

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

  cout << "E01AA_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, *a = 0, *b = 0, *c = 0;
  Integer n1, n2;
  n1 = n + 1;
  n2 = n * (n + 1) / 2;
  a  = new double[n1];
  b  = new double[n1];
  c  = new double[n2];

  cin >> x;

  for (int i = 0; i < n1; i++)
  {
    cin >> a[i];
  }
  for (int i = 0; i < n1; i++)
  {
    cin >> b[i];
  }

  // Call the passive routine
  Integer           ifail = 0;
  nag::ad::handle_t ad_handle;
  nag::ad::e01aa(ad_handle, a, b, c, n, x, ifail);

  cout.setf(ios::scientific, ios::floatfield);
  cout.precision(5);
  cout << "\n Interpolation point = ";
  cout.width(12);
  cout << x << endl;
  cout << "\n Function value at interpolation point = ";
  cout.width(12);
  cout << c[n2 - 1] << endl;

  delete[] a;
  delete[] b;
  delete[] c;
  return exit_status;
}