org.rubato.math.matrix
Class RMatrix

java.lang.Object
  extended by org.rubato.math.matrix.Matrix
      extended by org.rubato.math.matrix.RMatrix
All Implemented Interfaces:
java.lang.Comparable<Matrix>

public class RMatrix
extends Matrix

Matrixes over real numbers.


Constructor Summary
RMatrix(double[] v)
          Creates a nx1 real matrix from the vector v, where n is the length of v.
RMatrix(double[][] c)
          Creates a mn real matrix from the 2-dimensional array c of doubles.
RMatrix(int rows, int cols)
          Creates a real rows x cols matrix with all coefficients set to 0.
RMatrix(int rows, int cols, double value)
          Creates a real rows x cols matrix with all coefficients set to value.
RMatrix(RMatrix m)
          Creates a copy of the real matrix m.
RMatrix(ZMatrix m)
          Creates a real matrix copy of the integer matrix m.
RMatrix(ZnMatrix m)
          Creates a real matrix copy of the modular integer matrix m.
 
Method Summary
 RMatrix adjoint()
          Returns the adjoint of this matrix.
 RMatrix affineDifference()
           
 int compareTo(Matrix object)
          Compares this matrix to object.
 void computeRREF()
          Compute the reducted row echelon form of this matrix.
 double determinant()
          Returns the determinant of this matrix.
 RMatrix difference(RMatrix m)
          Returns the difference of this matrix and m.
 double dotProduct(RMatrix m)
          Returns the dot product of this matrix and m.
 boolean equals(java.lang.Object object)
           
 double euclidean()
          Returns the Euclidean norm of this matrix.
 double get(int row, int col)
          Returns the value at index row,col.
 RMatrix getMinorMatrix(int row, int col)
          Returns the matrix containing all rows and all columns of this matrix except row and col.
 RMatrix getSubMatrix(int fromRow, int toRow, int fromCol, int toCol)
          Returns the submatrix containing all rows from fromRow to toRow inclusive, and from fromCol to toCol inclusive.
static RMatrix getUnitMatrix(int size)
          Returns the unit real matrix of the given size.
 RMatrix inverse()
          Returns the inverse of this matrix, if it exists.
 boolean isConstant()
          Returns true iff the coefficients of this matrix are equal to a constant value.
 boolean isOne(int row, int col)
          Returns true iff the coefficient at row,col is one.
 boolean isRegular()
          Returns true iff this matrix is regular.
 boolean isUnit()
          Returns true iff this is a unit matrix.
 boolean isZero()
          Returns true iff this is a zero matrix.
 boolean isZero(int row, int col)
          Returns true iff the coefficient at row,col is zero.
 double minor(int row, int col)
          Returns the minor at row,col.
 RMatrix normalized()
          Returns this matrix normalized, in case of a column matrix.
 RMatrix power(int exponent)
          Returns this matrix raised to exponent.
 double[] product(double[] vector)
          Returns the product of this matrix with vector.
 RMatrix product(RMatrix m)
          Returns the product of this matrix and m.
 RMatrix quadraticForm()
          Returns the quadratic form of this matrix.
 int rank()
          Returns the rank of this matrix.
 RMatrix scaled(double scalar)
          Returns this matrix scaled by scalar.
 void set(int row, int col, double value)
          Sets index row,col to value.
 void setColumnCount(int cols)
          Resizes this matrix by changing the number of columns.
 void setRowCount(int rows)
          Resizes this matrix by changing the number of rows.
 void setSubMatrix(int row, int col, RMatrix m)
          Sets the submatrix starting at row,col to the matrix m.
 void setToElementaryMatrix(double value)
          Sets all values of this matrix to value.
 void setToOne(int row, int col)
          Sets the coefficient at row,col to one.
 void setToUnitMatrix()
          Makes this matrix unit square.
 void setToZero(int row, int col)
          Sets the coefficient at row,col to zero.
 void setToZeroMatrix()
          Sets all coefficients to zero.
 double sum()
          Returns the 1-norm of this matrix.
 RMatrix sum(RMatrix m)
          Returns the sum of this matrix and m.
 RMatrix taylor(int exponent)
           
 java.lang.String toString()
          Returns a string representation of this matrix.
 RMatrix transposed()
          Returns the transpose of this matrix.
 
Methods inherited from class org.rubato.math.matrix.Matrix
getColumnCount, getRowCount, isSquare, isZeroColumn, isZeroRow, productPossible, productPossible, sameSize, sameSize
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RMatrix

public RMatrix(int rows,
               int cols)
Creates a real rows x cols matrix with all coefficients set to 0.


RMatrix

public RMatrix(int rows,
               int cols,
               double value)
Creates a real rows x cols matrix with all coefficients set to value.


RMatrix

public RMatrix(RMatrix m)
Creates a copy of the real matrix m.


RMatrix

public RMatrix(ZMatrix m)
Creates a real matrix copy of the integer matrix m.


RMatrix

public RMatrix(ZnMatrix m)
Creates a real matrix copy of the modular integer matrix m.


RMatrix

public RMatrix(double[] v)
Creates a nx1 real matrix from the vector v, where n is the length of v.


RMatrix

public RMatrix(double[][] c)
Creates a mn real matrix from the 2-dimensional array c of doubles.

Method Detail

getUnitMatrix

public static RMatrix getUnitMatrix(int size)
Returns the unit real matrix of the given size.


get

public double get(int row,
                  int col)
Returns the value at index row,col.


set

public void set(int row,
                int col,
                double value)
Sets index row,col to value.


setRowCount

public void setRowCount(int rows)
Description copied from class: Matrix
Resizes this matrix by changing the number of rows. If new rows are created, their values are set to 0.

Specified by:
setRowCount in class Matrix

setColumnCount

public void setColumnCount(int cols)
Description copied from class: Matrix
Resizes this matrix by changing the number of columns. If new columns are created, the new coefficients are all set to zero.

Specified by:
setColumnCount in class Matrix

setToZeroMatrix

public void setToZeroMatrix()
Description copied from class: Matrix
Sets all coefficients to zero.

Specified by:
setToZeroMatrix in class Matrix

setToUnitMatrix

public void setToUnitMatrix()
Description copied from class: Matrix
Makes this matrix unit square. If necessary, the matrix is resized, its final size being the larger of the number of rows and the number of columns.

Specified by:
setToUnitMatrix in class Matrix

setToZero

public void setToZero(int row,
                      int col)
Description copied from class: Matrix
Sets the coefficient at row,col to zero.

Specified by:
setToZero in class Matrix

setToOne

public void setToOne(int row,
                     int col)
Description copied from class: Matrix
Sets the coefficient at row,col to one.

Specified by:
setToOne in class Matrix

setToElementaryMatrix

public void setToElementaryMatrix(double value)
Sets all values of this matrix to value.


getSubMatrix

public RMatrix getSubMatrix(int fromRow,
                            int toRow,
                            int fromCol,
                            int toCol)
Returns the submatrix containing all rows from fromRow to toRow inclusive, and from fromCol to toCol inclusive.


getMinorMatrix

public RMatrix getMinorMatrix(int row,
                              int col)
Returns the matrix containing all rows and all columns of this matrix except row and col.


transposed

public RMatrix transposed()
Returns the transpose of this matrix.


inverse

public RMatrix inverse()
Returns the inverse of this matrix, if it exists.

Throws:
java.lang.ArithmeticException - if inverse does not exist

adjoint

public RMatrix adjoint()
Returns the adjoint of this matrix.


affineDifference

public RMatrix affineDifference()

quadraticForm

public RMatrix quadraticForm()
Returns the quadratic form of this matrix.


scaled

public RMatrix scaled(double scalar)
Returns this matrix scaled by scalar.


power

public RMatrix power(int exponent)
Returns this matrix raised to exponent.

Throws:
java.lang.ArithmeticException - if the matrix is not square

taylor

public RMatrix taylor(int exponent)

rank

public int rank()
Description copied from class: Matrix
Returns the rank of this matrix.

Specified by:
rank in class Matrix

isConstant

public boolean isConstant()
Description copied from class: Matrix
Returns true iff the coefficients of this matrix are equal to a constant value.

Specified by:
isConstant in class Matrix

isZero

public boolean isZero()
Description copied from class: Matrix
Returns true iff this is a zero matrix.

Specified by:
isZero in class Matrix

isUnit

public boolean isUnit()
Description copied from class: Matrix
Returns true iff this is a unit matrix.

Specified by:
isUnit in class Matrix

isRegular

public boolean isRegular()
Description copied from class: Matrix
Returns true iff this matrix is regular.

Specified by:
isRegular in class Matrix

isZero

public boolean isZero(int row,
                      int col)
Description copied from class: Matrix
Returns true iff the coefficient at row,col is zero.

Specified by:
isZero in class Matrix

isOne

public boolean isOne(int row,
                     int col)
Description copied from class: Matrix
Returns true iff the coefficient at row,col is one.

Specified by:
isOne in class Matrix

normalized

public RMatrix normalized()
Returns this matrix normalized, in case of a column matrix.

Throws:
java.lang.ArithmeticException - if this matrix is not a column matrix.

dotProduct

public double dotProduct(RMatrix m)
Returns the dot product of this matrix and m. Both matrixes must be column matrixes of the same size.


equals

public boolean equals(java.lang.Object object)
Specified by:
equals in class Matrix

compareTo

public int compareTo(Matrix object)
Description copied from class: Matrix
Compares this matrix to object. If object is a matrix, but not of the same type, then the strings representation are compared.

Specified by:
compareTo in interface java.lang.Comparable<Matrix>
Overrides:
compareTo in class Matrix

setSubMatrix

public void setSubMatrix(int row,
                         int col,
                         RMatrix m)
Sets the submatrix starting at row,col to the matrix m.


computeRREF

public void computeRREF()
Compute the reducted row echelon form of this matrix. This operation is destructive, i.e., the contents are replaced.


sum

public RMatrix sum(RMatrix m)
Returns the sum of this matrix and m.


difference

public RMatrix difference(RMatrix m)
Returns the difference of this matrix and m.


product

public RMatrix product(RMatrix m)
Returns the product of this matrix and m.


product

public double[] product(double[] vector)
Returns the product of this matrix with vector.


determinant

public double determinant()
Returns the determinant of this matrix.

Throws:
java.lang.ArithmeticException - if this matrix is not square

minor

public double minor(int row,
                    int col)
Returns the minor at row,col.


euclidean

public double euclidean()
Returns the Euclidean norm of this matrix.


sum

public double sum()
Returns the 1-norm of this matrix.


toString

public java.lang.String toString()
Description copied from class: Matrix
Returns a string representation of this matrix.

Specified by:
toString in class Matrix