/* F07CA_P0W_F C++ Header Example Program.
*
* Copyright 2019 Numerical Algorithms Group.
* Mark 27, 2019.
*/
#include <nag.h>
#include <nagad.h>
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
int exit_status = 0;
void *ad_handle = 0;
Integer nrhs = 1, ifail = 0;
cout << "F07CA_P0W_F C++ Header Example Program Results\n\n";
// Skip heading in data file
string mystr;
getline (cin, mystr);
// Read number of x values
Integer n;
cin >> n;
// Allocate arrays containing A and its factorized form, B
// and the solution X.
double *dl=0, *d=0, *du=0, *x=0;
Integer n1 = n-1;
dl = new double [n1];
d = new double [n];
du = new double [n1];
x = new double [n];
// Read the tridiagonal matrix A and right hand side B, register and copy
double dd;
for (int i = 0; i<n1; i++) {
cin >> du[i];
}
for (int i = 0; i<n; i++) {
cin >> d[i];
}
for (int i = 0; i<n1; i++) {
cin >> dl[i];
}
for (int i = 0; i<n; i++) {
cin >> x[i];
}
// Solve the equations Ax = b for x
ifail = 0;
f07ca_p0w_f_(ad_handle,n,nrhs,dl,d,du,x,n,ifail);
// Print primal solution
cout << " Solution:\n";
cout.precision(4);
cout.width(12); cout << " ";
for (int i=0; i<n; i++) {
cout.width(10); cout << x[i];
}
delete [] dl;
delete [] d;
delete [] du;
delete [] x;
return exit_status;
}