/* D01FC_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>
using namespace std;
extern "C"
{
static void NAG_CALL f(void *& ad_handle,
const Integer &ndim,
const double z[],
double & fz,
Integer iuser[],
double ruser[]);
}
int main(void)
{
// Scalars
int exit_status = 0;
Integer ndim = 4, maxpts = 4000, lenwrk = 100;
cout << "D01FC_P0W_F C++ Header Example Program Results\n\n";
// Allocate memory
double *a = 0, *b = 0, *work = 0;
a = new double[ndim];
b = new double[ndim];
work = new double[lenwrk];
// Initialize variables
for (int i = 0; i < ndim; i++)
{
a[i] = 0.0;
b[i] = 1.0;
}
Integer minpts = 0;
double eps = 0.0001;
double ruser[3];
ruser[0] = 4.0;
ruser[1] = 2.0;
ruser[2] = 1.0;
// Call the passive routine
void * ad_handle = 0;
Integer ifail = 0;
double finval, acc;
Integer iuser[1];
nag::ad::d01fc(ad_handle, ndim, a, b, minpts, maxpts, f, eps, acc, lenwrk,
work, finval, -1, iuser, -1, ruser, ifail);
cout.setf(ios::scientific, ios::floatfield);
cout.setf(ios::right);
cout.precision(4);
cout << "\n Solution, x = ";
cout.width(12);
cout << finval << endl;
delete[] a;
delete[] b;
delete[] work;
return exit_status;
}
static void NAG_CALL f(void *& ad_handle,
const Integer &ndim,
const double z[],
double & fz,
Integer iuser[],
double ruser[])
{
double f1, f2, f3;
f1 = ruser[0] * z[0] * z[2] * z[2];
f2 = ruser[1] * z[0] * z[2];
f2 = exp(f2);
f3 = ruser[2] + z[1] + z[3];
f3 = f3 * f3;
fz = f1 * f2 / f3;
return;
}