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

NAG AD Library Introduction
Example description
/* E04AB_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;

static void NAG_CALL funct(void *&       ad_handle,
                           const double &xc,
                           double &      fc,
                           Integer       iuser[],
                           double        ruser[])
{
  fc = sin(ruser[0] * xc) / xc;
}

/* funct */

int main(void)
{
  Integer exit_status = 0, max_fun;
  double  a, b, e1, e2, f, x;
  double  ruser[1];
  Integer iuser[1];

  printf("E04AB_P0W_F C++ Header Example Program Results\n\n");

  // For communication with user-supplied functions:
  ruser[0] = 1.0;
  // e1 and e2 are set to zero so that nag_opt_one_var_func (e04abc) will
  // reset them to their default values.
  e1 = 0.0;
  e2 = 0.0;
  // The minimum is known to lie in the range (3.5, 5.0)
  a = 3.5;
  b = 5.0;
  // Allow 30 calls of funct
  max_fun = 30;

  Integer ifail     = 0;
  void *  ad_handle = 0;
  nag::ad::e04ab(ad_handle, funct, e1, e2, a, b, max_fun, x, f, -1, iuser, -1,
                 ruser, ifail);

  cout << "The minimum lies in the interval " << a << " to " << b << endl;
  cout << "Its estimated position is        " << x << endl;
  cout << "where the function value is      " << f << endl;
  cout << max_fun << " function evaluations were required." << endl;

  return exit_status;
}