I'm using apache-commons-math RealMatrix on my project to handle matrix operations, however I can't print it with proper formatting.
For every matrix i have so far it goes like this:
double coord[][] = new double[3][3];
coord[0][0] = 1d;
coord[0][1] = 0d;
coord[0][2] = 0d;
coord[1][0] = 2d;
coord[1][1] = 1d;
coord[1][2] = 1d;
coord[2][0] = 3d;
coord[2][1] = 2d;
coord[2][2] = 0d;
System.out.println("coordinates [nó, x, y]");
for(int co = 0 ; co < 3 ; co++){
for(int or = 0 ; or < 3 ; or++){
System.out.printf("%10.5f\t",coord[co][or]);
}
System.out.print("\n");
}
outputing:
coordinates [nó, x, y]
1,00000 0,00000 0,00000
2,00000 1,00000 1,00000
3,00000 2,00000 0,00000
But when i'm using RealMatrix to print, it only prints in string (as far as i could find by myself) like this:
double coord[][] = new double[3][3];
coord[0][0] = 1d;
coord[0][1] = 0d;
coord[0][2] = 0d;
coord[1][0] = 2d;
coord[1][1] = 1d;
coord[1][2] = 1d;
coord[2][0] = 3d;
coord[2][1] = 2d;
coord[2][2] = 0d;
RealMatrix m = MatrixUtils.createRealMatrix(coord);
System.out.println(m.toString());
outputing:
Array2DRowRealMatrix{{1.0,0.0,0.0},{2.0,1.0,1.0},{3.0,2.0,0.0}}
How can I get the same output as in the first case using RealMatrix? From the error messages I get when I try to do it by myself, it seems that if I can convert the realmatrix back to an array it would solve my problem, but I cant manage to do that either...
Edit 1: As I'm trying to solve this, I found that getting the results of my matrix operations in an array would be very helpful, or at least a way of reading specific values out of them.
Edit 2: Added Java tag