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

NAG AD Library Introduction
Example description
/* E02BB_P0W_F C++ Header Example Program.
 *
 * Copyright 2022 Numerical Algorithms Group.
 * Mark 28.6, 2022.
 */

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

int main()
{
  // Scalars
  int           exit_status = 0;
  const Integer m           = 7;

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

  // Data points and values.
  double x[m], y[m];

  x[0] = 0.0;
  x[1] = 0.2;
  x[2] = 0.4;
  x[3] = 0.6;
  x[4] = 0.75;
  x[5] = 0.9;
  x[6] = 1.0;

  for (int i = 0; i < m; i++)
  {
    y[i] = exp(x[i]);
  }

  // Call the passive routine
  const Integer     lck = m + 4, lwrk = 6 * m + 16;
  double            c[lck], lamda[lck], wrk[lwrk];
  Integer           ifail = 0;
  nag::ad::handle_t ad_handle;
  nag::ad::e01ba(ad_handle, m, x, y, lamda, c, lck, wrk, lwrk, ifail);

  // Evaluate computed spline using e02bb
  double xint = 0.5;
  double fit;

  ifail = 0;
  nag::ad::e02bb(ad_handle, lck, lamda, c, xint, fit, ifail);

  cout << "\n Value of fitted spline at x = " << xint;
  cout.precision(5);
  cout << " is: " << fit << endl;

  return exit_status;
}