com.yobotics.simulationconstructionset.mathfunctions
Class Matrix

java.lang.Object
  extended by com.yobotics.simulationconstructionset.mathfunctions.Matrix

public final class Matrix
extends java.lang.Object

Jama = Java Matrix class.

The Java Matrix Class provides the fundamental operations of numerical linear algebra. Various constructors create Matrices from two dimensional arrays of double precision floating point numbers. Various "gets" and "sets" provide access to submatrices and matrix elements. Several methods implement basic matrix arithmetic, including matrix addition and multiplication, matrix norms, and element-by-element array operations. Methods for reading and printing matrices are also included. All the operations in this version of the Matrix Class involve real matrices. Complex matrices may be handled in a future version.

Five fundamental matrix decompositions, which consist of pairs or triples of matrices, permutation vectors, and the like, produce results in five decomposition classes. These decompositions are accessed by the Matrix class to compute solutions of simultaneous linear equations, determinants, inverses and other matrix functions. The five decompositions are:

Example of use:

Solve a linear system A x = b and compute the residual norm, ||b - A x||.

     double[][] vals = {{1.,2.,3},{4.,5.,6.},{7.,8.,10.}};
     Matrix A = new Matrix(vals);
     Matrix b = Matrix.random(3,1);
     Matrix x = A.solve(b);
     Matrix r = A.times(x).minus(b);
     double rnorm = r.normInf();
 

Version:
5 August 1998
Author:
The MathWorks, Inc. and the National Institute of Standards and Technology.

Constructor Summary
Matrix(double[][] A)
          Construct a matrix from a 2-D array.
Matrix(int m, int n)
          Construct an m-by-n matrix of zeros.
 
Method Summary
 double get(int i, int j)
          Get a single element.
 double[][] getArray()
          Access the internal two-dimensional array.
 void getArrayCopy(double[][] C)
          Copy the internal two-dimensional array into the passed array.
 int getColumnDimension()
          Get column dimension.
 void getMatrix(double[][] B, int[] r, int j0, int j1)
          Get a submatrix.
 int getRowDimension()
          Get row dimension.
 void inverse(Matrix Xmat)
           
 void set(int i, int j, double s)
          Set a single element.
 void setIdentity()
          Sets this Matrix to be the identity matrix May 30, 2004: Added by J.Pratt
 void solve(Matrix Xmat, Matrix B)
           
 Matrix timesEquals(double s)
          Multiply a matrix by a scalar in place, A = s*A
 void timesEquals(Matrix B, Matrix C)
          In place Linear algebraic matrix multiplication, A = B * C May 30, 2004: Added by J.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Matrix

public Matrix(int m,
              int n)
Construct an m-by-n matrix of zeros.

Parameters:
m - Number of rows.
n - Number of colums.

Matrix

public Matrix(double[][] A)
Construct a matrix from a 2-D array.

Parameters:
A - Two-dimensional array of doubles.
Throws:
java.lang.IllegalArgumentException - All rows must have the same length
See Also:
#constructWithCopy
Method Detail

getArray

public double[][] getArray()
Access the internal two-dimensional array.

Returns:
Pointer to the two-dimensional array of matrix elements.

getArrayCopy

public void getArrayCopy(double[][] C)
Copy the internal two-dimensional array into the passed array.

Parameters:
C - Array that the values get copied into. Assumes dimensions are correct.

getRowDimension

public int getRowDimension()
Get row dimension.

Returns:
m, the number of rows.

getColumnDimension

public int getColumnDimension()
Get column dimension.

Returns:
n, the number of columns.

get

public double get(int i,
                  int j)
Get a single element.

Parameters:
i - Row index.
j - Column index.
Returns:
A(i,j)
Throws:
java.lang.ArrayIndexOutOfBoundsException

getMatrix

public void getMatrix(double[][] B,
                      int[] r,
                      int j0,
                      int j1)
Get a submatrix.

Parameters:
r - Array of row indices.
i0 - Initial column index
i1 - Final column index
Throws:
java.lang.ArrayIndexOutOfBoundsException - Submatrix indices

set

public void set(int i,
                int j,
                double s)
Set a single element.

Parameters:
i - Row index.
j - Column index.
s - A(i,j).
Throws:
java.lang.ArrayIndexOutOfBoundsException

timesEquals

public Matrix timesEquals(double s)
Multiply a matrix by a scalar in place, A = s*A

Parameters:
s - scalar
Returns:
replace A by s*A

timesEquals

public void timesEquals(Matrix B,
                        Matrix C)
In place Linear algebraic matrix multiplication, A = B * C May 30, 2004: Added by J. Pratt

Parameters:
B - two matrices
Throws:
java.lang.IllegalArgumentException - Matrix inner dimensions must agree.

solve

public void solve(Matrix Xmat,
                  Matrix B)

inverse

public void inverse(Matrix Xmat)

setIdentity

public void setIdentity()
Sets this Matrix to be the identity matrix May 30, 2004: Added by J.Pratt