Example: Matrix and PrintMatrix
The 1 norm of a matrix is found using a method from the Matrix class. The matrix is printed using the PrintMatrix class.
import com.imsl.math.*;
public class MatrixEx1 {
public static void main(String args[]) {
double nrm1;
double a[][] = {
{0., 1., 2., 3.},
{4., 5., 6., 7.},
{8., 9., 8., 1.},
{6., 3., 4., 3.}
};
// Get the 1 norm of matrix a
nrm1 = Matrix.oneNorm(a);
// Construct a PrintMatrix object with a title
PrintMatrix p = new PrintMatrix("A Simple Matrix");
// Print the matrix and its 1 norm
p.print(a);
System.out.println("The 1 norm of the matrix is "+nrm1);
}
}
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
The 1 norm of the matrix is 20.0
Link to Java source.