\n\n\n\nMatrix\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
\n\n\n\n\n
\n
\n
\n\n\n\n
\n
org.jscience.mathematics.vector
\n

## Class Matrix<F extends Field<F>>

\n
\n
\n
\n
\n
\n
• \n
\n
All Implemented Interfaces:
\n
javolution.lang.Immutable, javolution.lang.Realtime, javolution.lang.ValueType, GroupAdditive<Matrix<F>>, Ring<Matrix<F>>, Structure<Matrix<F>>, VectorSpace<Matrix<F>,F>
\n
\n
\n
Direct Known Subclasses:
\n
ComplexMatrix, DenseMatrix, Float64Matrix, SparseMatrix
\n
\n
\n
\n
`public abstract class Matrix<F extends Field<F>>\nextends Object\nimplements VectorSpace<Matrix<F>,F>, Ring<Matrix<F>>, javolution.lang.ValueType, javolution.lang.Realtime`
\n

This class represents a rectangular table of elements of a ring-like \n algebraic structure.

\n \n

Instances of this class can be used to resolve system of linear equations\n involving any kind of `Field` elements\n (e.g. `Real`, \n `Complex`, \n `Amount<?>`,\n `Function`, etc).\n For example:

``\n        // Creates a dense matrix (2x2) of Rational numbers.\n        DenseMatrix<Rational> M = DenseMatrix.valueOf(\n            { Rational.valueOf(23, 45), Rational.valueOf(33, 75) },\n            { Rational.valueOf(15, 31), Rational.valueOf(-20, 45)});\n            \n        // Creates a sparse matrix (16x2) of Real numbers.\n        SparseMatrix<Real> M = SparseMatrix.valueOf(\n            SparseVector.valueOf(16, Real.ZERO, 0, Real.valueOf(5)),\n            SparseVector.valueOf(16, Real.ZERO, 15, Real.valueOf(-3)));\n            \n        // Creates a floating-point (64 bits) matrix (3x2).\n        Float64Matrix M = Float64Matrix.valueOf(\n           {{ 1.0, 2.0, 3.0}, { 4.0, 5.0, 6.0}});\n            \n        // Creates a complex single column matrix (1x2).\n        ComplexMatrix M = ComplexMatrix.valueOf(\n           {{ Complex.valueOf(1.0, 2.0), Complex.valueOf(4.0, 5.0)}}).transpose();\n            \n        // Creates an identity matrix (2x2) for modulo integer.\n        SparseMatrix<ModuloInteger> IDENTITY = SparseMatrix.valueOf(\n           DenseVector.valueOf(ModuloInteger.ONE, ModuloInteger.ONE), ModuloInteger.ZERO);\n     ``

\n \n

Non-commutative field multiplication is supported. Invertible square \n matrices may form a non-commutative field (also called a division\n ring). In which case this class may be used to resolve system of linear\n equations with matrix coefficients.

\n \n

Implementation Note: Matrices may use `StackContext` and `ConcurrentContext` in order to \n minimize heap allocation and accelerate calculations on multi-core \n systems.

\n
\n Wikipedia: Matrix (mathematics)
\n
• \n
\n
\n
\n
\n
• \n\n
\n
• \n\n\n

### Method Summary

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
Methods
Modifier and TypeMethod and Description
`abstract Matrix<F>``adjoint()`\n
Returns the adjoint of this matrix.
\n
`abstract F``cofactor(int i,\n int j)`\n
Returns the cofactor of an element in this matrix.
\n
`abstract Matrix<F>``copy()`\n
Returns a copy of this matrix \n `allocated` \n by the calling thread (possibly on the stack).
\n
`abstract F``determinant()`\n
Returns the determinant of this matrix.
\n
`Matrix<F>``divide(Matrix<F> that)`\n
Returns this matrix divided by the one specified.
\n
`boolean``equals(Matrix<F> that,\n Comparator<F> cmp)`\n
Indicates if this matrix can be considered equals to the one \n specified using the specified comparator when testing for \n element equality.
\n
`boolean``equals(Object that)`\n
Indicates if this matrix is strictly equal to the object specified.
\n
`abstract F``get(int i,\n int j)`\n
Returns a single element from this matrix.
\n
`abstract Vector<F>``getColumn(int j)`\n
Returns the column identified by the specified index in this matrix.
\n
`abstract Vector<F>``getDiagonal()`\n
Returns the diagonal vector.
\n
`abstract int``getNumberOfColumns()`\n
Returns the number of columns `n` for this matrix.
\n
`abstract int``getNumberOfRows()`\n
Returns the number of rows `m` for this matrix.
\n
`abstract Vector<F>``getRow(int i)`\n
Returns the row identified by the specified index in this matrix.
\n
`int``hashCode()`\n
Returns a hash code value for this matrix.
\n
`abstract Matrix<F>``inverse()`\n
Returns the inverse of this matrix (must be square).
\n
`boolean``isSquare()`\n
Indicates if this matrix is square.
\n
`Matrix<F>``minus(Matrix<F> that)`\n
Returns the difference between this matrix and the one specified.
\n
`abstract Matrix<F>``opposite()`\n
Returns the negation of this matrix.
\n
`abstract Matrix<F>``plus(Matrix<F> that)`\n
Returns the sum of this matrix with the one specified.
\n
`Matrix<F>``pow(int exp)`\n
Returns this matrix raised at the specified exponent.
\n
`Matrix<F>``pseudoInverse()`\n
Returns the inverse or pseudo-inverse if this matrix if not square.
\n
`Matrix<F>``solve(Matrix<F> y)`\n
Solves this matrix for the specified matrix (returns `x`\n such as `this \xc2\xb7 x = y`).
\n
`Vector<F>``solve(Vector<F> y)`\n
Solves this matrix for the specified vector (returns `x`\n such as `this \xc2\xb7 x = y`).
\n
`abstract Matrix<F>``tensor(Matrix<F> that)`\n
Returns the linear algebraic matrix tensor product of this matrix\n and another (Kronecker product).
\n
`abstract Matrix<F>``times(F k)`\n
Returns the product of this matrix by the specified factor.
\n
`abstract Matrix<F>``times(Matrix<F> that)`\n
Returns the product of this matrix with the one specified.
\n
`abstract Vector<F>``times(Vector<F> v)`\n
Returns the product of this matrix by the specified vector.
\n
`String``toString()`\n
Returns the text representation of this matrix as a \n `java.lang.String`.
\n
`javolution.text.Text``toText()`\n
Returns the text representation of this matrix.
\n
`F``trace()`\n
Returns the trace of this matrix.
\n
`abstract Matrix<F>``transpose()`\n
Returns the transpose of this matrix.
\n
`abstract Vector<F>``vectorization()`\n
Returns the vectorization of this matrix.
\n
\n
\n
• \n\n\n

### Methods inherited from class java.lang.Object

\n`getClass, notify, notifyAll, wait, wait, wait`
• \n
\n
• \n
\n
• \n
\n
\n
\n
\n
• \n\n
\n
• \n\n\n

### Method Detail

\n\n\n\n
\n
• \n

#### getNumberOfRows

\n
`public abstract int getNumberOfRows()`
\n
Returns the number of rows `m` for this matrix.
\n
Returns:
m, the number of rows.
\n
• \n
\n\n\n\n
\n
• \n

#### getNumberOfColumns

\n
`public abstract int getNumberOfColumns()`
\n
Returns the number of columns `n` for this matrix.
\n
Returns:
n, the number of columns.
\n
• \n
\n\n\n\n
\n
• \n

#### get

\n
`public abstract F get(int i,\n    int j)`
\n
Returns a single element from this matrix.
\n
Parameters:
`i` - the row index (range [0..m[).
`j` - the column index (range [0..n[).
\n
Returns:
\n
Throws:
\n
`IndexOutOfBoundsException` - `\n ((i < 0) || (i >= m)) || ((j < 0) || (j >= n))`
\n
• \n
\n\n\n\n
\n
• \n

#### getRow

\n
`public abstract Vector<F> getRow(int i)`
\n
Returns the row identified by the specified index in this matrix.
\n
Parameters:
`i` - the row index (range [0..m[).
\n
Returns:
the vector holding the specified row.
\n
Throws:
\n
`IndexOutOfBoundsException` - `(i < 0) || (i >= m)`
\n
• \n
\n\n\n\n
\n
• \n

#### getColumn

\n
`public abstract Vector<F> getColumn(int j)`
\n
Returns the column identified by the specified index in this matrix.
\n
Parameters:
`j` - the column index (range [0..n[).
\n
Returns:
the vector holding the specified column.
\n
Throws:
\n
`IndexOutOfBoundsException` - `(j < 0) || (j >= n)`
\n
• \n
\n\n\n\n
\n
• \n

#### getDiagonal

\n
`public abstract Vector<F> getDiagonal()`
\n
Returns the diagonal vector.
\n
Returns:
the vector holding the diagonal elements.
\n
• \n
\n\n\n\n
\n
• \n

#### opposite

\n
`public abstract Matrix<F> opposite()`
\n
Returns the negation of this matrix.
\n
\n
Specified by:
\n
`opposite` in interface `GroupAdditive<Matrix<F extends Field<F>>>`
\n
Returns:
`-this`.
\n
• \n
\n\n\n\n
\n
• \n

#### plus

\n
`public abstract Matrix<F> plus(Matrix<F> that)`
\n
Returns the sum of this matrix with the one specified.
\n
\n
Specified by:
\n
`plus` in interface `GroupAdditive<Matrix<F extends Field<F>>>`
\n
Parameters:
`that` - the matrix to be added.
\n
Returns:
`this + that`.
\n
Throws:
\n
`DimensionException` - matrices\'s dimensions are different.
\n
• \n
\n\n\n\n
\n
• \n

#### minus

\n
`public Matrix<F> minus(Matrix<F> that)`
\n
Returns the difference between this matrix and the one specified.
\n
Parameters:
`that` - the matrix to be subtracted.
\n
Returns:
`this - that`.
\n
Throws:
\n
`DimensionException` - matrices\'s dimensions are different.
\n
• \n
\n\n\n\n\n\n
\n
• \n

#### times

\n
`public abstract Matrix<F> times(F k)`
\n
Returns the product of this matrix by the specified factor.
\n
\n
Specified by:
\n
`times` in interface `VectorSpace<Matrix<F extends Field<F>>,F extends Field<F>>`
\n
Parameters:
`k` - the coefficient multiplier.
\n
Returns:
`this \xc2\xb7 k`
\n
• \n
\n\n\n\n
\n
• \n

#### times

\n
`public abstract Vector<F> times(Vector<F> v)`
\n
Returns the product of this matrix by the specified vector.
\n
Parameters:
`v` - the vector.
\n
Returns:
`this \xc2\xb7 v`
\n
Throws:
\n
`DimensionException` - if `\n v.getDimension() != this.getNumberOfColumns()`
`\n`
• `\n`
`\n\n\n\n\n\ntimes\npublic abstract Matrix<F> times(Matrix<F> that)\nReturns the product of this matrix with the one specified.\n\nSpecified by:\ntimes in interface Ring<Matrix<F extends Field<F>>>\nParameters:that - the matrix multiplier.\nReturns:this \xc2\xb7 that.\nThrows:\nDimensionException - if \n this.getNumberOfColumns() != that.getNumberOfRows().\n\n\n\n\n\n\n\ninverse\npublic abstract Matrix<F> inverse()\nReturns the inverse of this matrix (must be square).\nReturns:1 / this\nThrows:\nDimensionException - if this matrix is not square.\n\n\n\n\n\n\n\ndivide\npublic Matrix<F> divide(Matrix<F> that)\nReturns this matrix divided by the one specified.\nParameters:that - the matrix divisor.\nReturns:this / that.\nThrows:\nDimensionException - if that matrix is not square or dimensions \n do not match.\n\n\n\n\n\n\n\npseudoInverse\npublic Matrix<F> pseudoInverse()\nReturns the inverse or pseudo-inverse if this matrix if not square.\n\n Note: To resolve the equation A * X = B,\n it is usually faster to calculate A.lu().solve(B)\n rather than A.inverse().times(B).\nReturns:the inverse or pseudo-inverse of this matrix.\n\n\n\n\n\n\n\ndeterminant\npublic abstract F determinant()\nReturns the determinant of this matrix.\nReturns:this matrix determinant.\nThrows:\nDimensionException - if this matrix is not square.\n\n\n\n\n\n\n\ntranspose\npublic abstract Matrix<F> transpose()\nReturns the transpose of this matrix.\nReturns:A\'.\n\n\n\n\n\n\n\ncofactor\npublic abstract F cofactor(int i,\n int j)\nReturns the cofactor of an element in this matrix. It is the value\n obtained by evaluating the determinant formed by the elements not in\n that particular row or column.\nParameters:i - the row index.j - the column index.\nReturns:the cofactor of THIS[i,j].\nThrows:\nDimensionException - matrix is not square or its dimension\n is less than 2.\n\n\n\n\n\n\n\nadjoint\npublic abstract Matrix<F> adjoint()\nReturns the adjoint of this matrix. It is obtained by replacing each\n element in this matrix with its cofactor and applying a + or - sign\n according (-1)**(i+j), and then finding the transpose of the resulting\n matrix.\nReturns:the adjoint of this matrix.\nThrows:\nDimensionException - if this matrix is not square or if\n its dimension is less than 2.\n\n\n\n\n\n\n\nisSquare\npublic boolean isSquare()\nIndicates if this matrix is square.\nReturns:getNumberOfRows() == getNumberOfColumns()\n\n\n\n\n\n\n\nsolve\npublic Vector<F> solve(Vector<F> y)\nSolves this matrix for the specified vector (returns x\n such as this \xc2\xb7 x = y).\nParameters:y - the vector for which the solution is calculated.\nReturns:x such as this \xc2\xb7 x = y\nThrows:\nDimensionException - if that matrix is not square or dimensions \n do not match.\n\n\n\n\n\n\n\nsolve\npublic Matrix<F> solve(Matrix<F> y)\nSolves this matrix for the specified matrix (returns x\n such as this \xc2\xb7 x = y).\nParameters:y - the matrix for which the solution is calculated.\nReturns:x such as this \xc2\xb7 x = y\nThrows:\nDimensionException - if that matrix is not square or dimensions \n do not match.\n\n\n\n\n\n\n\npow\npublic Matrix<F> pow(int exp)\nReturns this matrix raised at the specified exponent.\nParameters:exp - the exponent.\nReturns:thisexp\nThrows:\nDimensionException - if this matrix is not square.\n\n\n\n\n\n\n\ntrace\npublic F trace()\nReturns the trace of this matrix.\nReturns:the sum of the diagonal elements.\n\n\n\n\n\n\n\ntensor\npublic abstract Matrix<F> tensor(Matrix<F> that)\nReturns the linear algebraic matrix tensor product of this matrix\n and another (Kronecker product). The default implementation returns\n a DenseMatrix.\nParameters:that - the second matrix.\nReturns:this ⊗ thatSee Also:\n Wikipedia: Kronecker Product\n\n\n\n\n\n\n\nvectorization\npublic abstract Vector<F> vectorization()\nReturns the vectorization of this matrix. The vectorization of \n a matrix is the column vector obtain by stacking the columns of the\n matrix on top of one another. The default implementation returns \n a DenseVector.\nReturns:the vectorization of this matrix.See Also:\n Wikipedia: Vectorization.\n\n\n\n\n\n\n\ntoText\npublic javolution.text.Text toText()\nReturns the text representation of this matrix.\n\nSpecified by:\ntoText in interface javolution.lang.Realtime\nReturns:the text representation of this matrix.\n\n\n\n\n\n\n\ntoString\npublic final String toString()\nReturns the text representation of this matrix as a \n java.lang.String.\n\nOverrides:\ntoString in class Object\nReturns:toText().toString()\n\n\n\n\n\n\n\nequals\npublic boolean equals(Matrix<F> that,\n Comparator<F> cmp)\nIndicates if this matrix can be considered equals to the one \n specified using the specified comparator when testing for \n element equality. The specified comparator may allow for some \n tolerance in the difference between the matrix elements.\nParameters:that - the matrix to compare for equality.cmp - the comparator to use when testing for element equality.\nReturns:true if this matrix and the specified matrix are\n both matrices with equal elements according to the specified\n comparator; false otherwise.\n\n\n\n\n\n\n\nequals\npublic boolean equals(Object that)\nIndicates if this matrix is strictly equal to the object specified.\n\nOverrides:\nequals in class Object\nParameters:that - the object to compare for equality.\nReturns:true if this matrix and the specified object are\n both matrices with equal elements; false otherwise.See Also:equals(Matrix, Comparator)\n\n\n\n\n\n\n\nhashCode\npublic int hashCode()\nReturns a hash code value for this matrix.\n Equals objects have equal hash codes.\n\nOverrides:\nhashCode in class Object\nReturns:this matrix hash code value.See Also:equals(org.jscience.mathematics.vector.Matrix<F>, java.util.Comparator<F>)\n\n\n\n\n\n\n\ncopy\npublic abstract Matrix<F> copy()\nReturns a copy of this matrix \n allocated \n by the calling thread (possibly on the stack).\n\nSpecified by:\ncopy in interface javolution.lang.ValueType\nReturns:an identical and independant copy of this matrix.\n\n\n`
• `\n`
`\n`
• `\n`
`\n`
`\n`
```\n\n\n\n\n\n\n\n\nOverview\nPackage\nClass\nTree\nIndex\nHelp\n\n\n\n\n\nPrev Class\nNext Class\n\n\nFrames\nNo Frames\n\n\nAll Classes\n\n\n<!--\n allClassesLink = document.getElementById("allclasses_navbar_bottom");\n if(window==top) {\n allClassesLink.style.display = "block";\n }\n else {\n allClassesLink.style.display = "none";\n }\n //-->\n\n\n\n\nSummary: \nNested | \nField | \nConstr | \nMethod\n\n\nDetail: \nField | \nConstr | \nMethod\n\n\n\n\n\n\nSCaVis 1.0 © jWork.org\n\n\n ```
``` © 2013 Powered by Doc2SQL Page generated in 2.62550020218 seconds and 251 kB ```