package com.imsl.test.example.math; import com.imsl.math.*; /** *
* SparseMatrix Example 1: Computes the matrix product of two sparse * matrices.
* * The matrix product of two matrices in sparse format is computed using a * method from the SparseMatrix class. The one norm of the result is also * computed. The matrix and its norm are printed. ** See example {@link SuperLUEx1} for an explanation of the sparse format. *
* * @see Code * @see Output */ public class SparseMatrixEx1 { public static void main(String args[]) { SparseMatrix b = new SparseMatrix(6, 6); b.set(0, 0, 10.0); b.set(1, 1, 10.0); b.set(1, 2, -3.0); b.set(1, 3, -1.0); b.set(2, 2, 15.0); b.set(3, 0, -2.0); b.set(3, 3, 10.0); b.set(3, 4, -1.0); b.set(4, 0, -1.0); b.set(4, 3, -5.0); b.set(4, 4, 1.0); b.set(4, 5, -3.0); b.set(5, 0, -1.0); b.set(5, 1, -2.0); b.set(5, 5, 6.0); SparseMatrix c = new SparseMatrix(6, 3); c.set(0, 0, 5.0); c.set(1, 2, -3.0); c.set(2, 0, 1.0); c.set(2, 2, 7.0); c.set(3, 0, 2.0); c.set(4, 1, -5.0); c.set(4, 2, 2.0); c.set(5, 2, 4.0); SparseMatrix A = SparseMatrix.multiply(b, c); // Get the one norm of matrix A System.out.println("The 1-norm of the matrix is " + A.oneNorm()); SparseMatrix.SparseArray sa = A.toSparseArray(); // Print the matrix and its one norm System.out.println("row column value"); for (int i = 0; i < sa.numberOfRows; i++) { for (int j = 0; j < sa.index[i].length; j++) { int jj = sa.index[i][j]; System.out.println(" " + i + " " + jj + " " + sa.values[i][j]); } } } }