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

NAG AD Library Introduction
Example description
/* F06PA_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 <nagx04.h>
#include <stdio.h>
#include <string>
using namespace std;

int main(void)
{
  int     exit_status = 0;
  void *  ad_handle   = 0;
  Integer ifail       = 0;

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

  // Read problem size and number of right-hand-sides
  Integer m, n;
  cin >> m >> n;
  double alpha, beta;
  cin >> alpha >> beta;

  // Allocate arrays containing A and its factorized form, B
  // and the solution X.
  double *a = 0, *b = 0, *y = 0;
  a = new double[m * n];
  b = new double[m];
  y = new double[n];

  // Read the matrix A
  double dd;
  for (int i = 0; i < m; ++i)
    {
      for (int j = 0; j < n; ++j)
        {
          cin >> dd;
          Integer k = i + j * m;
          a[k]      = dd;
        }
    }
  for (int i = 0; i < m; ++i)
    {
      cin >> dd;
      b[i] = dd;
    }
  for (int i = 0; i < n; ++i)
    {
      y[i] = 1.0;
    }

  //  y = beta*y + alpha*A^T*b
  ifail = 0;
  nag::ad::f06pa(ad_handle, "T", m, n, alpha, a, m, b, 1, beta, y, 1, ifail);

  cout << endl;
  NagError fail;
  INIT_FAIL(fail);
  x04cac(Nag_ColMajor, Nag_GeneralMatrix, Nag_NonUnitDiag, n, 1, y, n,
         "  Array y after update", 0, &fail);

  delete[] a;
  delete[] b;
  delete[] y;

  return exit_status;
}