|
JADE v6.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.dautelle.realtime.RealtimeObject
com.dautelle.math.Matrix
This class represents a rectangular array of Operable
objects. It may be used to resolve system of linear equations
involving any kind of Operable
elements
(e.g. Real
, Complex
,
Quantity
,
Function
, etc).
Non-commutative multiplication is supported and this class itself
implements the Operable
interface. Consequently, this class may
be used to resolve system of linear equations involving matrices
(for which the multiplication is not commutative).
Implementation Note: This class uses ConcurrentContext
to accelerate calculations on multi-processor systems.
Nested Class Summary |
Nested classes inherited from class com.dautelle.realtime.RealtimeObject |
RealtimeObject.Factory |
Constructor Summary | |
protected |
Matrix()
Default constructor. |
Method Summary | |
Matrix |
add(Matrix that)
Returns the sum of this matrix with the one specified. |
Matrix |
adjoint()
Returns the adjoint of this matrix. |
Operable |
cofactor(int i,
int j)
Returns the cofactor of an element in this matrix. |
Operable |
determinant()
Returns the determinant of this matrix. |
Matrix |
divide(Matrix that)
Returns this matrix divided by the one specified. |
boolean |
equals(java.lang.Object that)
Indicates if this matrix is equal to the object specified. |
java.lang.Object |
export()
Exports this object out of the current pool context. |
Operable |
get(int i,
int j)
Returns a single element from this matrix. |
int |
getColumnDimension()
Returns the column dimension of this matrix. |
Matrix |
getMatrix(int[] rows,
int[] columns)
Returns a sub-matrix composed of the specified rows and columns from this matrix. |
Matrix |
getMatrix(int i0,
int i1,
int j0,
int j1)
Returns a sub-matrix of this matrix given the range of its rows and columns indices. |
int |
getRowDimension()
Returns the row dimension of this matrix. |
int |
hashCode()
Returns a hash code value for this matrix. |
Matrix |
inverse()
Returns the inverse of this matrix. |
boolean |
isSquare()
Indicates if this matrix is square. |
LUDecomposition |
lu()
Returns the LUDecomposition of this Matrix . |
Matrix |
multiply(Matrix that)
Returns the product of this matrix with the one specified. |
Matrix |
multiply(Operable k)
Return the multiplication of this matrix with the specified factor. |
Matrix |
negate()
Returns the negation of this matrix. |
static Matrix |
newInstance(int n,
int m)
Returns a n-by-m matrix filled with null elements. |
Operable |
opposite()
Returns the additive inverse of this object. |
Operable |
plus(Operable that)
Returns the sum of this object with the one specified. |
Matrix |
pow(int exp)
Returns this matrix raised at the specified exponent. |
Matrix |
pseudoInverse()
Returns the pseudo-inverse of this matrix. |
Operable |
reciprocal()
Returns the multiplicative inverse of this object. |
void |
set(int i,
int j,
Operable element)
Sets a single element of this matrix. |
Matrix |
subtract(Matrix that)
Returns the difference between this matrix and the one specified. |
Matrix |
tensor(Matrix that)
Returns the linear algebraic matrix tensor product of this matrix and another. |
Operable |
times(Operable that)
Returns the product of this object with the one specified. |
java.lang.Object |
toHeap()
Moves this object to the heap. |
java.lang.String |
toString()
Returns the text representation of this matrix. |
void |
toXml(XmlElement xml)
Sets the attributes and content of the XML element corresponding to this object. |
Operable |
trace()
Returns the trace of this matrix. |
Matrix |
transpose()
Returns the transpose of this matrix. |
static Matrix |
valueOf(int n,
int m,
java.util.Collection elements)
Returns a n-by-m matrix populated from the specified collection of Operable objects (rows first). |
static Matrix |
valueOf(int n,
int m,
Operable diagonal,
Operable other)
Returns a n-by-m matrix filled with the specified diagonal element and the specified non-diagonal element. |
static Matrix |
valueOf(Operable[][] elements)
Returns a matrix from a 2-dimensional array of Operable objects. |
static Matrix |
valueOf(XmlElement xml)
XML factory method. |
Methods inherited from class com.dautelle.realtime.RealtimeObject |
clone, isLocalObject, isPoolObject, recycle |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
protected Matrix()
Method Detail |
public static Matrix newInstance(int n, int m)
null
elements.
n
- the number of rows.m
- the number of columns.
public static Matrix valueOf(int n, int m, Operable diagonal, Operable other)
valueOf(n, n, ONE, ZERO)
).
n
- the number of rows.m
- the number of columns.diagonal
- the diagonal element.other
- the non-diagonal element.
d
on the diagonal and
o
elsewhere.public static Matrix valueOf(Operable[][] elements)
Operable
objects.
The first dimension being the row and the second being the column.
Note: It is safe to reuse the specifed array as it is not internally referenced by the matrix being returned.
elements
- the array of Operable
objects.
java.lang.IllegalArgumentException
- all rows must have the same length.public static Matrix valueOf(int n, int m, java.util.Collection elements)
Operable
objects (rows first).
n
- the number of rows.m
- the number of columns.elements
- the collection of Operable
objects.
DimensionException
- if elements.size() != n * m
java.lang.ClassCastException
- if any of the element is not Operable
.public static Matrix valueOf(XmlElement xml)
xml
- the XML element describing the matrix to return.
For example: <math:Matrix row="2" column="1"> <math:Complex real="1.0" imaginary="0.0"/> <math:Complex real="0.0" imaginary="1.0"/> </math:Matrix>
public final int getRowDimension()
public final int getColumnDimension()
public final boolean isSquare()
getRowDimension == getColumnDimension
public final Operable get(int i, int j)
i
- the row index (range [0..n[).j
- the column index (range [0..m[).
java.lang.IndexOutOfBoundsException
- i >= getRowDimension() |
j >= getColumnDimension()
.public final void set(int i, int j, Operable element)
i
- the row index (range [0..n[).j
- the column index (range [0..m[).element
- the element set at [i,j].
java.lang.IndexOutOfBoundsException
- i >= getRowDimension() |
j >= getColumnDimension()
.public final Matrix getMatrix(int i0, int i1, int j0, int j1)
i0
- the initial row index.i1
- the final row index.j0
- the initial column index.j1
- the final column index.
THIS(i0:i1, j0:j1)
public final Matrix getMatrix(int[] rows, int[] columns)
rows
- the indices of the rows to return.columns
- the indices of the columns to return.
public final LUDecomposition lu()
LUDecomposition
of this Matrix
.
Numerical stability is guaranteed (through pivoting) if the
Operable
elements of this matrix are derived
from java.lang.Number
. For others elements types,
numerical stability can be ensured by setting the
local pivot comparator
.
public final boolean equals(java.lang.Object that)
that
- the object to compare for equality.
true
if this matrix and the specified object are
considered equal; false
otherwise.public final int hashCode()
equals(java.lang.Object)
public final Matrix negate()
-this
.public final Matrix add(Matrix that)
that
- the matrix to be added.
this + that
.
DimensionException
- matrices's dimensions are different.public final Matrix subtract(Matrix that)
that
- the matrix to be subtracted.
this - that
.
DimensionException
- matrices's dimensions are different.public final Matrix multiply(Operable k)
k
- the coefficient multiplier.
k * M
.public Matrix multiply(Matrix that)
Note: This method uses ConcurrentContext
to reduce garbage
and accelerate calculation on multi-processor systems.
that
- the matrix multiplier.
this * that
.
DimensionException
- M.getRowDimension()
!= this.getColumnDimension()
.public Matrix divide(Matrix that)
that
- the matrix divisor.
this.multiply(that.inverse())
.public Matrix pseudoInverse()
public Matrix inverse()
Note: To resolve the equation A * X = B
,
it is usually faster to calculate A.lu().solve(B)
rather than A.inverse().times(B)
.
pseudoInverse()
if
the matrix is not square.lu()
public Matrix tensor(Matrix that)
that
- the second matrix.
this
and that
.public java.lang.String toString()
public Matrix transpose()
A'
.public Operable determinant()
lu().determinant()
DimensionException
- matrix is not square.public Operable 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 Operable trace()
public Matrix adjoint()
DimensionException
- if this matrix is not square or if
its dimension is less than 2.public Matrix pow(int exp)
exp
- the exponent.
thisexp
DimensionException
- if this matrix is not square.public Operable plus(Operable that)
Operable
plus
in interface Operable
that
- the object to be added.
this + that
.public Operable opposite()
Operable
this.plus(this.opposite()) == ZERO
,
with ZERO
being the additive identity.
opposite
in interface Operable
-this
.public Operable times(Operable that)
Operable
times
in interface Operable
that
- the object multiplier.
this * that
.public Operable reciprocal()
Operable
this.times(this.reciprocal()) == ONE
,
with ONE
being the multiplicative identity.
reciprocal
in interface Operable
ONE / this
.public void toXml(XmlElement xml)
Representable
toXml
in interface Representable
xml
- the XML element to set according to this object's desired XML
representation.public java.lang.Object export()
Realtime
Realtime
members are exported as well (recursion).
This method affects only objects belonging to the current pool context.
To avoid pool depletion, a "free" object from the outer pool
is moved to replace the object being exported.
export
in interface Realtime
export
in class RealtimeObject
public java.lang.Object toHeap()
Realtime
Realtime
members are moved to the heap as well (recursion).
This method affects only objects belonging to a pool context
(current or not).
toHeap
in interface Realtime
toHeap
in class RealtimeObject
|
JADE v6.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |