|
JScience v3.3 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjavolution.context.RealtimeObject
org.jscience.mathematics.vectors.Matrix<F>
public abstract class Matrix<F extends Field<F>>
This class represents a rectangular table of elements of a ring-like algebraic structure.
Instances of this class can be used to resolve system of linear equations
involving any kind of Field elements
(e.g. Real,
Complex,
Measure<?>,
Function, etc).
For example:
// Creates a dense matrix (2x2) of Rational numbers.
DenseMatrix<Rational> M = DenseMatrix.valueOf(
{ Rational.valueOf(23, 45), Rational.valueOf(33, 75) },
{ Rational.valueOf(15, 31), Rational.valueOf(-20, 45)});
// Creates a sparse matrix (16x2) of Real numbers.
SparseMatrix<Real> M = SparseMatrix.valueOf(
SparseVector.valueOf(16, Real.ZERO, 0, Real.valueOf(5)),
SparseVector.valueOf(16, Real.ZERO, 15, Real.valueOf(-3)));
// Creates a floating-point (64 bits) matrix (3x2).
Float64Matrix M = Float64Matrix.valueOf(
{{ 1.0, 2.0, 3.0}, { 4.0, 5.0, 6.0}});
// Creates a complex single column matrix (1x2).
ComplexMatrix M = ComplexMatrix.valueOf(
{{ Complex.valueOf(1.0, 2.0), Complex.valueOf(4.0, 5.0)}}).transpose();
// Creates an identity matrix (2x2) for modulo integer.
SparseMatrix<ModuloInteger> IDENTITY = SparseMatrix.valueOf(
DenseVector.valueOf(ModuloInteger.ONE, ModuloInteger.ONE), ModuloInteger.ZERO);
Non-commutative field multiplication is supported. Invertible square matrices may form a non-commutative field (also called a division ring). In which case this class may be used to resolve system of linear equations with matrix coefficients.
Implementation Note: Matrices may use PoolContext and ConcurrentContext in order to
minimize heap allocation and accelerate calculations on multi-core
systems.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class javolution.context.RealtimeObject |
|---|
RealtimeObject.Factory<T extends RealtimeObject> |
| Nested classes/interfaces inherited from interface javolution.context.Realtime |
|---|
Realtime.ObjectSpace |
| Field Summary | |
|---|---|
protected static XMLFormat<Matrix> |
XML
Holds the default XML representation for matrices. |
| Constructor Summary | |
|---|---|
protected |
Matrix()
Default constructor (for sub-classes). |
| Method Summary | ||
|---|---|---|
abstract Matrix<F> |
adjoint()
Returns the adjoint of this matrix. |
|
abstract F |
cofactor(int i,
int j)
Returns the cofactor of an element in this matrix. |
|
abstract F |
determinant()
Returns the determinant of this matrix. |
|
Matrix<F> |
divide(Matrix<F> that)
Returns this matrix divided by the one specified. |
|
boolean |
equals(Matrix<F> that,
java.util.Comparator<F> cmp)
Indicates if this matrix can be considered equals to the one specified using the specified comparator when testing for element equality. |
|
boolean |
equals(java.lang.Object that)
Indicates if this matrix is strictly equal to the object specified. |
|
abstract F |
get(int i,
int j)
Returns a single element from this matrix. |
|
abstract Vector<F> |
getColumn(int j)
Returns the column identified by the specified index in this matrix. |
|
abstract Vector<F> |
getDiagonal()
Returns the diagonal vector. |
|
abstract int |
getNumberOfColumns()
Returns the number of columns n for this matrix. |
|
abstract int |
getNumberOfRows()
Returns the number of rows m for this matrix. |
|
abstract Vector<F> |
getRow(int i)
Returns the row identified by the specified index in this matrix. |
|
int |
hashCode()
Returns a hash code value for this matrix. |
|
abstract Matrix<F> |
inverse()
Returns the inverse of this matrix (must be square). |
|
boolean |
isSquare()
Indicates if this matrix is square. |
|
Matrix<F> |
minus(Matrix<F> that)
Returns the difference between this matrix and the one specified. |
|
abstract Matrix<F> |
opposite()
Returns the negation of this matrix. |
|
abstract Matrix<F> |
plus(Matrix<F> that)
Returns the sum of this matrix with the one specified. |
|
Matrix<F> |
pow(int exp)
Returns this matrix raised at the specified exponent. |
|
Matrix<F> |
pseudoInverse()
Returns the inverse or pseudo-inverse if this matrix if not square. |
|
Matrix<F> |
solve(Matrix<F> y)
Solves this matrix for the specified matrix (returns x
such as this · x = y). |
|
Vector<F> |
solve(Vector<F> y)
Solves this matrix for the specified vector (returns x
such as this · x = y). |
|
abstract Matrix<F> |
tensor(Matrix<F> that)
Returns the linear algebraic matrix tensor product of this matrix and another (Kronecker product). |
|
abstract Matrix<F> |
times(F k)
Returns the product of this matrix by the specified factor. |
|
abstract Matrix<F> |
times(Matrix<F> that)
Returns the product of this matrix with the one specified. |
|
abstract Vector<F> |
times(Vector<F> v)
Returns the product of this matrix by the specified vector. |
|
Text |
toText()
Returns the text representation of this matrix. |
|
F |
trace()
Returns the trace of this matrix. |
|
abstract Matrix<F> |
transpose()
Returns the transpose of this matrix. |
|
static Matrix<Complex> |
valueOf(Complex[][] elements)
Deprecated. Since 3.3 - Replaced by ComplexMatrix.valueOf(Complex[][]) |
|
static Matrix<Float64> |
valueOf(double[][] values)
Deprecated. Since 3.3 - Replaced by Float64Matrix.valueOf(double[][]) |
|
static
|
valueOf(F[][] elements)
Deprecated. Since 3.3 - Replaced by DenseMatrix.valueOf(Field[][]) |
|
static
|
valueOf(Vector<F> diagonal,
F zero)
Deprecated. Since 3.3 - Replaced by SparseMatrix.valueOf(Vector, Field) |
|
abstract Vector<F> |
vectorization()
Returns the vectorization of this matrix. |
|
| Methods inherited from class javolution.context.RealtimeObject |
|---|
export, isLocal, move, moveHeap, preserve, toString, unpreserve |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface javolution.context.Realtime |
|---|
move |
| Field Detail |
|---|
protected static final XMLFormat<Matrix> XML
<DenseMatrix rows="2" columns="2">
<Complex real="1.0" imaginary="0.0" />
<Complex real="0.0" imaginary="1.0" />
<Complex real="0.0" imaginary="0.4" />
<Complex real="-5.0" imaginary="-1.0" />
</DenseMatrix>
| Constructor Detail |
|---|
protected Matrix()
| Method Detail |
|---|
public static <F extends Field<F>> Matrix<F> valueOf(F[][] elements)
DenseMatrix.valueOf(Field[][])
elements - this matrix elements.
DimensionException - if rows have different length.public static Matrix<Float64> valueOf(double[][] values)
Float64Matrix.valueOf(double[][])
double
values (convenience method).
values - the array of double values.
DimensionException - if rows have different length.public static Matrix<Complex> valueOf(Complex[][] elements)
ComplexMatrix.valueOf(Complex[][])
complex numbers (convenience method).
elements - the array of complex elements.
DimensionException - if rows have different length.
public static <F extends Field<F>> Matrix<F> valueOf(Vector<F> diagonal,
F zero)
SparseMatrix.valueOf(Vector, Field)
diagonal - the diagonal vector.zero - value of non-diagonal elements.
diagonal on the diagonal and
zero elsewhere.public abstract int getNumberOfRows()
m for this matrix.
public abstract int getNumberOfColumns()
n for this matrix.
public abstract F get(int i,
int j)
i - the row index (range [0..m[).j - the column index (range [0..n[).
java.lang.IndexOutOfBoundsException -
((i < 0) || (i >= m)) || ((j < 0) || (j >= n))public abstract Vector<F> getRow(int i)
i - the row index (range [0..m[).
java.lang.IndexOutOfBoundsException - (i < 0) || (i >= m)public abstract Vector<F> getColumn(int j)
j - the column index (range [0..n[).
java.lang.IndexOutOfBoundsException - (j < 0) || (j >= n)public abstract Vector<F> getDiagonal()
public abstract Matrix<F> opposite()
opposite in interface GroupAdditive<Matrix<F extends Field<F>>>-this.public abstract Matrix<F> plus(Matrix<F> that)
plus in interface GroupAdditive<Matrix<F extends Field<F>>>that - the matrix to be added.
this + that.
DimensionException - matrices's dimensions are different.public Matrix<F> minus(Matrix<F> that)
that - the matrix to be subtracted.
this - that.
DimensionException - matrices's dimensions are different.public abstract Matrix<F> times(F k)
times in interface VectorSpace<Matrix<F extends Field<F>>,F extends Field<F>>k - the coefficient multiplier.
this · kpublic abstract Vector<F> times(Vector<F> v)
v - the vector.
this · v
DimensionException - if
v.getDimension() != this.getNumberOfColumns()public abstract Matrix<F> times(Matrix<F> that)
times in interface Ring<Matrix<F extends Field<F>>>that - the matrix multiplier.
this · that.
DimensionException - if
this.getNumberOfColumns() != that.getNumberOfRows().public abstract Matrix<F> inverse()
1 / this
DimensionException - if this matrix is not square.public Matrix<F> divide(Matrix<F> that)
that - the matrix divisor.
this / that.
DimensionException - if that matrix is not square or dimensions
do not match.public Matrix<F> pseudoInverse()
Note: To resolve the equation A * X = B,
it is usually faster to calculate A.lu().solve(B)
rather than A.inverse().times(B).
public abstract F determinant()
DimensionException - if this matrix is not square.public abstract Matrix<F> transpose()
A'.
public abstract F cofactor(int i,
int j)
i - the row index.j - the column index.
THIS[i,j].
DimensionException - matrix is not square or its dimension
is less than 2.public abstract Matrix<F> adjoint()
DimensionException - if this matrix is not square or if
its dimension is less than 2.public boolean isSquare()
getNumberOfRows() == getNumberOfColumns()public Vector<F> solve(Vector<F> y)
x
such as this · x = y).
y - the vector for which the solution is calculated.
x such as this · x = y
DimensionException - if that matrix is not square or dimensions
do not match.public Matrix<F> solve(Matrix<F> y)
x
such as this · x = y).
y - the matrix for which the solution is calculated.
x such as this · x = y
DimensionException - if that matrix is not square or dimensions
do not match.public Matrix<F> pow(int exp)
exp - the exponent.
thisexp
DimensionException - if this matrix is not square.public F trace()
public abstract Matrix<F> tensor(Matrix<F> that)
DenseMatrix.
that - the second matrix.
this ⊗ thatpublic abstract Vector<F> vectorization()
DenseVector.
public Text toText()
toText in interface RealtimetoText in class RealtimeObject
public boolean equals(Matrix<F> that,
java.util.Comparator<F> cmp)
that - the matrix to compare for equality.cmp - the comparator to use when testing for element equality.
true if this matrix and the specified matrix are
both matrices with equal elements according to the specified
comparator; false otherwise.public boolean equals(java.lang.Object that)
equals in class java.lang.Objectthat - the object to compare for equality.
true if this matrix and the specified object are
both matrices with equal elements; false otherwise.equals(Matrix, Comparator)public int hashCode()
hashCode in class java.lang.Objectequals(org.jscience.mathematics.vectors.Matrix, java.util.Comparator)
|
JScience v3.3 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||