Java Matrix Package

Download: java_matrix.zip

This is a Java implementation of a Matrix class. It is distributed as a package, so you need to add the package to your CLASSPATH. The file setup.bat will do this if the Jama-1.0.3.jar is in the current directory. Then you can compile and run the example.

Reference

JAMA: A Java Matrix Package

There is another Matrix class, which appears to be derived from the Jama package. It allows the use of formatted print and creating a Matrix from a one-dimenisonal array. See Java Matrix (2008)


Solve.java

import Jama.*; 

/** Example of use of Matrix Class **/

public class Solve {



   /** Shorten spelling of print. **/

   private static void print (String s) {
      System.out.print(s);
   }
   


   public static void main (String argv[]) {

     double a[][] = { {4, -2, 1}, {-3, -1, 4}, {1, -1, 3} };
     double v[][] = { {15}, {8}, {13}};
     Matrix A = new Matrix(a);
     print("A = ");
     A.print(8,1);
     Matrix b = new Matrix(v);
     print("b = ");
     b.print(8,1);
     Matrix x = A.solve(b);
     print("x = ");
     x.print(8,4);
     Matrix Residual = A.times(x).minus(b);
     double rnorm = Residual.normInf();
     print("residual = " + rnorm + "\n");
    }
}


Results

C:\ece595_06\math>java Solve
A =
       4.0      -2.0       1.0
      -3.0      -1.0       4.0
       1.0      -1.0       3.0

b =
      15.0
       8.0
      13.0

x =
    2.0000
   -2.0000
    3.0000

residual = 1.7763568394002505E-15


Maintained by John Loomis, updated Sun Sep 22 19:24:30 2013