ru.sscc.matrix
Class RealMatrix

java.lang.Object
  |
  +--ru.sscc.matrix.RealMatrix
Direct Known Subclasses:
DenseMatrix, RectBandedMatrix, SymBandedMatrix

public abstract class RealMatrix
extends java.lang.Object
implements RealAlgebraicMatrix, java.lang.Cloneable

An abstract implementation of a real rectangular algebraic matrix based on RealContainer entries vector. A storage of entries in the vector depends on a subclass. An abstract operations set and get provide a subclass independent access to matrix entries. All matrices are supposed to be cloneable and serializable. Four static matrix-bymatrix multiplication methods are implemented here.

See Also:
Serialized Form

Field Summary
protected  RealContainer entries
          A container for matrix entries.
 int nColumns
          A number of matrix columns.
 int nRows
          A number of matrix rows.
 
Constructor Summary
protected RealMatrix(RealContainer entries, int nRows, int nColumns)
          Constructor.
 
Method Summary
abstract  double add(int i, int j, double value)
          Adds the value of a matrix entry at the position (i,j).
 java.lang.Object clone()
          Clones the matrix.
 int columnsNumber()
          Returns a number of matrix columns.
 void ensureAlgebraic()
          Tests the matrix to be algebraic and throws the IllegalStateException if not.
 void ensureDimensions(int rowsNumber, int columnsNumber)
          Tests the matrix dimensions to be equal to specified dimensions and throws the IllegalArgumentException if not.
 void ensureDimensions(Matrix matrix)
          Tests the matrix dimensions to be equal to the parameter matrix dimensions and throws the IllegalArgumentException if not.
 void ensureSquareMatrix()
          Tests the matrix to be square matrix and throws the IllegalArgumentException if not.
abstract  double get(int i, int j)
          Gets a value of a matrix entry at the position (i,j).
 RealContainer getContainer()
          Returns the matrix data container.
 void lock()
          Locks matrix by vector operations (sets the matrix to be nonalgebraic).
abstract  double mul(int i, int j, double value)
          Multiplies a matrix entry at the position (i,j) by a value.
abstract  void multiply(RealVector source, RealVector target)
          Multiplies the matrix by a column-vector.
static DenseMatrix multiplyNN(RealMatrix A, RealMatrix B, DenseMatrix C)
          Calculates C=AB, where A and B are arbitrary real matrices, and C is the dense rectangular matrix.
static DenseMatrix multiplyNT(RealMatrix A, RealMatrix B, DenseMatrix C)
          Calculates C=ABT, where A and B are arbitrary real matrices, and C is the dense rectangular matrix.
abstract  void multiplyT(RealVector source, RealVector target)
          Multiplies the transposed matrix by a column-vector.
static DenseMatrix multiplyTN(RealMatrix A, RealMatrix B, DenseMatrix C)
          Calculates C=ATB, where A and B are arbitrary real matrices, and C is the dense rectangular matrix.
static DenseMatrix multiplyTT(RealMatrix A, RealMatrix B, DenseMatrix C)
          Calculates C=ATBT, where A and B are arbitrary real matrices, and C is the dense rectangular matrix.
 double relativeAccuracy()
          Returns the matrix entries relative accuracy: the smallest value e such that 1+e isn't equal to 1 for the data type used for the matrix entries.
 int rowsNumber()
          Returns a number of matrix rows.
abstract  double set(int i, int j, double value)
          Sets the value of a matrix entry at the position (i,j).
protected  void unlock()
          Clears nonalgebraicness tag for the matrix and allows use the matrix in algebraic operations again.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nRows

public final int nRows
A number of matrix rows.

nColumns

public final int nColumns
A number of matrix columns.

entries

protected RealContainer entries
A container for matrix entries.
Constructor Detail

RealMatrix

protected RealMatrix(RealContainer entries,
                     int nRows,
                     int nColumns)
Constructor.
Parameters:
entries - a container of matrix entries
nRows - a number of matrix rows
nColumns - a number of matrix columns
Method Detail

rowsNumber

public final int rowsNumber()
Returns a number of matrix rows.
Tags copied from interface: Matrix
Returns:
a number of matrix rows.

columnsNumber

public final int columnsNumber()
Returns a number of matrix columns.
Tags copied from interface: Matrix
Returns:
a number of matrix columns.

getContainer

public final RealContainer getContainer()
Returns the matrix data container.

relativeAccuracy

public final double relativeAccuracy()
Returns the matrix entries relative accuracy: the smallest value e such that 1+e isn't equal to 1 for the data type used for the matrix entries.
Specified by:
relativeAccuracy in interface RealAlgebraicMatrix

lock

public final void lock()
Locks matrix by vector operations (sets the matrix to be nonalgebraic). Throws the IllegalStateException if the matrix is already nonalgebraic.

unlock

protected void unlock()
Clears nonalgebraicness tag for the matrix and allows use the matrix in algebraic operations again.

ensureAlgebraic

public void ensureAlgebraic()
Tests the matrix to be algebraic and throws the IllegalStateException if not.

ensureDimensions

public final void ensureDimensions(Matrix matrix)
Tests the matrix dimensions to be equal to the parameter matrix dimensions and throws the IllegalArgumentException if not.

ensureDimensions

public final void ensureDimensions(int rowsNumber,
                                   int columnsNumber)
Tests the matrix dimensions to be equal to specified dimensions and throws the IllegalArgumentException if not.

ensureSquareMatrix

public void ensureSquareMatrix()
Tests the matrix to be square matrix and throws the IllegalArgumentException if not.

clone

public java.lang.Object clone()
Clones the matrix.
Overrides:
clone in class java.lang.Object

get

public abstract double get(int i,
                           int j)
Gets a value of a matrix entry at the position (i,j).
Parameters:
i - a zero based row number
j - a zero based column number
Returns:
an entry value at the required position

set

public abstract double set(int i,
                           int j,
                           double value)
Sets the value of a matrix entry at the position (i,j).
Parameters:
i - a zero based row number
j - a zero based column number
value - a value to set
Returns:
the set value

add

public abstract double add(int i,
                           int j,
                           double value)
Adds the value of a matrix entry at the position (i,j).
Parameters:
i - a zero based row number
j - a zero based column number
value - a value to set
Returns:
the addition result

mul

public abstract double mul(int i,
                           int j,
                           double value)
Multiplies a matrix entry at the position (i,j) by a value.
Parameters:
i - a zero based row number
j - a zero based column number
value - a value to set
Returns:
the multiplication result

multiply

public abstract void multiply(RealVector source,
                              RealVector target)
Multiplies the matrix by a column-vector. Throws IllegalStateException if the matrix is nonalgebraic.
Specified by:
multiply in interface RealAlgebraicMatrix
Parameters:
source - a source vector to multiply
target - a target vector to write the result

multiplyT

public abstract void multiplyT(RealVector source,
                               RealVector target)
Multiplies the transposed matrix by a column-vector. Throws IllegalStateException if the matrix is nonalgebraic.
Specified by:
multiplyT in interface RealAlgebraicMatrix
Parameters:
source - a source vector to multiply
target - a target vector to write the result

multiplyNN

public static DenseMatrix multiplyNN(RealMatrix A,
                                     RealMatrix B,
                                     DenseMatrix C)
Calculates C=AB, where A and B are arbitrary real matrices, and C is the dense rectangular matrix. All matrices must be algebraic and their dimensions must satisfy the identities A.nColumns==B.nRows, C.nRows==A.nRows, and C.nColumns==B.nColumns. It is possible to pass null instead of the C parameter. In this case a dense matrix of the required dimensions will be constructed.
Parameters:
A - the first multiplier
B - the second multiplier
C - the matrix to store the result (null is possible)
Returns:
the result of the multiplication (the same object as the last parameter if it isn't equal to null)
Throws:
java.lang.IllegalStateException - is thrown if any matrix isn't algebraic
java.lang.IllegalArgumentException - is thrown if the dimensions of matrices are incompatible

multiplyTN

public static DenseMatrix multiplyTN(RealMatrix A,
                                     RealMatrix B,
                                     DenseMatrix C)
Calculates C=ATB, where A and B are arbitrary real matrices, and C is the dense rectangular matrix. All matrices must be algebraic and their dimensions must satisfy the identities A.nRows==B.nRows, C.nRows==A.nColumns, and C.nColumns==B.nColumns. It is possible to pass null instead of the C parameter. In this case a dense matrix of the required dimensions will be constructed.
Parameters:
A - the first multiplier
B - the second multiplier
C - the matrix to store the result (null is possible)
Returns:
the result of the multiplication (the same object as the last parameter if it isn't equal to null)
Throws:
java.lang.IllegalStateException - is thrown if any matrix isn't algebraic
java.lang.IllegalArgumentException - is thrown if the dimensions of matrices are incompatible

multiplyNT

public static DenseMatrix multiplyNT(RealMatrix A,
                                     RealMatrix B,
                                     DenseMatrix C)
Calculates C=ABT, where A and B are arbitrary real matrices, and C is the dense rectangular matrix. All matrices must be algebraic and their dimensions must satisfy the identities A.nColumns==B.nColumns, C.nRows==A.nRows, and C.nColumns==B.nRows. It is possible to pass null instead of the C parameter. In this case a dense matrix of the required dimensions will be constructed.
Parameters:
A - the first multiplier
B - the second multiplier
C - the matrix to store the result (null is possible)
Returns:
the result of the multiplication (the same object as the last parameter if it isn't equal to null)
Throws:
java.lang.IllegalStateException - is thrown if any matrix isn't algebraic
java.lang.IllegalArgumentException - is thrown if the dimensions of matrices are incompatible

multiplyTT

public static DenseMatrix multiplyTT(RealMatrix A,
                                     RealMatrix B,
                                     DenseMatrix C)
Calculates C=ATBT, where A and B are arbitrary real matrices, and C is the dense rectangular matrix. All matrices must be algebraic and their dimensions must satisfy the identities A.nRows==B.nColumns, C.nRows==A.nColumns, and C.nColumns==B.nRows. It is possible to pass null instead of the C parameter. In this case a dense matrix of the required dimensions will be constructed.
Parameters:
A - the first multiplier
B - the second multiplier
C - the matrix to store the result (null is possible)
Returns:
the result of the multiplication (the same object as the last parameter if it isn't equal to null)
Throws:
java.lang.IllegalStateException - is thrown if any matrix isn't algebraic
java.lang.IllegalArgumentException - is thrown if the dimensions of matrices are incompatible