JSci.maths
Class IntegerDiagonalMatrix

java.lang.Object
  extended by JSci.maths.Matrix
      extended by JSci.maths.IntegerMatrix
          extended by JSci.maths.IntegerSquareMatrix
              extended by JSci.maths.IntegerTridiagonalMatrix
                  extended by JSci.maths.IntegerDiagonalMatrix
All Implemented Interfaces:
java.io.Serializable, Algebra.Member, Module.Member, VectorSpace.Member, Ring.Member, AbelianGroup.Member, Member

public final class IntegerDiagonalMatrix
extends IntegerTridiagonalMatrix

The IntegerDiagonalMatrix class provides an object for encapsulating diagonal matrices containing integers. 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.IntegerTridiagonalMatrix
diag, ldiag, TRIDIAGONAL, udiag
 
Fields inherited from class JSci.maths.IntegerSquareMatrix
LU, LUpivot
 
Fields inherited from class JSci.maths.IntegerMatrix
ARRAY_2D, matrix
 
Fields inherited from class JSci.maths.Matrix
CLASS_SPECIFIC, numCols, numRows, storageFormat
 
Constructor Summary
  IntegerDiagonalMatrix(int size)
          Constructs an empty matrix.
  IntegerDiagonalMatrix(int[] array)
          Constructs a matrix by wrapping an array containing the diagonal elements.
  IntegerDiagonalMatrix(int[][] array)
          Constructs a matrix from an array.
protected IntegerDiagonalMatrix(int size, int storeID)
          Constructs a matrix.
 
Method Summary
 IntegerDiagonalMatrix add(IntegerDiagonalMatrix m)
          Returns the addition of this matrix and another.
 IntegerMatrix add(IntegerMatrix m)
          Returns the addition of this matrix and another.
 IntegerSquareMatrix add(IntegerSquareMatrix m)
          Returns the addition of this matrix and another.
 IntegerTridiagonalMatrix add(IntegerTridiagonalMatrix m)
          Returns the addition of this matrix and another.
 DoubleSquareMatrix[] choleskyDecompose()
          Returns the Cholesky decomposition of this matrix.
 int det()
          Returns the determinant.
 boolean equals(java.lang.Object m)
          Compares two integer diagonal matrices for equality.
 double frobeniusNorm()
          Returns the Frobenius (l2) norm.
 int getElement(int i, int j)
          Returns an element of the matrix.
static IntegerDiagonalMatrix identity(int size)
          Creates an identity matrix.
 int infNorm()
          Returns the linfinity-norm.
 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.
 IntegerDiagonalMatrix multiply(IntegerDiagonalMatrix m)
          Returns the multiplication of this matrix and another.
 IntegerMatrix multiply(IntegerMatrix m)
          Returns the multiplication of this matrix and another.
 IntegerSquareMatrix multiply(IntegerSquareMatrix m)
          Returns the multiplication of this matrix and another.
 IntegerSquareMatrix multiply(IntegerTridiagonalMatrix m)
          Returns the multiplication of this matrix and another.
 IntegerVector multiply(IntegerVector v)
          Returns the multiplication of a vector by this matrix.
 IntegerMatrix scalarMultiply(int x)
          Returns the multiplication of this matrix by a scalar.
 void setElement(int i, int j, int x)
          Sets the value of an element of the matrix.
 IntegerDiagonalMatrix subtract(IntegerDiagonalMatrix m)
          Returns the subtraction of this matrix by another.
 IntegerMatrix subtract(IntegerMatrix m)
          Returns the subtraction of this matrix and another.
 IntegerSquareMatrix subtract(IntegerSquareMatrix m)
          Returns the subtraction of this matrix and another.
 IntegerTridiagonalMatrix subtract(IntegerTridiagonalMatrix m)
          Returns the subtraction of this matrix and another.
 ComplexMatrix toComplexMatrix()
          Converts this matrix to a complex matrix.
 DoubleMatrix toDoubleMatrix()
          Converts this matrix to a double matrix.
 int trace()
          Returns the trace.
 Matrix transpose()
          Returns the transpose of this matrix.
 
Methods inherited from class JSci.maths.IntegerTridiagonalMatrix
toString
 
Methods inherited from class JSci.maths.IntegerSquareMatrix
choleskyDecomposition
 
Methods inherited from class JSci.maths.IntegerMatrix
add, finalize, hashCode, multiply, negate, scalarDivide, scalarMultiply, subtract
 
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

IntegerDiagonalMatrix

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


IntegerDiagonalMatrix

public IntegerDiagonalMatrix(int size)
Constructs an empty matrix.

Parameters:
size - the number of rows/columns

IntegerDiagonalMatrix

public IntegerDiagonalMatrix(int[][] array)
Constructs a matrix from an array.

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

IntegerDiagonalMatrix

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

Parameters:
array - an assigned value
Method Detail

identity

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

Parameters:
size - the number of rows/columns

equals

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

Overrides:
equals in class IntegerTridiagonalMatrix
Parameters:
m - a integer diagonal matrix

toDoubleMatrix

public DoubleMatrix toDoubleMatrix()
Converts this matrix to a double matrix.

Overrides:
toDoubleMatrix in class IntegerTridiagonalMatrix
Returns:
a double diagonal matrix

toComplexMatrix

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

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

getElement

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

Overrides:
getElement in class IntegerTridiagonalMatrix
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,
                       int x)
Sets the value of an element of the matrix.

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

isSymmetric

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

Overrides:
isSymmetric in class IntegerTridiagonalMatrix

isUnitary

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

Overrides:
isUnitary in class IntegerSquareMatrix

det

public int det()
Returns the determinant.

Overrides:
det in class IntegerSquareMatrix

trace

public int trace()
Returns the trace.

Overrides:
trace in class IntegerTridiagonalMatrix

infNorm

public int infNorm()
Returns the linfinity-norm.

Overrides:
infNorm in class IntegerTridiagonalMatrix

frobeniusNorm

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

Overrides:
frobeniusNorm in class IntegerTridiagonalMatrix

add

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

Overrides:
add in class IntegerTridiagonalMatrix
Parameters:
m - an integer matrix
Throws:
MatrixDimensionException - If the matrices are different sizes.

add

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

Overrides:
add in class IntegerTridiagonalMatrix
Parameters:
m - an integer square matrix
Throws:
MatrixDimensionException - If the matrices are different sizes.

add

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

Overrides:
add in class IntegerTridiagonalMatrix
Parameters:
m - an integer tridiagonal matrix
Throws:
MatrixDimensionException - If the matrices are different sizes.

add

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

Parameters:
m - an integer diagonal matrix
Throws:
MatrixDimensionException - If the matrices are different sizes.

subtract

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

Overrides:
subtract in class IntegerTridiagonalMatrix
Parameters:
m - an integer matrix
Throws:
MatrixDimensionException - If the matrices are different sizes.

subtract

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

Overrides:
subtract in class IntegerTridiagonalMatrix
Parameters:
m - an integer square matrix
Throws:
MatrixDimensionException - If the matrices are different sizes.

subtract

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

Overrides:
subtract in class IntegerTridiagonalMatrix
Parameters:
m - an integer tridiagonal matrix
Throws:
MatrixDimensionException - If the matrices are different sizes.

subtract

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

Parameters:
m - an integer diagonal matrix
Throws:
MatrixDimensionException - If the matrices are different sizes.

scalarMultiply

public IntegerMatrix scalarMultiply(int x)
Returns the multiplication of this matrix by a scalar.

Overrides:
scalarMultiply in class IntegerTridiagonalMatrix
Parameters:
x - an integer
Returns:
an integer diagonal matrix

multiply

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

Overrides:
multiply in class IntegerTridiagonalMatrix
Parameters:
v - an integer vector
Throws:
DimensionException - If the matrix and vector are incompatible.

multiply

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

Overrides:
multiply in class IntegerTridiagonalMatrix
Parameters:
m - an integer matrix
Returns:
an IntegerMatrix or a IntegerSquareMatrix as appropriate
Throws:
MatrixDimensionException - If the matrices are different sizes.

multiply

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

Overrides:
multiply in class IntegerTridiagonalMatrix
Parameters:
m - an integer square matrix
Throws:
MatrixDimensionException - If the matrices are different sizes.

multiply

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

Overrides:
multiply in class IntegerTridiagonalMatrix
Parameters:
m - an integer tridiagonal matrix
Throws:
MatrixDimensionException - If the matrices are different sizes.

multiply

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

Parameters:
m - an integer diagonal matrix
Throws:
MatrixDimensionException - If the matrices are different sizes.

transpose

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

Overrides:
transpose in class IntegerTridiagonalMatrix
Returns:
an integer diagonal matrix

luDecompose

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

Overrides:
luDecompose in class IntegerTridiagonalMatrix
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 IntegerTridiagonalMatrix
Returns:
an array with [0] containing the L-matrix and [1] containing the U-matrix.