JSci.maths
Class DoubleSquareMatrix

java.lang.Object
  extended by JSci.maths.Matrix
      extended by JSci.maths.DoubleMatrix
          extended by JSci.maths.DoubleSquareMatrix
All Implemented Interfaces:
java.io.Serializable, Algebra.Member, Module.Member, VectorSpace.Member, Ring.Member, AbelianGroup.Member, Member
Direct Known Subclasses:
DoubleSparseSquareMatrix, DoubleTridiagonalMatrix

public class DoubleSquareMatrix
extends DoubleMatrix

The DoubleSquareMatrix class provides an object for encapsulating square matrices containing doubles.

Version:
2.2
Author:
Mark Hale
See Also:
Serialized Form

Field Summary
protected  DoubleSquareMatrix[] LU
           
protected  int[] LUpivot
           
 
Fields inherited from class JSci.maths.DoubleMatrix
ARRAY_2D, matrix
 
Fields inherited from class JSci.maths.Matrix
CLASS_SPECIFIC, numCols, numRows, storageFormat
 
Constructor Summary
  DoubleSquareMatrix(double[][] array)
          Constructs a matrix by wrapping an array.
  DoubleSquareMatrix(DoubleVector[] array)
          Constructs a matrix from an array of vectors (columns).
  DoubleSquareMatrix(int size)
          Constructs an empty matrix.
protected DoubleSquareMatrix(int size, int storeID)
          Constructs a matrix.
 
Method Summary
 DoubleMatrix add(DoubleMatrix m)
          Returns the addition of this matrix and another.
 DoubleSquareMatrix add(DoubleSquareMatrix m)
          Returns the addition of this matrix and another.
 DoubleSquareMatrix[] choleskyDecompose()
          Returns the Cholesky decomposition of this matrix.
 double det()
          Returns the determinant.
 DoubleSquareMatrix inverse()
          Returns the inverse of this matrix.
 boolean isSymmetric()
          Returns true if this matrix is symmetric.
 boolean isUnitary()
          Returns true if this matrix is unitary.
 DoubleSquareMatrix[] luDecompose(int[] pivot)
          Returns the LU decomposition of this matrix.
 DoubleMatrix mapElements(Mapping f)
          Applies a function on all the matrix elements.
 DoubleSquareMatrix multiply(DoubleSquareMatrix m)
          Returns the multiplication of this matrix and another.
 DoubleVector multiply(DoubleVector v)
          Returns the multiplication of a vector by this matrix.
 double operatorNorm()
          Returns the operator norm.
 DoubleSquareMatrix[] polarDecompose()
          Returns the polar decomposition of this matrix.
 DoubleMatrix scalarMultiply(double x)
          Returns the multiplication of this matrix by a scalar.
 double scalarProduct(DoubleMatrix m)
          Returns the scalar product of this matrix and another.
 double scalarProduct(DoubleSquareMatrix m)
          Returns the scalar product of this matrix and another.
 DoubleSquareMatrix[] singularValueDecompose()
          Returns the singular value decomposition of this matrix.
 DoubleMatrix subtract(DoubleMatrix m)
          Returns the subtraction of this matrix and another.
 DoubleSquareMatrix subtract(DoubleSquareMatrix m)
          Returns the subtraction of this matrix by another.
 double trace()
          Returns the trace.
 Matrix transpose()
          Returns the transpose of this matrix.
 
Methods inherited from class JSci.maths.DoubleMatrix
add, directSum, equals, finalize, frobeniusNorm, getElement, hashCode, infNorm, multiply, multiply, negate, scalarDivide, scalarDivide, scalarMultiply, setElement, subtract, tensorProduct, toComplexMatrix, toIntegerMatrix, toString
 
Methods inherited from class JSci.maths.Matrix
columns, getInvalidElementMsg, rows
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

LU

protected transient DoubleSquareMatrix[] LU

LUpivot

protected transient int[] LUpivot
Constructor Detail

DoubleSquareMatrix

protected DoubleSquareMatrix(int size,
                             int storeID)
Constructs a matrix.


DoubleSquareMatrix

public DoubleSquareMatrix(int size)
Constructs an empty matrix.

Parameters:
size - the number of rows/columns.

DoubleSquareMatrix

public DoubleSquareMatrix(double[][] array)
Constructs a matrix by wrapping an array.

Parameters:
array - an assigned value.
Throws:
MatrixDimensionException - If the array is not square.

DoubleSquareMatrix

public DoubleSquareMatrix(DoubleVector[] array)
Constructs a matrix from an array of vectors (columns).

Parameters:
array - an assigned value.
Method Detail

isSymmetric

public boolean isSymmetric()
Returns true if this matrix is symmetric.


isUnitary

public boolean isUnitary()
Returns true if this matrix is unitary.


det

public double det()
Returns the determinant.


trace

public double trace()
Returns the trace.


operatorNorm

public double operatorNorm()
                    throws MaximumIterationsExceededException
Returns the operator norm.

Throws:
MaximumIterationsExceededException - If it takes more than 50 iterations to determine an eigenvalue.

add

public DoubleMatrix add(DoubleMatrix m)
Returns the addition of this matrix and another.

Overrides:
add in class DoubleMatrix
Parameters:
m - a double matrix.
Throws:
MatrixDimensionException - If the matrices are different sizes.

add

public DoubleSquareMatrix add(DoubleSquareMatrix m)
Returns the addition of this matrix and another.

Parameters:
m - a double square matrix.
Throws:
MatrixDimensionException - If the matrices are different sizes.

subtract

public DoubleMatrix subtract(DoubleMatrix m)
Returns the subtraction of this matrix and another.

Overrides:
subtract in class DoubleMatrix
Parameters:
m - a double matrix.
Throws:
MatrixDimensionException - If the matrices are different sizes.

subtract

public DoubleSquareMatrix subtract(DoubleSquareMatrix m)
Returns the subtraction of this matrix by another.

Parameters:
m - a double square matrix.
Throws:
MatrixDimensionException - If the matrices are different sizes.

scalarMultiply

public DoubleMatrix scalarMultiply(double x)
Returns the multiplication of this matrix by a scalar.

Overrides:
scalarMultiply in class DoubleMatrix
Parameters:
x - a double.
Returns:
a double square matrix.

scalarProduct

public double scalarProduct(DoubleMatrix m)
Returns the scalar product of this matrix and another.

Overrides:
scalarProduct in class DoubleMatrix
Parameters:
m - a double matrix.
Throws:
MatrixDimensionException - If the matrices are different sizes.

scalarProduct

public double scalarProduct(DoubleSquareMatrix m)
Returns the scalar product of this matrix and another.

Parameters:
m - a double square matrix.
Throws:
MatrixDimensionException - If the matrices are different sizes.

multiply

public DoubleVector multiply(DoubleVector v)
Returns the multiplication of a vector by this matrix.

Overrides:
multiply in class DoubleMatrix
Parameters:
v - a double vector.
Throws:
DimensionException - If the matrix and vector are incompatible.

multiply

public DoubleSquareMatrix multiply(DoubleSquareMatrix m)
Returns the multiplication of this matrix and another.

Parameters:
m - a double square matrix.
Throws:
MatrixDimensionException - If the matrices are incompatible.

transpose

public Matrix transpose()
Returns the transpose of this matrix.

Overrides:
transpose in class DoubleMatrix
Returns:
a double square matrix.

inverse

public DoubleSquareMatrix inverse()
Returns the inverse of this matrix.

Returns:
a double square matrix.

luDecompose

public DoubleSquareMatrix[] luDecompose(int[] pivot)
Returns the LU decomposition of this matrix.

Parameters:
pivot - an empty array of length rows()+1 to hold the pivot information (null if not interested). The last array element will contain the parity.
Returns:
an array with [0] containing the L-matrix and [1] containing the U-matrix.

choleskyDecompose

public DoubleSquareMatrix[] choleskyDecompose()
Returns the Cholesky decomposition of this matrix. Matrix must be symmetric and positive definite.

Returns:
an array with [0] containing the L-matrix and [1] containing the U-matrix.

singularValueDecompose

public DoubleSquareMatrix[] singularValueDecompose()
Returns the singular value decomposition of this matrix. Based on the code from JAMA (public domain).

Returns:
an array with [0] containing the U-matrix, [1] containing the S-matrix and [2] containing the V-matrix.

polarDecompose

public DoubleSquareMatrix[] polarDecompose()
Returns the polar decomposition of this matrix.


mapElements

public DoubleMatrix mapElements(Mapping f)
Applies a function on all the matrix elements.

Overrides:
mapElements in class DoubleMatrix
Parameters:
f - a user-defined function.
Returns:
a double square matrix.