|
JScience v4.3 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.jscience.mathematics.vector.Matrix<F>
org.jscience.mathematics.vector.SparseMatrix<F>
public final class SparseMatrix<F extends Field<F>>
This class represents a matrix made of sparse
vectors (as rows). To create a sparse matrix made of column vectors the
transpose() method can be used.
For example:
SparseVector<Rational> column0 = SparseVector.valueOf(...);
SparseVector<Rational> column1 = SparseVector.valueOf(...);
SparseMatrix<Rational> M = SparseMatrix.valueOf(column0, column1).transpose();
As for any concrete structure, this class is declared final (otherwise most
operations would have to be overridden to return the appropriate type).
Specialized dense matrix should sub-class Matrix directly.
For example:
// Extension through composition.
final class BandMatrix <F extends Field<F>> extends Matrix<F> {
private SparseMatrix<F> _value;
...
public BandMatrix opposite() { // Returns the right type.
return BandMatrix.valueOf(_value.opposite());
}
...
}
| Field Summary |
|---|
| Fields inherited from class org.jscience.mathematics.vector.Matrix |
|---|
XML |
| Method Summary | ||
|---|---|---|
SparseMatrix<F> |
adjoint()
Returns the adjoint of this matrix. |
|
F |
cofactor(int i,
int j)
Returns the cofactor of an element in this matrix. |
|
SparseMatrix<F> |
copy()
Returns a copy of this matrix allocated
by the calling thread (possibly on the stack). |
|
F |
determinant()
Returns the determinant of this matrix. |
|
F |
get(int i,
int j)
Returns a single element from this matrix. |
|
SparseVector<F> |
getColumn(int j)
Returns the column identified by the specified index in this matrix. |
|
SparseVector<F> |
getDiagonal()
Returns the diagonal vector. |
|
int |
getNumberOfColumns()
Returns the number of columns n for this matrix. |
|
int |
getNumberOfRows()
Returns the number of rows m for this matrix. |
|
SparseVector<F> |
getRow(int i)
Returns the row identified by the specified index in this matrix. |
|
F |
getZero()
Returns the value of the non-set elements for this sparse matrix. |
|
SparseMatrix<F> |
inverse()
Returns the inverse of this matrix (must be square). |
|
SparseMatrix<F> |
minus(Matrix<F> that)
Returns the difference between this matrix and the one specified. |
|
SparseMatrix<F> |
opposite()
Returns the negation of this matrix. |
|
SparseMatrix<F> |
plus(Matrix<F> that)
Returns the sum of this matrix with the one specified. |
|
Matrix<F> |
solve(Matrix<F> y)
Solves this matrix for the specified matrix (returns x
such as this · x = y). |
|
SparseMatrix<F> |
tensor(Matrix<F> that)
Returns the linear algebraic matrix tensor product of this matrix and another (Kronecker product). |
|
SparseMatrix<F> |
times(F k)
Returns the product of this matrix by the specified factor. |
|
SparseMatrix<F> |
times(Matrix<F> that)
Returns the product of this matrix with the one specified. |
|
SparseVector<F> |
times(Vector<F> v)
Returns the product of this matrix by the specified vector. |
|
SparseMatrix<F> |
transpose()
Returns the transpose of this matrix. |
|
static
|
valueOf(java.util.List<SparseVector<F>> rows)
Returns a sparse matrix holding the row vectors from the specified collection (column vectors if transposed). |
|
static
|
valueOf(Matrix<F> that,
F zero)
Returns a sparse matrix equivalent to the specified matrix but with the zero elements removed using the default object equality comparator. |
|
static
|
valueOf(Matrix<F> that,
F zero,
javolution.util.FastComparator<? super F> comparator)
Returns a sparse matrix equivalent to the specified matrix but with the zero elements removed using the specified object equality comparator. |
|
static
|
valueOf(SparseVector<F>... rows)
Returns a sparse matrix holding the specified row vectors (column vectors if transposed). |
|
static
|
valueOf(Vector<F> diagonal,
F zero)
Returns the sparse square matrix having the specified diagonal vector. |
|
SparseVector<F> |
vectorization()
Returns the vectorization of this matrix. |
|
| Methods inherited from class org.jscience.mathematics.vector.Matrix |
|---|
divide, equals, equals, hashCode, isSquare, pow, pseudoInverse, solve, toString, toText, trace |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Method Detail |
|---|
public static <F extends Field<F>> SparseMatrix<F> valueOf(Vector<F> diagonal,
F zero)
SparseMatrix<Real> IDENTITY = Matrix.valueOf(
DenseVector.valueOf({Real.ONE, Real.ONE, Real.ONE}), Real.ZERO);
diagonal - the diagonal vector.zero - value of non-diagonal elements.
diagonal on the diagonal and
zero elsewhere.public static <F extends Field<F>> SparseMatrix<F> valueOf(SparseVector<F>... rows)
transposed).
rows - the row vectors.
DimensionException - if the rows do not have the same dimension.public static <F extends Field<F>> SparseMatrix<F> valueOf(java.util.List<SparseVector<F>> rows)
transposed).
rows - the list of row vectors.
DimensionException - if the rows do not have the same dimension.
public static <F extends Field<F>> SparseMatrix<F> valueOf(Matrix<F> that,
F zero)
that - the matrix to convert.zero - the zero element for the sparse vector to return.
SparseMatrix.valueOf(that, zero, FastComparator.DEFAULT) or a dense matrix holding the same elements
public static <F extends Field<F>> SparseMatrix<F> valueOf(Matrix<F> that,
F zero,
javolution.util.FastComparator<? super F> comparator)
that - the matrix to convert.zero - the zero element for the sparse vector to return.comparator - the comparator used to determinate zero equality.
that or a dense matrix holding the same elements
as the specified matrix.public F getZero()
public int getNumberOfRows()
Matrixm for this matrix.
getNumberOfRows in class Matrix<F extends Field<F>>public int getNumberOfColumns()
Matrixn for this matrix.
getNumberOfColumns in class Matrix<F extends Field<F>>
public F get(int i,
int j)
Matrix
get in class Matrix<F extends Field<F>>i - the row index (range [0..m[).j - the column index (range [0..n[).
public SparseVector<F> getRow(int i)
Matrix
getRow in class Matrix<F extends Field<F>>i - the row index (range [0..m[).
public SparseVector<F> getColumn(int j)
Matrix
getColumn in class Matrix<F extends Field<F>>j - the column index (range [0..n[).
public SparseVector<F> getDiagonal()
Matrix
getDiagonal in class Matrix<F extends Field<F>>public SparseMatrix<F> opposite()
Matrix
opposite in interface GroupAdditive<Matrix<F extends Field<F>>>opposite in class Matrix<F extends Field<F>>-this.public SparseMatrix<F> plus(Matrix<F> that)
Matrix
plus in interface GroupAdditive<Matrix<F extends Field<F>>>plus in class Matrix<F extends Field<F>>that - the matrix to be added.
this + that.public SparseMatrix<F> minus(Matrix<F> that)
Matrix
minus in class Matrix<F extends Field<F>>that - the matrix to be subtracted.
this - that.public SparseMatrix<F> times(F k)
Matrix
times in interface VectorSpace<Matrix<F extends Field<F>>,F extends Field<F>>times in class Matrix<F extends Field<F>>k - the coefficient multiplier.
this · kpublic SparseVector<F> times(Vector<F> v)
Matrix
times in class Matrix<F extends Field<F>>v - the vector.
this · vpublic SparseMatrix<F> times(Matrix<F> that)
Matrix
times in interface Ring<Matrix<F extends Field<F>>>times in class Matrix<F extends Field<F>>that - the matrix multiplier.
this · that.public SparseMatrix<F> inverse()
Matrix
inverse in class Matrix<F extends Field<F>>1 / thispublic F determinant()
Matrix
determinant in class Matrix<F extends Field<F>>public Matrix<F> solve(Matrix<F> y)
Matrixx
such as this · x = y).
solve in class Matrix<F extends Field<F>>y - the matrix for which the solution is calculated.
x such as this · x = ypublic SparseMatrix<F> transpose()
Matrix
transpose in class Matrix<F extends Field<F>>A'.
public F cofactor(int i,
int j)
Matrix
cofactor in class Matrix<F extends Field<F>>i - the row index.j - the column index.
THIS[i,j].public SparseMatrix<F> adjoint()
Matrix
adjoint in class Matrix<F extends Field<F>>public SparseMatrix<F> tensor(Matrix<F> that)
MatrixDenseMatrix.
tensor in class Matrix<F extends Field<F>>that - the second matrix.
this ⊗ thatpublic SparseVector<F> vectorization()
MatrixDenseVector.
vectorization in class Matrix<F extends Field<F>>public SparseMatrix<F> copy()
Matrixallocated
by the calling thread (possibly on the stack).
copy in interface javolution.lang.ValueTypecopy in class Matrix<F extends Field<F>>
|
JScience v4.3 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||