RE
- the type of the elements in the matrix.public class Matrix<RE extends IRingElement<RE>>
extends java.lang.Object
implements java.io.Serializable
Modifier and Type | Field and Description |
---|---|
protected RE[][] |
entries
the elements in the matrix
|
protected IRingElementFactory<RE> |
FACTORY |
protected int |
numOfCols
the number of columns in this matrix.
|
protected int |
numOfRows
the number of rows in this matrix.
|
private static long |
serialVersionUID |
Constructor and Description |
---|
Matrix(int numberOfRows,
int numberOfCols,
IRingElementFactory<RE> factory)
Constructs an empty Matrix with a certain number of rows and columns.
|
Matrix(Matrix<?> matrix,
IRingElementFactory<RE> factory)
Convert a matrix to a new type
|
Matrix(java.lang.Object[][] theEntries,
IRingElementFactory<RE> factory)
Create a matrix with elements of type
RE from a 2-dimensional
array containing any type of objects the factory of RE
understands. |
Matrix(RE[][] theEntries)
Constructs a Matrix out of a two dimensional array of RingElements.
|
Matrix(RE[][] theEntries,
int rows,
int cols)
Constructs a Matrix out of a two dimensional array of RingElements.
|
Matrix(RE[] theEntries,
int numberOfRows)
Constructs a Matrix with a certain number of rows and columns and and
fills it with RingElements from one RingElement array.
|
Matrix(Vector<RE>[] rowVectors)
Constructs a Matrix out of an array of row vectors.
|
Modifier and Type | Method and Description |
---|---|
Matrix<RE> |
add(Matrix<RE> matrix)
Returns the matrix that is the sum of this Matrix and another matrix.
|
Matrix<RE> |
add(RE scalar)
Returns the matrix that is the sum of this Matrix and a scalar.
|
void |
addReplace(Matrix<RE> anotherMatrix)
Adds another matrix to this Matrix.
|
void |
addReplace(RE scalar)
Adds a scalar to this Matrix.
|
Matrix<RE> |
and(Matrix<RE> anotherMatrix)
Returns the logical AND of this Matrix with another.
|
Matrix<RE> |
apply(Matrix<RE> anotherMatrix,
DyadicOperator<RE> fun)
Returns the result of applying a specified function to the elements of
this Matrix and another.
|
Matrix<RE> |
apply(MonadicOperator<RE> monadicOperator)
Returns the result of applying a specified function to every element of
this Matrix.
|
Matrix<RE> |
apply(RE scalar,
DyadicOperator<RE> fun)
Returns the result of applying a specified function to the elements of a
this Matrix a scalar.
|
void |
applyReplace(Matrix<RE> anotherMatrix,
DyadicOperator<RE> fun)
Sets this Matrix to the result of applying a specified function to
elements of this Matrix and another's.
|
void |
applyReplace(MonadicOperator<RE> fun)
Sets this Matrix to the result of applying a specified function to every
element of this Matrix.
|
void |
applyReplace(RE scalar,
DyadicOperator<RE> fun)
Sets this Matrix to the result of applying a specified function to
elements of this Matrix and a scalar.
|
Matrix<RE> |
arrayMultiply(Matrix<RE> anotherMatrix)
Returns the element-wise product of this Matrix and another.
|
Polynomial<RE> |
characteristicPolynomial() |
private void |
check_sizes(Matrix<RE> b,
java.lang.String op) |
private Matrix<RE> |
comparison(Matrix<RE> anotherMatrix,
FEComparator<RE> feComparator,
java.lang.String compName) |
private Matrix<RE> |
comparison(RE scalar,
FEComparator<RE> feComparator) |
Matrix<RE> |
copy()
Returns a deep copy of this Matrix.
|
RE |
det()
Returns the determinant of this Matrix.
|
Matrix<RE> |
divide(RE scalar)
Returns a Matrix that is this Matrix divided by a scalar.
|
void |
divideReplace(Matrix<RE> anotherMatrix)
Divides this Matrix by another.
|
void |
divideReplace(RE scalar)
Divides this Matrix by a scalar.
|
Vector<RE> |
eig()
Calculates the eigenvalues of a matrix.
|
Matrix<RE> |
eq(Matrix<RE> anotherMatrix)
Returns a Matrix containing ones where this Matrix's elements are equal
to those of another Matrices, and zeros elsewhere.
|
Matrix<RE> |
eq(RE scalar)
Returns a Matrix containing ones where this Matrix's elements are equal
to a scalar, and zeros elsewhere.
|
boolean |
equals(java.lang.Object o)
Tests two matrices for equality.
|
private RE |
extracted(RE t,
int i) |
Matrix<RE> |
gausselim()
Returns a matrix that is this Matrix with Gauss-elimination executed on.
|
Matrix<RE> |
gaussjord()
Returns a matrix that is this Matrix with the Gauss-Jordan algorithm
executed on.
|
Matrix<RE> |
ge(Matrix<RE> anotherMatrix)
Returns a Matrix containing ones where this Matrix's elements are greater
than or equal to those of another Matrices, and zeros elsewhere.
|
Matrix<RE> |
ge(RE scalar)
Returns a Matrix containing ones where this Matrix's elements are greater
than or equal to a scalar, and zeros elsewhere.
|
RE |
get(int rowIndex,
int colIndex)
Gets the entry of this Matrix at a certain row - and col index.
|
Vector<RE> |
getCol(int colIndex)
Gets the column vector at a certain column index.
|
int |
getCols()
Gets the number of columns of this Matrix.
|
RE[][] |
getEntries() |
IRingElementFactory<RE> |
getFactory()
give accesss to the factory
|
Matrix<RE> |
getMatrix(int[] r,
int j0,
int j1)
Get a submatrix.
|
Matrix<RE> |
getMatrix(int i0,
int i1,
int j0,
int j1)
Get a submatrix.
|
Vector<RE> |
getRow(int rowIndex)
Gets the row vector at a certain row index.
|
int |
getRows()
Gets the number of rows of this Matrix.
|
Matrix<RE> |
gt(Matrix<RE> anotherMatrix)
Returns a Matrix containing ones where this Matrix's elements are greater
than those of another Matrices, and zeros elsewhere.
|
Matrix<RE> |
gt(RE scalar)
Returns a Matrix containing ones where this Matrix's elements are greater
than a scalar, and zeros elsewhere.
|
int |
hashCode()
Calculate the hash code from the top-left corner, 3x3 matrix (or smaller)
|
Matrix<RE> |
hermitian()
Returns a matrix that is this Matrix hermitianly transposed.
|
Matrix<RE> |
insertCol(int colIndex,
Vector<RE> vector)
Returns a Matrix with a Vector inserted at specified index as a column.
|
Matrix<RE> |
insertRow(int rowIndex,
Vector<RE> vector)
Returns a Matrix with a Vector inserted at specified index as a row.
|
Matrix<RE> |
inverse()
Returns the inverse of this Matrix.
|
boolean |
isIdentity()
Determine whether this matrix is a identity matrix
|
boolean |
isZeroCol(int colIndex)
Returns whether the column at the specified column index is a zero column
or not.
|
boolean |
isZeroRow(int rowIndex)
Returns whether the row at the specified row index is a zero row or not.
|
Matrix<RE> |
le(Matrix<RE> anotherMatrix)
Returns a Matrix containing ones where this Matrix's elements are less
than or equal to those of another Matrices, and zeros elsewhere.
|
Matrix<RE> |
le(RE scalar)
Returns a Matrix containing ones where this Matrix's elements are less
than or equal to a scalar, and zeros elsewhere.
|
Matrix<RE> |
lt(Matrix<RE> anotherMatrix)
Returns a Matrix containing ones where this Matrix's elements are less
than those of another Matrices, and zeros elsewhere.
|
Matrix<RE> |
lt(RE scalar)
Returns a Matrix containing ones where this Matrix's elements are less
than a scalar, and zeros elsewhere.
|
RE |
max()
Computes the largest value of any element in this Matrix.
|
RE |
mean()
Computes the mean over all elements of this Matrix.
|
Vector<RE> |
meanCols()
Computes the mean over the columns of this Matrix.
|
Vector<RE> |
meanRows()
Computes the mean over the rows of this Matrix.
|
RE |
min()
Computes the smallest value of any element in this Matrix.
|
Polynomial<RE> |
minimalPolynomial() |
Matrix<RE> |
multiply(Matrix<RE> anotherMatrix)
Returns the matrix that is the product of this Matrix and another matrix.
|
Matrix<RE> |
multiply(RE scalar)
Returns a Matrix that is this Matrix multiplied with a scalar.
|
Vector<RE> |
multiply(Vector<RE> vector)
Returns the vector that is the product of this Matrix and a given vector.
|
void |
multiplyReplace(Matrix<RE> anotherMatrix)
Multiplies this Matrix element-wise by another.
|
void |
multiplyReplace(RE scalar)
Multiplies this Matrix by a scalar.
|
Matrix<RE> |
ne(Matrix<RE> anotherMatrix)
Returns a Matrix containing ones where this Matrix's elements are not
equal to those of another Matrices, and zeros elsewhere.
|
Matrix<RE> |
ne(RE scalar)
Returns a Matrix containing ones where this Matrix's elements are not
equal to a scalar, and zeros elsewhere.
|
Matrix<RE> |
not()
Returns the logical negation of this Matrix.
|
private Matrix<RE> |
operate(Matrix<RE> matrix2,
DyadicOperator<RE> dyadicOperator,
java.lang.String funName)
apply an operator on this and a second matrix
|
private Matrix<RE> |
operate(RE scalar,
DyadicOperator<RE> dyadicOperator)
apply an operator on this matrix and a scalar
|
private void |
operateReplace(Matrix<RE> matrix,
DyadicOperator<RE> dyadicOperator,
java.lang.String funName) |
private void |
operateReplace(RE scalar,
DyadicOperator<RE> dyadicOperator) |
Matrix<RE> |
or(Matrix<RE> anotherMatrix)
Returns the logical OR of this Matrix with another.
|
int |
order() |
int |
order(int max)
Calculate the order o of this matrix: the integer number o for which m^o
is the identity matrix.
|
int |
rank()
Returns the rank of this Matrix.
|
private RE |
reduce(Reduction<RE> r) |
void |
set(int rowIndex,
int colIndex,
RE iRingElement)
Sets the entry of this Matrix at a certain row - and col index.
|
void |
setAll(RE newEntry)
Sets all entries to a RingElement.
|
void |
setCol(int matrixCol,
RE value)
Set a given column in the matrix to "value"
|
void |
setCol(int colIndex,
Vector<RE> vector)
Sets the column vector at a certain column index of the matrix.
|
void |
setColFromMatrix(int toCol,
Matrix<RE> matrix,
int fromCol)
copy a given column from another matrix into this matrix
|
void |
setRow(int rowIndex,
RE value)
Sets the row the matrix to the RingElement value.
|
void |
setRow(int rowIndex,
Vector<RE> vector)
Sets the row vector at a certain index of the matrix.
|
void |
setRowFromMatrix(int toRow,
Matrix<RE> matrix,
int fromRow)
copy a given row from another matrix into this matrix
|
Matrix<RE> |
subtract(Matrix<RE> anotherMatrix)
Returns the matrix that is this this Matrix minus another one.
|
Matrix<RE> |
subtract(RE scalar)
Returns the matrix that is this this Matrix minus a scalar.
|
void |
subtractReplace(Matrix<RE> anotherMatrix)
Subtracts another Matrix from this.
|
void |
subtractReplace(RE scalar)
Subtracts a scalar from this Matrix.
|
RE |
sum()
Computes the sum over all elements of this Matrix.
|
Vector<RE> |
sumCols()
Computes the sum over the columns of this matrix.
|
Vector<RE> |
sumRows()
Computes the sum over the rows of this matrix.
|
void |
swapCols(int colIndex1,
int colIndex2)
Swaps two columns of this Matrix.
|
void |
swapRows(int rowIndex1,
int rowIndex2)
Swaps two rows of this Matrix.
|
java.lang.String |
toString()
Returns a String representation of this Matrix.
|
Vector<RE> |
toVector()
Returns a new 1xN Vector made from the N elements of this Matrix.
|
RE |
trace()
Calculate the trace of the matrix
|
Matrix<RE> |
transpose()
Returns a matrix that is this Matrix transposed.
|
Matrix<RE> |
withoutCol(int colIndex)
Returns this Matrix without the column at a certain column index.
|
Matrix<RE> |
withoutRow(int rowIndex)
Returns this Matrix without the row at a certain row index.
|
private static final long serialVersionUID
protected final int numOfRows
protected final int numOfCols
protected final IRingElementFactory<RE extends IRingElement<RE>> FACTORY
protected RE extends IRingElement<RE>[][] entries
public Matrix(int numberOfRows, int numberOfCols, IRingElementFactory<RE> factory)
numberOfRows
- numberOfCols
- factory
- the factory to be used to create elements for this matrix.public Matrix(RE[] theEntries, int numberOfRows) throws InvalidOperationException
numberOfRows
- theEntries
- in a RingElement array.InvalidOperationException
- if theEntries is nullInvalidOperationException
- if numberOfRows is not validpublic Matrix(Vector<RE>[] rowVectors) throws InvalidOperationException
rowVectors
- as an array of VectorsInvalidOperationException
- if rowVectors is nullInvalidOperationException
- if rowVectors contains a null VectorInvalidOperationException
- if rowVectors contains Vectors of unequal lengthspublic Matrix(RE[][] theEntries) throws InvalidOperationException
theEntries
- as a two dimensional RingElement array.InvalidOperationException
- if theEntries is nullpublic Matrix(java.lang.Object[][] theEntries, IRingElementFactory<RE> factory) throws InvalidOperationException
RE
from a 2-dimensional
array containing any type of objects the factory of RE
understands.InvalidOperationException
public Matrix(RE[][] theEntries, int rows, int cols)
theEntries
- rows
- cols
- public Matrix(Matrix<?> matrix, IRingElementFactory<RE> factory)
matrix
- the matrix to be convertedfactory
- The factory with which the elements in the new matrix are
createdpublic int getRows()
public int getCols()
public RE[][] getEntries()
public RE get(int rowIndex, int colIndex) throws InvalidOperationException
rowIndex
- colIndex
- InvalidOperationException
- if rowIndex is not between 1 and numberOfRows or colIndex is
not between 1 and numberOfColspublic void set(int rowIndex, int colIndex, RE iRingElement) throws InvalidOperationException
rowIndex
- colIndex
- iRingElement
- InvalidOperationException
- if rowIndex or colIndex is invalidpublic Vector<RE> getRow(int rowIndex)
rowIndex
- public Vector<RE> getCol(int colIndex)
colIndex
- public void setRow(int rowIndex, Vector<RE> vector) throws InvalidOperationException
rowIndex
- vector
- InvalidOperationException
- if index out of boundspublic void setRow(int rowIndex, RE value) throws InvalidOperationException
rowIndex
- value
- InvalidOperationException
- if index out of boundspublic void setCol(int colIndex, Vector<RE> vector)
colIndex
- vector
- public Matrix<RE> withoutRow(int rowIndex)
rowIndex
- public Matrix<RE> withoutCol(int colIndex)
colIndex
- public Matrix<RE> insertCol(int colIndex, Vector<RE> vector) throws InvalidOperationException
vector
- colIndex
- InvalidOperationException
- if index out of boundspublic Matrix<RE> insertRow(int rowIndex, Vector<RE> vector) throws InvalidOperationException
vector
- rowIndex
- InvalidOperationException
- if index out of boundspublic Matrix<RE> getMatrix(int i0, int i1, int j0, int j1)
i0
- Initial row indexi1
- Final row indexj0
- Initial column indexj1
- Final column indexjava.lang.ArrayIndexOutOfBoundsException
- Submatrix indicespublic Matrix<RE> getMatrix(int[] r, int j0, int j1)
r
- Array of row indices.j0
- Initial column indexj1
- Final column indexjava.lang.ArrayIndexOutOfBoundsException
- Submatrix indicespublic java.lang.String toString()
toString
in class java.lang.Object
public Matrix<RE> add(Matrix<RE> matrix) throws InvalidOperationException
matrix
- the second matrixInvalidOperationException
- if matrices differ in sizepublic Matrix<RE> add(RE scalar)
scalar
- public Matrix<RE> subtract(Matrix<RE> anotherMatrix) throws InvalidOperationException
anotherMatrix
- InvalidOperationException
- if matrices differ in sizepublic Matrix<RE> subtract(RE scalar)
scalar
- public Matrix<RE> multiply(RE scalar)
scalar
- public Matrix<RE> divide(RE scalar)
scalar
- public Vector<RE> multiply(Vector<RE> vector) throws InvalidOperationException
vector
- InvalidOperationException
- if number of columns of this matrix does not equal number of
elements of vectorpublic Matrix<RE> multiply(Matrix<RE> anotherMatrix) throws InvalidOperationException
anotherMatrix
- InvalidOperationException
- if number of columns of this matrix does not equal number of
rows of the other matrixpublic RE det() throws InvalidOperationException
InvalidOperationException
- if matrix is not squarepublic void swapRows(int rowIndex1, int rowIndex2)
rowIndex1
- index of first swap partner.rowIndex2
- index of second swap partner.public void swapCols(int colIndex1, int colIndex2)
colIndex1
- index of first swap partner.colIndex2
- index of second swap partner.public Matrix<RE> gaussjord()
public Matrix<RE> gausselim()
public Vector<RE> eig() throws InvalidOperationException
InvalidOperationException
- if this matrix is no square matrix or the entries are not all
DoubleWrappers.public boolean isZeroRow(int rowIndex)
rowIndex
- index of the row to be testedpublic boolean isZeroCol(int colIndex)
colIndex
- of the column to be testedpublic int rank()
public Matrix<RE> transpose()
public RE trace()
public Matrix<RE> hermitian()
ComplexMatrix
InvalidOperationException
- if the elements are of type Complexpublic boolean equals(java.lang.Object o)
equals
in class java.lang.Object
o
- an
object (typically a matrix).o
is a matrix the two matrices
equal in all entries.public Matrix<RE> inverse()
InvalidOperationException
- if the matrix is not square.public void divideReplace(RE scalar)
scalar
- public void divideReplace(Matrix<RE> anotherMatrix) throws InvalidOperationException
anotherMatrix
- InvalidOperationException
- if the matrices have different sizespublic void multiplyReplace(RE scalar)
scalar
- public void multiplyReplace(Matrix<RE> anotherMatrix) throws InvalidOperationException
anotherMatrix
- InvalidOperationException
- if the matrices have different sizespublic void addReplace(RE scalar)
scalar
- public void addReplace(Matrix<RE> anotherMatrix)
anotherMatrix
- InvalidOperationException
- if the matrices have different sizespublic void subtractReplace(RE scalar)
scalar
- public void subtractReplace(Matrix<RE> anotherMatrix)
anotherMatrix
- InvalidOperationException
- if the matrices have different sizespublic Matrix<RE> and(Matrix<RE> anotherMatrix)
anotherMatrix
- InvalidOperationException
- if the matrices have different sizespublic Matrix<RE> or(Matrix<RE> anotherMatrix)
anotherMatrix
- InvalidOperationException
- if the matrices have different sizespublic Matrix<RE> not()
public Matrix<RE> lt(Matrix<RE> anotherMatrix)
anotherMatrix
- InvalidOperationException
- if the matrices have different sizespublic Matrix<RE> lt(RE scalar)
scalar
- public Matrix<RE> le(Matrix<RE> anotherMatrix)
anotherMatrix
- InvalidOperationException
- if the matrices have different sizespublic Matrix<RE> le(RE scalar)
scalar
- public Matrix<RE> gt(Matrix<RE> anotherMatrix)
anotherMatrix
- InvalidOperationException
- if the matrices have different sizespublic Matrix<RE> gt(RE scalar)
scalar
- public Matrix<RE> ge(Matrix<RE> anotherMatrix)
anotherMatrix
- InvalidOperationException
- if the matrices have different sizespublic Matrix<RE> ge(RE scalar)
scalar
- public Matrix<RE> eq(Matrix<RE> anotherMatrix)
anotherMatrix
- InvalidOperationException
- if the matrices have different sizespublic Matrix<RE> eq(RE scalar)
scalar
- public Matrix<RE> ne(Matrix<RE> anotherMatrix)
anotherMatrix
- InvalidOperationException
- if the matrices have different sizespublic Matrix<RE> ne(RE scalar)
scalar
- public void applyReplace(MonadicOperator<RE> fun)
fun
- the function to applypublic Matrix<RE> apply(MonadicOperator<RE> monadicOperator)
monadicOperator
- the function to applypublic void applyReplace(Matrix<RE> anotherMatrix, DyadicOperator<RE> fun)
anotherMatrix
- fun
- the function to applypublic Matrix<RE> apply(Matrix<RE> anotherMatrix, DyadicOperator<RE> fun)
anotherMatrix
- fun
- the function to applypublic void applyReplace(RE scalar, DyadicOperator<RE> fun)
scalar
- fun
- the function to applypublic Matrix<RE> apply(RE scalar, DyadicOperator<RE> fun)
scalar
- fun
- the function to applypublic Matrix<RE> arrayMultiply(Matrix<RE> anotherMatrix) throws InvalidOperationException
anotherMatrix
- InvalidOperationException
- if the matrices have different sizespublic void setAll(RE newEntry)
newEntry
- the RingElementpublic RE sum()
public RE mean()
public RE min()
public RE max()
public Vector<RE> sumCols()
public Vector<RE> meanRows()
public Vector<RE> meanCols()
public Vector<RE> toVector() throws InvalidOperationException
InvalidOperationException
- if number of rows not equal to oneprivate Matrix<RE> operate(Matrix<RE> matrix2, DyadicOperator<RE> dyadicOperator, java.lang.String funName)
matrix2
- the second matrixdyadicOperator
- an operatorfunName
- an informal name for the operator.private Matrix<RE> operate(RE scalar, DyadicOperator<RE> dyadicOperator)
scalar
- dyadicOperator
- an operatorprivate void operateReplace(Matrix<RE> matrix, DyadicOperator<RE> dyadicOperator, java.lang.String funName)
private void operateReplace(RE scalar, DyadicOperator<RE> dyadicOperator)
private Matrix<RE> comparison(Matrix<RE> anotherMatrix, FEComparator<RE> feComparator, java.lang.String compName)
private Matrix<RE> comparison(RE scalar, FEComparator<RE> feComparator)
private void check_sizes(Matrix<RE> b, java.lang.String op) throws InvalidOperationException
InvalidOperationException
public int order(int max)
max
- The maximal order to test for.InvalidOperationException
- if the matrix is not square.public int order()
order(int)
public boolean isIdentity()
InvalidOperationException
- is matrix is not square.public int hashCode()
hashCode
in class java.lang.Object
Object.hashCode()
public void setCol(int matrixCol, RE value)
matrixCol
- the row to be changed.value
- public void setRowFromMatrix(int toRow, Matrix<RE> matrix, int fromRow)
toRow
- matrix
- fromRow
- public void setColFromMatrix(int toCol, Matrix<RE> matrix, int fromCol)
toCol
- matrix
- fromCol
- public IRingElementFactory<RE> getFactory()
public Polynomial<RE> characteristicPolynomial()
InvalidOperationException
- if this is not a square matrixpublic Polynomial<RE> minimalPolynomial()