/* F06PA_P0W_F C++ Header Example Program.
*
* Copyright 2024 Numerical Algorithms Group.
* Mark 30.0, 2024.
*/
#include <iostream>
#include <dco.hpp>
#include <math.h>
#include <nag.h>
#include <nagad.h>
#include <nagx04.h>
#include <stdio.h>
#include <string>
using namespace std;
int main()
{
int exit_status = 0;
nag::ad::handle_t ad_handle;
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;
}