NAG Library Manual, Mark 28.6
```/* F11BD_A1W_F C++ Header Example Program.
*
* Copyright 2022 Numerical Algorithms Group.
* Mark 28.6, 2022.
*/

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

int main()
{
int               exit_status = 0;
Integer           ifail = 0;

cout << "F11BD_A1W_F C++ Header Example Program Results\n\n";
// Skip heading in data file
string mystr;
getline(cin, mystr);

Integer n, m;
double  alphar;
cin >> n;
cin >> m;
cin >> alphar;

// Allocate arrays containing A and its factorized form, B
// and the solution X.
nagad_a1w_w_rtype *b = 0, *x = 0, *work = 0;
double *           dx;
Integer            lwork = 2 * m * n + 1000;

if (!(b = NAG_ALLOC(n, nagad_a1w_w_rtype)) ||
!(dx = NAG_ALLOC(2 * n, double)))
{
cout << "Allocation failure\n";
exit_status = -1;
exit(exit_status);
}

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

nagad_a1w_w_rtype alpha, bb, b1, a, c;
alpha = alphar;

b1 = 12.0;
a  = 1.0;
c  = 1.0;
bb = b1 - 2.0;

dco::ga1s<double>::global_tape->register_variable(alpha);
dco::ga1s<double>::global_tape->register_variable(bb);

// Create AD configuration data object
ifail = 0;

for (int i = 0; i < n; ++i)
{
b[i] = b1 * (i + 1);
x[i] = 3.0;
}
b[n - 1] = b[n - 1] - (n + 1);

b[0] = b[0] + (b1 - 1.0) * alpha;
for (int i = 1; i < n - 1; ++i)
{
b[i] = b[i] + b1 * alpha;
}
b[n - 1] = b[n - 1] + (b1 - 1.0) * alpha;

// Initialize rthe solver
Integer           iterm = 2, maxitn = 800, monit = 0, lwreq = lwork;
ifail                    = 0;
anorm, sigmax, monit, lwreq, work, lwork, ifail);

// Reverse communication call of solver
Integer           irevcm = 0;

while (irevcm != 4)
{
ifail = 0;
if (irevcm != 4)
{
ifail = -1;
if (irevcm == -1)
{
//  b = A^Tx
b[0] = bb * x[0] + a * x[1];
for (int i = 1; i < n - 1; ++i)
{
b[i] = c * x[i - 1] + bb * x[i] + a * x[i + 1];
}
b[n - 1] = c * x[n - 2] + bb * x[n - 1];
}
if (irevcm == 1)
{
// b = Ax
b[0] = bb * x[0] + c * x[1];
for (int i = 1; i < n - 1; ++i)
{
b[i] = a * x[i - 1] + bb * x[i] + c * x[i + 1];
}
b[n - 1] = a * x[n - 2] + bb * x[n - 1];
}
if (irevcm == 2)
{
for (int i = 0; i < n; ++i)
{
b[i] = x[i] / bb;
}
}
}
}

cout.setf(ios::scientific, ios::floatfield);
cout.precision(2);

cout << "  Solution vector   Residual vector\n";
for (int i = 0; i < n; ++i)
{
cout.width(12);
cout << dco::value(x[i]) << "     ";
cout.width(13);
cout << dco::value(b[i]) << endl;
}

cout << "\n\n Derivatives calculated: First order adjoints\n";
cout << " Computational mode    : algorithmic\n";
cout << "\n Derivatives of solution w.r.t alpha and bb:\n";

// Obtain derivatives
for (int i = 0; i < n; i++)
{

double inc = 1.0;
dco::derivative(x[i]) += inc;
ifail                                              = 0;
dco::ga1s<double>::global_tape->sparse_interpret() = true;

dx[i]     = dco::derivative(alpha);
dx[n + i] = dco::derivative(bb);
}
// Print derivatives
cout << endl;
NagError fail;
INIT_FAIL(fail);
x04cac(Nag_ColMajor, Nag_GeneralMatrix, Nag_NonUnitDiag, n, 2, dx, n,
"      d/dalpha    d/dbb", 0, &fail);

ifail = 0;

dco::ga1s<double>::tape_t::remove(dco::ga1s<double>::global_tape);

return exit_status;
}
```