Example: Matrix Formatting
A simple matrix is printed using the default format with the PrintMatrix class. The PrintMatrixFormat class is then used to change the default format.
import com.imsl.math.*;
import java.text.*;
public class PrintMatrixFormatEx1 {
public static void main(String args[]) {
double a[][] = {
{0., 1., 2., 3.},
{4., 5., 6., 7.},
{8., 9., 8., 1.},
{6., 3., 4., 3.}
};
// Construct a PrintMatrix object with a title
PrintMatrix p = new PrintMatrix("A Simple Matrix");
// Print the matrix
p.print(a);
// Turn row and column labels off
PrintMatrixFormat mf = new PrintMatrixFormat();
mf.setNoRowLabels();
mf.setNoColumnLabels();
// Print the matrix
p.print(mf, a);
}
}
Output
A Simple Matrix
0 1 2 3
0 0 1 2 3
1 4 5 6 7
2 8 9 8 1
3 6 3 4 3
A Simple Matrix
0 1 2 3
4 5 6 7
8 9 8 1
6 3 4 3
Link to Java source.