JSci.maths.matrices
Class DoubleTridiagonalMatrix

java.lang.Object
  extended byJSci.maths.matrices.Matrix
      extended byJSci.maths.matrices.AbstractDoubleMatrix
          extended byJSci.maths.matrices.AbstractDoubleSquareMatrix
              extended byJSci.maths.matrices.DoubleTridiagonalMatrix
All Implemented Interfaces:
AbelianGroup.Member, Algebra.Member, Member, Module.Member, Ring.Member, java.io.Serializable, SquareMatrix, TridiagonalMatrix, VectorSpace.Member

public class DoubleTridiagonalMatrix
extends AbstractDoubleSquareMatrix
implements TridiagonalMatrix

The DoubleTridiagonalMatrix class provides an object for encapsulating double tridiagonal matrices.

See Also:
Serialized Form

Field Summary
protected  double[] diag
           
protected  double[] ldiag
          Tridiagonal data.
protected  double[] udiag
           
 
Fields inherited from class JSci.maths.matrices.AbstractDoubleSquareMatrix
LU, LUpivot
 
Fields inherited from class JSci.maths.matrices.Matrix
numCols, numRows
 
Constructor Summary
DoubleTridiagonalMatrix(double[][] array)
          Constructs a matrix from an array.
DoubleTridiagonalMatrix(int size)
          Constructs an empty matrix.
 
Method Summary
 AbstractDoubleSquareMatrix add(AbstractDoubleSquareMatrix m)
          Returns the addition of this matrix and another.
 DoubleSquareMatrix add(DoubleSquareMatrix m)
           
 DoubleTridiagonalMatrix add(DoubleTridiagonalMatrix m)
          Returns the addition of this matrix and another.
 AbstractDoubleSquareMatrix[] choleskyDecompose()
          Returns the Cholesky decomposition of this matrix.
 boolean equals(AbstractDoubleMatrix m)
          Compares two ${nativeTyp} matrices for equality.
 double frobeniusNorm()
          Returns the Frobenius (l2) norm.
 double getElement(int i, int j)
          Returns an element of the matrix.
 double infNorm()
          Returns the linfinity-norm.
 boolean isSymmetric()
          Returns true if this matrix is symmetric.
 AbstractDoubleMatrix mapElements(Mapping 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)
           
 DoubleSquareMatrix multiply(DoubleTridiagonalMatrix m)
           
 double operatorNorm()
          Returns the operator norm.
 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)
           
 double scalarProduct(DoubleTridiagonalMatrix m)
           
 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)
           
 DoubleTridiagonalMatrix subtract(DoubleTridiagonalMatrix m)
          Returns the subtraction of this matrix and another.
 AbstractComplexMatrix toComplexMatrix()
          Converts this matrix to a complex matrix.
 AbstractIntegerMatrix toIntegerMatrix()
          Converts this matrix to an integer matrix.
 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 JSci.maths.matrices.AbstractDoubleSquareMatrix
add, det, directSum, inverse, isUnitary, luDecompose, negate, polarDecompose, scalarProduct, subtract, tensor
 
Methods inherited from class JSci.maths.matrices.AbstractDoubleMatrix
add, directSum, equals, hashCode, multiply, multiply, scalarDivide, scalarMultiply, subtract, tensor
 
Methods inherited from class JSci.maths.matrices.Matrix
columns, getInvalidElementMsg, rows
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ldiag

protected final double[] ldiag
Tridiagonal data.


diag

protected final double[] diag

udiag

protected final double[] udiag
Constructor Detail

DoubleTridiagonalMatrix

public DoubleTridiagonalMatrix(int size)
Constructs an empty matrix.

Parameters:
size - the number of rows/columns

DoubleTridiagonalMatrix

public DoubleTridiagonalMatrix(double[][] array)
Constructs a matrix from an array. Any non-tridiagonal elements in the array are ignored.

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

equals

public boolean equals(AbstractDoubleMatrix m)
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

getElement

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

Specified by:
getElement in class AbstractDoubleMatrix
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. 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:
MatrixDimensionException - If attempting to access an invalid element.

isSymmetric

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

Overrides:
isSymmetric in class AbstractDoubleSquareMatrix

trace

public double trace()
Returns the trace.

Overrides:
trace in class AbstractDoubleSquareMatrix

infNorm

public double infNorm()
Returns the linfinity-norm.

Overrides:
infNorm in class AbstractDoubleMatrix

frobeniusNorm

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

Overrides:
frobeniusNorm in class AbstractDoubleMatrix

operatorNorm

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

Overrides:
operatorNorm in class AbstractDoubleSquareMatrix
Throws:
MaximumIterationsExceededException - If it takes more than 50 iterations to determine an eigenvalue.

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:
MatrixDimensionException - If the matrices are different sizes.

add

public DoubleSquareMatrix add(DoubleSquareMatrix m)

add

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

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

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:
MatrixDimensionException - If the matrices are different sizes.

subtract

public DoubleSquareMatrix subtract(DoubleSquareMatrix m)

subtract

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

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

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:
MatrixDimensionException - If the matrices are different sizes.

scalarProduct

public double scalarProduct(DoubleSquareMatrix m)

scalarProduct

public double scalarProduct(DoubleTridiagonalMatrix 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:
DimensionException - 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:
MatrixDimensionException - If the matrices are incompatible.

multiply

public DoubleSquareMatrix multiply(DoubleSquareMatrix m)

multiply

public DoubleSquareMatrix multiply(DoubleTridiagonalMatrix m)

transpose

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

Overrides:
transpose in class AbstractDoubleSquareMatrix
Returns:
a double 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.
PlanetMath references:
QRDecomposition

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.

mapElements

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

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