org.rubato.math.matrix
Class QMatrix

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

public class QMatrix
extends Matrix

Matrixes over rational numbers.


Constructor Summary
QMatrix(int rows, int cols)
          Creates a rational rows x cols matrix with all coefficients set to 0.
QMatrix(int rows, int cols, Rational value)
          Creates a rational rows x cols matrix with all coefficients set to value.
QMatrix(QMatrix m)
          Creates a copy of the rational matrix m.
QMatrix(Rational[] v)
          Creates a nx1 rational matrix from the vector v, where n is the length of v.
QMatrix(Rational[][] c)
          Creates a rational matrix from the two-dimensional array c.
QMatrix(ZMatrix m)
          Creates a rational matrix copy of the integer matrix m.
QMatrix(ZnMatrix m)
          Creates a rational matrix copy of the modular integer matrix m.
 
Method Summary
 QMatrix adjoint()
          Returns the adjoint of this matrix.
 QMatrix affineDifference()
           
 int compareTo(Matrix object)
          Compares this matrix to object.
 void computeRREF()
          Compute the reducted row echelon form of this matrix.
 Rational determinant()
          Returns the determinant of this matrix.
 QMatrix difference(QMatrix m)
          Returns the difference of this matrix and m.
 Rational dotProduct(QMatrix m)
           
 boolean equals(java.lang.Object object)
           
 Rational euclidean()
          Returns the Euclidean norm of this matrix.
 Rational get(int row, int col)
          Returns the value at index row,col.
 QMatrix getMinorMatrix(int row, int col)
          Returns the matrix containing all rows and all columns of this matrix except row and col.
 QMatrix 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 QMatrix getUnitMatrix(int size)
          Returns the unit complex matrix of the given size.
 QMatrix 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.
 Rational minor(int row, int col)
          Returns the minor at row,col.
 QMatrix power(int exponent)
          Returns this matrix raised to exponent.
 QMatrix product(QMatrix m)
          Returns the product of this matrix and m.
 Rational[] product(Rational[] vector)
          Returns the product of this matrix with vector.
 QMatrix quadraticForm()
          Returns the quadratic form of this matrix.
 int rank()
          Returns the rank of this matrix.
 QMatrix scaled(Rational scalar)
          Returns this matrix scaled by scalar.
 void set(int row, int col, Rational 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, QMatrix m)
          Sets the submatrix starting at row,col to the matrix m.
 void setToElementaryMatrix(Rational 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.
 Rational sum()
          Returns the 1-norm of this matrix.
 QMatrix sum(QMatrix m)
          Returns the sum of this matrix and m.
 QMatrix taylor(int exponent)
           
 java.lang.String toString()
          Returns a string representation of this matrix.
 QMatrix 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

QMatrix

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


QMatrix

public QMatrix(int rows,
               int cols,
               Rational value)
Creates a rational rows x cols matrix with all coefficients set to value.


QMatrix

public QMatrix(QMatrix m)
Creates a copy of the rational matrix m.


QMatrix

public QMatrix(ZMatrix m)
Creates a rational matrix copy of the integer matrix m.


QMatrix

public QMatrix(ZnMatrix m)
Creates a rational matrix copy of the modular integer matrix m.


QMatrix

public QMatrix(Rational[] v)
Creates a nx1 rational matrix from the vector v, where n is the length of v.


QMatrix

public QMatrix(Rational[][] c)
Creates a rational matrix from the two-dimensional array c.

Method Detail

getUnitMatrix

public static QMatrix getUnitMatrix(int size)
Returns the unit complex matrix of the given size.


get

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


set

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


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

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

setToElementaryMatrix

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


getSubMatrix

public QMatrix 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 QMatrix getMinorMatrix(int row,
                              int col)
Returns the matrix containing all rows and all columns of this matrix except row and col.


transposed

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


inverse

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

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

adjoint

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


affineDifference

public QMatrix affineDifference()

quadraticForm

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


scaled

public QMatrix scaled(Rational scalar)
Returns this matrix scaled by scalar.


power

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

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

taylor

public QMatrix 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

dotProduct

public Rational dotProduct(QMatrix m)

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,
                         QMatrix 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 QMatrix sum(QMatrix m)
Returns the sum of this matrix and m.


difference

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


product

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


product

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


determinant

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

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

minor

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


euclidean

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


sum

public Rational 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