/** TestMatmul: * simple class to test the matrix multiplikation */ public class TestMatrix { private SquareMatrix a, b, c; public TestMatrix(int n) { a = new SquareMatrix(n); b = new SquareMatrix(n); c = new SquareMatrix(n); // initialize a and b for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { a.set(i, j, i + j); b.set(i, j, i - j); } b.set(i, i, 1.0); } } public void run() { a.mult(b, c); } public void check() { int n = a.shape()[0]; double sp_th = n * (n + 1); double sp = c.trace(); double c12_th = (n * n * n - 7 * n + 9) / 3.0; double c12 = c.get(1, 2); System.out.println("trace (expected) : " + sp_th); System.out.println("trace : " + sp); System.out.println("c(1,2) (expected) : " + c12_th); System.out.println("c(1,2) : " + c12); } static public void main(String[] args) { TestMatrix tm = new TestMatrix(300); // initializes everything tm.run(); tm.check(); } }