org.jscience.mathematics.algebraic.matrices
Class DoubleSquareMatrix

java.lang.Object
  extended by org.jscience.mathematics.algebraic.AbstractHypermatrix
      extended by org.jscience.mathematics.algebraic.AbstractMatrix
          extended by org.jscience.mathematics.algebraic.matrices.AbstractDoubleMatrix
              extended by org.jscience.mathematics.algebraic.matrices.AbstractDoubleSquareMatrix
                  extended by org.jscience.mathematics.algebraic.matrices.DoubleSquareMatrix
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Algebra.Member, Ring.Member, AbelianGroup.Member, Hypermatrix, Matrix, Module.Member, VectorSpace.Member, SquareMatrix, Member
Direct Known Subclasses:
DoubleSymmetricMatrix

public class DoubleSquareMatrix
extends AbstractDoubleSquareMatrix
implements java.lang.Cloneable, java.io.Serializable

The DoubleSquareMatrix class provides an object for encapsulating double square matrices.

See Also:
Serialized Form

Field Summary
protected  double[][] matrix
          Array containing the elements of the matrix.
 
Fields inherited from class org.jscience.mathematics.algebraic.matrices.AbstractDoubleSquareMatrix
LU, LUpivot
 
Constructor Summary
DoubleSquareMatrix(AbstractDoubleVector[] array)
          Constructs a matrix from an array of vectors (columns).
DoubleSquareMatrix(double[][] array)
          Constructs a matrix by wrapping an array.
DoubleSquareMatrix(DoubleSquareMatrix mat)
          Copy constructor.
DoubleSquareMatrix(int size)
          Constructs an empty matrix.
 
Method Summary
 AbstractDoubleSquareMatrix add(AbstractDoubleSquareMatrix m)
          Returns the addition of this matrix and another.
 DoubleSquareMatrix add(DoubleSquareMatrix m)
           
 AbstractDoubleSquareMatrix[] choleskyDecompose()
          Returns the Cholesky decomposition of this matrix.
 java.lang.Object clone()
          Clone matrix into a new matrix.
 double det()
          Returns the determinant.
 AbstractDoubleSquareMatrix directSum(AbstractDoubleSquareMatrix m)
          Returns the direct sum of this matrix and another.
 boolean equals(AbstractDoubleMatrix m, double tol)
          Compares two ${nativeTyp} matrices for equality.
 double frobeniusNorm()
          Returns the Frobenius or Hilbert-Schmidt (l2) norm.
 double getPrimitiveElement(int i, int j)
          Returns an element of the matrix.
 double infNorm()
          Returns the linfinity-norm.
 AbstractDoubleSquareMatrix inverse()
          Returns the inverse of this matrix.
 AbstractDoubleSquareMatrix[] luDecompose(int[] pivot)
          Returns the LU decomposition of this matrix.
 AbstractDoubleMatrix mapElements(PrimitiveMapping f)
          Applies a function on all the matrix elements.
 AbstractDoubleSquareMatrix multiply(AbstractDoubleSquareMatrix m)
          Returns the multiplication of this matrix and another.
 AbstractDoubleVector multiply(AbstractDoubleVector v)
          Returns the multiplication of a vector by this matrix.
 DoubleSquareMatrix multiply(DoubleSquareMatrix m)
           
 AbelianGroup.Member negate()
          Returns the negative of this matrix.
 AbstractDoubleSquareMatrix[] polarDecompose()
          Returns the polar decomposition of this matrix.
 AbstractDoubleSquareMatrix[] qrDecompose()
          Returns the QR decomposition of this matrix.
 AbstractDoubleMatrix scalarDivide(double x)
          Returns the division of this matrix by a scalar.
 AbstractDoubleMatrix scalarMultiply(double x)
          Returns the multiplication of this matrix by a scalar.
 double scalarProduct(AbstractDoubleSquareMatrix m)
          Returns the scalar product of this matrix and another.
 double scalarProduct(DoubleSquareMatrix m)
           
 void setAllElements(double x)
          Sets the value of all elements of the matrix.
 void setElement(int i, int j, double x)
          Sets the value of an element of the matrix.
 AbstractDoubleSquareMatrix[] singularValueDecompose()
          Returns the singular value decomposition of this matrix.
 AbstractDoubleSquareMatrix subtract(AbstractDoubleSquareMatrix m)
          Returns the subtraction of this matrix by another.
 DoubleSquareMatrix subtract(DoubleSquareMatrix m)
           
 AbstractDoubleSquareMatrix tensorProduct(AbstractDoubleSquareMatrix m)
          Returns the tensor product of this matrix and another.
 AbstractComplexMatrix toComplexMatrix()
          Converts this matrix to a complex matrix.
 AbstractIntegerMatrix toIntegerMatrix()
          Converts this matrix to an integer matrix.
 double[][] toPrimitiveArray()
          Projects the matrix to an array.
 java.lang.String toString()
          Returns a string representing this matrix.
 double trace()
          Returns the trace.
 Matrix transpose()
          Returns the transpose of this matrix.
 
Methods inherited from class org.jscience.mathematics.algebraic.matrices.AbstractDoubleSquareMatrix
add, isSymmetric, isUnitary, operatorNorm, scalarProduct, subtract
 
Methods inherited from class org.jscience.mathematics.algebraic.matrices.AbstractDoubleMatrix
abs, add, directSum, equals, equals, getColumn, getElement, getMatrixAsColumns, getMatrixAsRows, getRow, getSet, getSubMatrix, hashCode, horizontalAxisSymmetry, mass, max, mean, min, multiply, multiply, read, reverse, scalarDivide, scalarMultiply, setColumn, setRow, setSubMatrix, subtract, tensorProduct, verticalAxisSymmetry
 
Methods inherited from class org.jscience.mathematics.algebraic.AbstractMatrix
getElement, getInvalidElementMsg, numColumns, numRows, print, print, print, print, toArray, toArray
 
Methods inherited from class org.jscience.mathematics.algebraic.AbstractHypermatrix
getDimensions, numDimensions, numElements, numElements, toArray
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jscience.mathematics.algebraic.Matrix
getColumn, getElement, getRow, numColumns, numRows, toArray
 
Methods inherited from interface org.jscience.mathematics.algebraic.Hypermatrix
getDimensions, getElement, numDimensions, numElements, numElements, toArray, toArray
 

Field Detail

matrix

protected final double[][] matrix
Array containing the elements of the matrix.

Constructor Detail

DoubleSquareMatrix

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

Parameters:
array - an assigned value

DoubleSquareMatrix

public DoubleSquareMatrix(int size)
Constructs an empty matrix.


DoubleSquareMatrix

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

Parameters:
array - an assigned value

DoubleSquareMatrix

public DoubleSquareMatrix(DoubleSquareMatrix mat)
Copy constructor.

Parameters:
mat - an assigned value
Method Detail

equals

public boolean equals(AbstractDoubleMatrix m,
                      double tol)
Compares two ${nativeTyp} matrices for equality.

Overrides:
equals in class AbstractDoubleMatrix
Parameters:
m - a double matrix

toString

public java.lang.String toString()
Returns a string representing this matrix.

Overrides:
toString in class AbstractDoubleMatrix

toIntegerMatrix

public AbstractIntegerMatrix toIntegerMatrix()
Converts this matrix to an integer matrix.

Overrides:
toIntegerMatrix in class AbstractDoubleSquareMatrix
Returns:
an integer matrix

toComplexMatrix

public AbstractComplexMatrix toComplexMatrix()
Converts this matrix to a complex matrix.

Overrides:
toComplexMatrix in class AbstractDoubleSquareMatrix
Returns:
a complex matrix

getPrimitiveElement

public double getPrimitiveElement(int i,
                                  int j)
Returns an element of the matrix.

Specified by:
getPrimitiveElement in class AbstractDoubleMatrix
Parameters:
i - row index of the element
j - column index of the element
Throws:
IllegalDimensionException - If attempting to access an invalid element.

setElement

public void setElement(int i,
                       int j,
                       double x)
Sets the value of an element of the matrix. Should only be used to initialise this matrix.

Specified by:
setElement in class AbstractDoubleMatrix
Parameters:
i - row index of the element
j - column index of the element
x - a number
Throws:
IllegalDimensionException - If attempting to access an invalid element.

setAllElements

public void setAllElements(double x)
Sets the value of all elements of the matrix.

Overrides:
setAllElements in class AbstractDoubleMatrix
Parameters:
x - a double element

infNorm

public double infNorm()
Returns the linfinity-norm.

Overrides:
infNorm in class AbstractDoubleMatrix

frobeniusNorm

public double frobeniusNorm()
Returns the Frobenius or Hilbert-Schmidt (l2) norm.

Overrides:
frobeniusNorm in class AbstractDoubleMatrix

det

public double det()
Returns the determinant.

Overrides:
det in class AbstractDoubleSquareMatrix

trace

public double trace()
Returns the trace.

Overrides:
trace in class AbstractDoubleSquareMatrix

negate

public AbelianGroup.Member negate()
Returns the negative of this matrix.

Specified by:
negate in interface AbelianGroup.Member
Overrides:
negate in class AbstractDoubleSquareMatrix
Returns:
DOCUMENT ME!

add

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

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

add

public DoubleSquareMatrix add(DoubleSquareMatrix m)

subtract

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

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

subtract

public DoubleSquareMatrix subtract(DoubleSquareMatrix m)

scalarMultiply

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

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

scalarDivide

public AbstractDoubleMatrix scalarDivide(double x)
Returns the division of this matrix by a scalar.

Overrides:
scalarDivide in class AbstractDoubleSquareMatrix
Parameters:
x - a double.
Returns:
a double square matrix.

scalarProduct

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

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

scalarProduct

public double scalarProduct(DoubleSquareMatrix m)

multiply

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

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

multiply

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

Overrides:
multiply in class AbstractDoubleSquareMatrix
Parameters:
m - a double matrix
Returns:
a AbstractDoubleMatrix or a AbstractDoubleSquareMatrix as appropriate
Throws:
IllegalDimensionException - If the matrices are incompatible.

multiply

public DoubleSquareMatrix multiply(DoubleSquareMatrix m)

directSum

public AbstractDoubleSquareMatrix directSum(AbstractDoubleSquareMatrix m)
Returns the direct sum of this matrix and another.

Overrides:
directSum in class AbstractDoubleSquareMatrix

tensorProduct

public AbstractDoubleSquareMatrix tensorProduct(AbstractDoubleSquareMatrix m)
Returns the tensor product of this matrix and another.

Overrides:
tensorProduct in class AbstractDoubleSquareMatrix

transpose

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

Specified by:
transpose in interface Matrix
Overrides:
transpose in class AbstractDoubleSquareMatrix
Returns:
a double matrix

inverse

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

Overrides:
inverse in class AbstractDoubleSquareMatrix
Returns:
a double square matrix.

luDecompose

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

Overrides:
luDecompose in class AbstractDoubleSquareMatrix
Parameters:
pivot - an empty array of length numRows()+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 AbstractDoubleSquareMatrix[] choleskyDecompose()
Returns the Cholesky decomposition of this matrix. Matrix must be symmetric and positive definite.

Overrides:
choleskyDecompose in class AbstractDoubleSquareMatrix
Returns:
an array with [0] containing the L-matrix and [1] containing the U-matrix.

qrDecompose

public AbstractDoubleSquareMatrix[] qrDecompose()
Returns the QR decomposition of this matrix. Based on the code from JAMA (public domain).

Overrides:
qrDecompose in class AbstractDoubleSquareMatrix
Returns:
an array with [0] containing the Q-matrix and [1] containing the R-matrix.

singularValueDecompose

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

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

polarDecompose

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

Overrides:
polarDecompose in class AbstractDoubleSquareMatrix

mapElements

public AbstractDoubleMatrix mapElements(PrimitiveMapping f)
Applies a function on all the matrix elements.

Overrides:
mapElements in class AbstractDoubleMatrix
Parameters:
f - a user-defined function
Returns:
a double matrix

clone

public java.lang.Object clone()
Clone matrix into a new matrix.

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

toPrimitiveArray

public double[][] toPrimitiveArray()
Projects the matrix to an array.

Overrides:
toPrimitiveArray in class AbstractDoubleMatrix
Returns:
an double array.