I am using the Armadillo linear algebra library to diagonalize matrices. I need to increase the number of digits displayed/written to a file at the end. According to Armadillo's reference, "arma::mat" will create a double matrix. So, I tried using std::setprecision from "iomanip", but it did not quite work. Here is a minimal code that captures the problem:
#include<iostream>
#include<armadillo>
#include<iomanip>
int main()
{
double Trace_A = 0.;
arma::mat A;
A = :arma::randu<arma::mat>(5,5);
Trace = arma::trace(A);
// Normal output
std::cout << "A = \n" <<A ;
std::cout << "Trace(A) = " << Trace_A << std::endl;
std::cout << "---------------------------------------------" << std::endl;
// Displaying more digits
std::cout << std::fixed << std::setprecision(15);
std::cout << "A = \n" << A;
std::cout << "Trace(A) = " << Trace_A << std::endl;
}
And, here is what I get:
A =
0.8402 0.1976 0.4774 0.9162 0.0163
0.3944 0.3352 0.6289 0.6357 0.2429
0.7831 0.7682 0.3648 0.7173 0.1372
0.7984 0.2778 0.5134 0.1416 0.8042
0.9116 0.5540 0.9522 0.6070 0.1567
Trace(A) = 1.83848
---------------------------------------------
A =
0.8402 0.1976 0.4774 0.9162 0.0163
0.3944 0.3352 0.6289 0.6357 0.2429
0.7831 0.7682 0.3648 0.7173 0.1372
0.7984 0.2778 0.5134 0.1416 0.8042
0.9116 0.5540 0.9522 0.6070 0.1567
Trace(A) = 1.838476590271330
Curiously, it works for the trace which is passed on to the double variable "Trace_A" but not for the matrix itself. Any idea what I am doing wrong here?