org.jscience.chemistry.quantum.math.matrix
Class Matrix

java.lang.Object
  extended by org.jscience.chemistry.quantum.math.matrix.Matrix
All Implemented Interfaces:
java.lang.Cloneable

public class Matrix
extends java.lang.Object
implements java.lang.Cloneable

A general NxM real matrix.


Field Summary
protected  int columnCount
          Holds value of property columnCount.
protected  double[][] matrix
          Holds value of property matrix.
protected  int rowCount
          Holds value of property rowCount.
 
Constructor Summary
Matrix(double[][] a)
          Creates a new instance of Matrix, based on already allocated 2D array
Matrix(int n)
          Creates a new instance of square (NxN) Matrix
Matrix(int n, int m)
          Creates a new instance of NxM Matrix
 
Method Summary
 Matrix add(Matrix b)
          Simple matrix addition of two square matrices: this + b
 java.lang.Object clone()
          clone this vector ;) Cloning is getting interesting!
 int getColumnCount()
          Getter for property columnCount.
 double[][] getMatrix()
          Getter for property matrix.
 double getMatrixAt(int i, int j)
          Getter for property matrix.
 int getRowCount()
          Getter for property rowCount.
 void makeIdentity()
          make the current matrix an identity matrix, all diagonals as 1.0 and non-diagonals zero
only sensible if a square matrix
 Matrix mul(Matrix b)
          Simple matrix multiplication of two matrices: this * b
 double rootMeanSquare()
          rootMeanSquare() - method to compute the root mean square of elements of a diagonal.
 void setColumnCount(int columnCount)
          Setter for property columnCount.
 void setMatrix(double[][] matrix)
          Setter for property matrix.
 void setMatrixAt(int i, int j, double value)
          Getter for property matrix.
 void setRowCount(int rowCount)
          Setter for property rowCount.
 Matrix similarityTransform(Matrix x)
          Similarity Transform : XAX' :: x * this * x'
 Matrix similarityTransformT(Matrix x)
          Similarity Transform : X'AX :: x' * this * x
 double sumOffDiagonal()
          Absolute sum of off-diagonal elements.
 Matrix symmetricOrthogonalization()
          Symmetric orthogonalization of the real symmetric matrix X (this).
 java.lang.String toString()
          overridden toString()
 double trace()
          Tr(this) = sum(diagonal(this)); Only valid if this a square matrix.
 Matrix transpose()
          Transpose a real matrix A (A')
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

matrix

protected double[][] matrix
Holds value of property matrix.


rowCount

protected int rowCount
Holds value of property rowCount.


columnCount

protected int columnCount
Holds value of property columnCount.

Constructor Detail

Matrix

public Matrix(int n,
              int m)
Creates a new instance of NxM Matrix

Parameters:
n - the first dimension
m - the second dimension

Matrix

public Matrix(int n)
Creates a new instance of square (NxN) Matrix

Parameters:
n - the dimension

Matrix

public Matrix(double[][] a)
Creates a new instance of Matrix, based on already allocated 2D array

Parameters:
a - the 2D array
Method Detail

add

public Matrix add(Matrix b)
Simple matrix addition of two square matrices: this + b

Parameters:
b - the matrix to which to add
Returns:
the result Cij = (Aij + Bij)

mul

public Matrix mul(Matrix b)
Simple matrix multiplication of two matrices: this * b

Parameters:
b - the matrix to which to multiply
Returns:
the result Cij = Sum(Aik*Bkj)

transpose

public Matrix transpose()
Transpose a real matrix A (A')

Returns:
the transposed instance

trace

public double trace()
Tr(this) = sum(diagonal(this)); Only valid if this a square matrix.

Returns:
the trace of this matrix

similarityTransform

public Matrix similarityTransform(Matrix x)
Similarity Transform : XAX' :: x * this * x'

Parameters:
x - the pre multiplier
Returns:
XAX'

similarityTransformT

public Matrix similarityTransformT(Matrix x)
Similarity Transform : X'AX :: x' * this * x

Parameters:
x - the post multiplier
Returns:
X'AX

symmetricOrthogonalization

public Matrix symmetricOrthogonalization()
Symmetric orthogonalization of the real symmetric matrix X (this). This is given by U'(1/sqrt(lambda))U, where lambda, U are the eigenvalues/vectors

Returns:
a matrix object U'(1/sqrt(lambda))U

makeIdentity

public void makeIdentity()
make the current matrix an identity matrix, all diagonals as 1.0 and non-diagonals zero
only sensible if a square matrix


rootMeanSquare

public double rootMeanSquare()
rootMeanSquare() - method to compute the root mean square of elements of a diagonal. This is one type of matrix norm. sqrt(sum(Aii)).


sumOffDiagonal

public double sumOffDiagonal()
Absolute sum of off-diagonal elements.

Returns:
Sum(a[i][j],i!=j)

getMatrix

public double[][] getMatrix()
Getter for property matrix.

Returns:
Value of property matrix.

getMatrixAt

public double getMatrixAt(int i,
                          int j)
Getter for property matrix.

Parameters:
i - index i
j - index j
Returns:
Value of property matrix.

setMatrix

public void setMatrix(double[][] matrix)
Setter for property matrix.

Parameters:
matrix - New value of property matrix.

setMatrixAt

public void setMatrixAt(int i,
                        int j,
                        double value)
Getter for property matrix.

Parameters:
i - index i
j - index j
value - the new value

toString

public java.lang.String toString()
overridden toString()

Overrides:
toString in class java.lang.Object

clone

public java.lang.Object clone()
clone this vector ;) Cloning is getting interesting! :)

Overrides:
clone in class java.lang.Object
Returns:
the clone

getRowCount

public int getRowCount()
Getter for property rowCount.

Returns:
Value of property rowCount.

setRowCount

public void setRowCount(int rowCount)
Setter for property rowCount.

Parameters:
rowCount - New value of property rowCount.

getColumnCount

public int getColumnCount()
Getter for property columnCount.

Returns:
Value of property columnCount.

setColumnCount

public void setColumnCount(int columnCount)
Setter for property columnCount.

Parameters:
columnCount - New value of property columnCount.