JSci.maths
Class DoubleDiagonalMatrix

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

public final class DoubleDiagonalMatrix
extends DoubleTridiagonalMatrix

The DoubleDiagonalMatrix class encapsulates diagonal matrices containing doubles. Uses compressed diagonal storage.

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

Field Summary
protected static int DIAGONAL
          Storage format identifier.
 
Fields inherited from class JSci.maths.DoubleTridiagonalMatrix
diag, ldiag, TRIDIAGONAL, udiag
 
Fields inherited from class JSci.maths.DoubleSquareMatrix
LU, 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
  DoubleDiagonalMatrix(double[] array)
          Constructs a matrix by wrapping an array containing the diagonal elements.
  DoubleDiagonalMatrix(double[][] array)
          Constructs a matrix from an array.
  DoubleDiagonalMatrix(int size)
          Constructs an empty matrix.
protected DoubleDiagonalMatrix(int size, int storeID)
          Constructs a matrix.
 
Method Summary
 DoubleDiagonalMatrix add(DoubleDiagonalMatrix m)
          Returns the addition of this matrix and another.
 DoubleMatrix add(DoubleMatrix m)
          Returns the addition of this matrix and another.
 DoubleSquareMatrix add(DoubleSquareMatrix m)
          Returns the addition of this matrix and another.
 DoubleTridiagonalMatrix add(DoubleTridiagonalMatrix m)
          Returns the addition of this matrix and another.
 DoubleSquareMatrix[] choleskyDecompose()
          Returns the Cholesky decomposition of this matrix.
 double det()
          Returns the determinant.
 boolean equals(java.lang.Object m)
          Compares two double diagonal matrices for equality.
 double frobeniusNorm()
          Returns the Frobenius (l2) norm.
 double getElement(int i, int j)
          Returns an element of the matrix.
static DoubleDiagonalMatrix identity(int size)
          Creates an identity matrix.
 double infNorm()
          Returns the linfinity-norm.
 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.
 DoubleDiagonalMatrix multiply(DoubleDiagonalMatrix m)
          Returns the multiplication of this matrix and another.
 DoubleMatrix multiply(DoubleMatrix m)
          Returns the multiplication of this matrix and another.
 DoubleSquareMatrix multiply(DoubleSquareMatrix m)
          Returns the multiplication of this matrix and another.
 DoubleSquareMatrix multiply(DoubleTridiagonalMatrix 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.
 DoubleMatrix scalarMultiply(double x)
          Returns the multiplication of this matrix by a scalar.
 double scalarProduct(DoubleDiagonalMatrix m)
          Returns the scalar product of this matrix and another.
 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.
 double scalarProduct(DoubleTridiagonalMatrix m)
          Returns the scalar product of this matrix and another.
 void setElement(int i, int j, double x)
          Sets the value of an element of the matrix.
 DoubleSquareMatrix[] singularValueDecompose()
          Returns the singular value decomposition of this matrix.
 DoubleDiagonalMatrix subtract(DoubleDiagonalMatrix m)
          Returns the subtraction of this matrix by another.
 DoubleMatrix subtract(DoubleMatrix m)
          Returns the subtraction of this matrix and another.
 DoubleSquareMatrix subtract(DoubleSquareMatrix m)
          Returns the subtraction of this matrix and another.
 DoubleTridiagonalMatrix subtract(DoubleTridiagonalMatrix m)
          Returns the subtraction of this matrix and another.
 ComplexMatrix toComplexMatrix()
          Converts this matrix to a complex matrix.
 IntegerMatrix toIntegerMatrix()
          Converts this matrix to an integer matrix.
 double trace()
          Returns the trace.
 Matrix transpose()
          Returns the transpose of this matrix.
 
Methods inherited from class JSci.maths.DoubleTridiagonalMatrix
toString
 
Methods inherited from class JSci.maths.DoubleSquareMatrix
polarDecompose
 
Methods inherited from class JSci.maths.DoubleMatrix
add, directSum, finalize, hashCode, multiply, negate, scalarDivide, scalarDivide, scalarMultiply, subtract, tensorProduct
 
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

DIAGONAL

protected static final int DIAGONAL
Storage format identifier.

See Also:
Constant Field Values
Constructor Detail

DoubleDiagonalMatrix

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


DoubleDiagonalMatrix

public DoubleDiagonalMatrix(int size)
Constructs an empty matrix.

Parameters:
size - the number of rows/columns

DoubleDiagonalMatrix

public DoubleDiagonalMatrix(double[][] array)
Constructs a matrix from an array.

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

DoubleDiagonalMatrix

public DoubleDiagonalMatrix(double[] array)
Constructs a matrix by wrapping an array containing the diagonal elements.

Parameters:
array - an assigned value
Method Detail

identity

public static DoubleDiagonalMatrix identity(int size)
Creates an identity matrix.

Parameters:
size - the number of rows/columns

equals

public boolean equals(java.lang.Object m)
Compares two double diagonal matrices for equality.

Overrides:
equals in class DoubleTridiagonalMatrix
Parameters:
m - a double diagonal matrix

toIntegerMatrix

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

Overrides:
toIntegerMatrix in class DoubleTridiagonalMatrix
Returns:
an integer diagonal matrix

toComplexMatrix

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

Overrides:
toComplexMatrix in class DoubleTridiagonalMatrix
Returns:
a complex diagonal matrix

getElement

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

Overrides:
getElement in class DoubleTridiagonalMatrix
Parameters:
i - row index of the element
j - column index of the element
Throws:
MatrixDimensionException - 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.

Overrides:
setElement in class DoubleTridiagonalMatrix
Parameters:
i - row index of the element
j - column index of the element
x - a number
Throws:
MatrixDimensionException - If attempting to access an invalid element.

isSymmetric

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

Overrides:
isSymmetric in class DoubleTridiagonalMatrix

isUnitary

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

Overrides:
isUnitary in class DoubleSquareMatrix

det

public double det()
Returns the determinant.

Overrides:
det in class DoubleSquareMatrix

trace

public double trace()
Returns the trace.

Overrides:
trace in class DoubleTridiagonalMatrix

infNorm

public double infNorm()
Returns the linfinity-norm.

Overrides:
infNorm in class DoubleTridiagonalMatrix

frobeniusNorm

public double frobeniusNorm()
Returns the Frobenius (l2) norm.

Overrides:
frobeniusNorm in class DoubleTridiagonalMatrix

operatorNorm

public double operatorNorm()
Returns the operator norm.

Overrides:
operatorNorm in class DoubleTridiagonalMatrix

add

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

Overrides:
add in class DoubleTridiagonalMatrix
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.

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

add

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

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

add

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

Parameters:
m - a double diagonal 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 DoubleTridiagonalMatrix
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 and another.

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

subtract

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

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

subtract

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

Parameters:
m - a double diagonal 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 DoubleTridiagonalMatrix
Parameters:
x - a double.
Returns:
a double diagonal matrix.

scalarProduct

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

Overrides:
scalarProduct in class DoubleTridiagonalMatrix
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.

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

scalarProduct

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

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

scalarProduct

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

Parameters:
m - a double diagonal 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 DoubleTridiagonalMatrix
Parameters:
v - a double vector.
Throws:
DimensionException - If the matrix and vector are incompatible.

multiply

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

Overrides:
multiply in class DoubleTridiagonalMatrix
Parameters:
m - a double matrix
Returns:
a DoubleMatrix or a DoubleSquareMatrix as appropriate
Throws:
MatrixDimensionException - If the matrices are different sizes.

multiply

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

Overrides:
multiply in class DoubleTridiagonalMatrix
Parameters:
m - a double square matrix
Throws:
MatrixDimensionException - If the matrices are different sizes.

multiply

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

Overrides:
multiply in class DoubleTridiagonalMatrix
Parameters:
m - a double tridiagonal matrix
Throws:
MatrixDimensionException - If the matrices are different sizes.

multiply

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

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

inverse

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

Overrides:
inverse in class DoubleSquareMatrix
Returns:
a double diagonal matrix

transpose

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

Overrides:
transpose in class DoubleTridiagonalMatrix
Returns:
a double diagonal matrix

luDecompose

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

Overrides:
luDecompose in class DoubleTridiagonalMatrix
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.

Overrides:
choleskyDecompose in class DoubleTridiagonalMatrix
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.

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

mapElements

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

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