Using jMatrices


  White Paper
  Java Doc


Using jMatrices as a Library
Using jMatrices as a Shell

Using jMatrices as a Library

  1. Matrix objects can be created using static methods in the class org.jmatrices.dbl.MatrixFactory. Please check the javadocs for further details.
  2. If you have an empty matrix you can set element values using the only set method in the Matrix interface.
  3. Once you have an appropriate matrix(-ices), you are ready to perform operations on it(them).
  4. To perform an operation you have to first decide which of the following patterns your intended operation fits. Operation patterns fit one of the following patterns
    1. [measure] A -> s ,where A is a matrix and s is a scalar(number) or boolean.
      Examples include, rank, determinant, isSquare, isIdempotent, sum, mean, isDiagonal etc.
    2. [transform] A -> B, where a matrix A is transformed into another matrix B.
      Examples include transpose, inverse, element-by-element operations
    3. [row column transform] A -> V, where A is transformed into a Row or Column vector V.
      Examples include sum, product, mean of rows or columns
    4. [operate] A,B -> C where given two matrices A and B, we operate on them to get a matrix C.
      Examples include solving, matrix addition, multiplication, subtraction, element-by-element multiplication etc.
    5. [decompose] A -> C,D,..,s,r,t... where C,D,.. are matrices and s,r,t are scalars.
      Examples include LU, SVD, QR, Eigenvalue and Cholesky decompositions
  5. Once you have decided on what type of an operation you are interested in, you can check out the corresponding package as indicated by the following table
        operation type package
      a. [measure] org.jmatrices.dbl.measure
      b. [transform] org.jmatrices.dbl.transformer
      c. [row column transform] org.jmatrices.dbl.rowcoltr
      d. [operate] org.jmatrices.dbl.operator
      e. [decompose] org.jmatrices.dbl.decomposition
  6. Now you are on your own .. Have fun exploring!

Example code listing... [download]

Using jMatrices as a Shell

Shell is a JavaScript console that allows interactive usage of the library in the spirit of mathematical products like Matlab and Gauss. Right now syntax supporting Matlab, is available. Gauss will be implemented in the next release or so.

To the start the shell, in the console, type

java -jar jmatrices_shell_0_6.jar

This of course assumes that java VM is installed and accessible from where the jmatrices_shell_0_6.jar file is saved.

Once the console is ready, type the following
js> ms = Packages.org.jmatrices.dbl.client.MatlabSyntax
js> A = ms.create("[1,2,3;4,5,6;7,8,9]")
js> B=ms.rand(3,3);
js> C=ms.multiply(A,B);
js> invB = ms.inv(B);

for help type
js> ms.help();

You can even write scripts and execute them through the File menu's Load.

Example - The following image shows how to use the console to execute the same code as shown above in the class MatrixClient

Note: c and cThroughInv appear to be equal, visually, this is due to rounding-off to a maximum of 8 decimal digits. The comparison without rounding off (as done by the method), results in a false.

Copyright © 2001-2004, Piyush Purang | email | Last modified at 2004-05-18 04:31 PM