NAG Library Manual, Mark 27.2
```/* D01GA_A1W_F C++ Header Example Program.
*
* Copyright 2021 Numerical Algorithms Group.
* Mark 27.2, 2021.
*/

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

int main(void)
{
// Scalars
int     exit_status = 0;
Integer n           = 21;
double  ar          = 1.0;

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

// Allocate memory
nagad_a1w_w_rtype *x = 0, *y = 0;

if (!(x = NAG_ALLOC(n, nagad_a1w_w_rtype)) ||
{
printf("Allocation failure\n");
exit_status = -2;
}

if (exit_status == 0)
{

dco::ga1s<double>::global_tape = dco::ga1s<double>::tape_t::create();

// Create AD configuration data object
Integer ifail     = 0;

/* Register variables to differentiate w.r.t. */
a = ar;
dco::ga1s<double>::global_tape->register_variable(a);

// Initialize variables
for (int i = 0; i < n; i++)
{
double            xr = (1.0 * i) / (1.0 * (n - 1));
x[i] = xr;
tmp  = a * x[i];
y[i] = 4.0 / (1.0 + tmp * tmp);
}

ifail = 0;

double inc = 1.0;
dco::derivative(ans) += inc;
dco::ga1s<double>::global_tape->sparse_interpret() = true;

cout << "\n Derivatives calculated: First order adjoints\n";
cout << " Computational mode    : algorithmic\n";

// Get derivative
double da;
da = dco::derivative(a);

cout.setf(ios::scientific, ios::floatfield);
cout.setf(ios::right);
cout.precision(4);
cout << "\n Solution, ans = ";
double ans_value = dco::value(ans);
cout.width(12);
cout << ans_value << endl;
cout << "\n Derivative:\n";
cout << " d(ans)/da = ";
cout.width(12);
cout << da << endl;

// Remove computational data object and tape