/* G02AB_P0W_F C++ Header Example Program.
*
* Copyright 2020 Numerical Algorithms Group.
* Mark 27.1, 2020.
*/
#include <nagad.h>
#include <nag.h>
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
/* Scalars */
Integer exit_status = 0;
cout << "G02AB_P0W_F C++ Example Program Results\n\n";
void *ad_handle = 0;
Integer ifail = 0;
// Skip heading in data file
string mystr;
getline (cin, mystr);
// Inputs from data file
Integer n;
double alpha;
cin >> n;
cin >> mystr;
cin >> alpha;
Integer pdg = n;
Integer pdx = n;
double *g = 0, *w = 0, *x = 0;
g = new double [n * n];
w = new double [n];
x = new double [n * n];
/* Read in the matrix g */
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> g[i+j*n];
x[i+j*n] = 0.0;
}
}
/* Read in the vector w */
for (int i = 0; i < n; i++) {
cin >> w[i];
}
/* Use the defaults for errtol, maxits and maxit */
double errtol = 0.0;
Integer maxits = 0;
Integer maxit = 0;
double nrmgrd;
Integer feval, iter;
g02ab_p0w_f_(ad_handle, g, pdg, n, "B", alpha, w, errtol,
maxits, maxit, x, pdx, iter, feval,
nrmgrd, ifail, 1);
NagError fail;
INIT_FAIL(fail);
x04cac(Nag_ColMajor,Nag_GeneralMatrix,Nag_NonUnitDiag,n,n,x,n,
" Nearest Correlation Matrix",0,&fail);
cout.setf(ios::scientific,ios::floatfield);
cout.precision(3);
cout << endl;
cout << " Number of Newton steps taken : " << iter << "\n";
cout << " Number of function evaluations: " << feval << "\n";
cout << " alpha : " << alpha << endl;
delete [] g;
delete [] w;
delete [] x;
return exit_status;
}