public interface RealMatrix extends AnyMatrix, Serializable
Matrix element indexing is 0-based -- e.g., getEntry(0, 0)
returns the element in
the first row, first column of the matrix.
Modifier and Type | Method and Description |
---|---|
RealMatrix |
add(RealMatrix m)
Returns the result of adding the matrix
m to this matrix. |
void |
addToEntry(int row,
int column,
double increment)
Adds (in place) a given value to the specified entry of this matrix.
|
RealMatrix |
concatenateDiagonally(RealMatrix m)
Diagonally concatenates this matrix and another matrix
m , placing it in the lower
right part of the concatenated matrix. |
RealMatrix |
concatenateDiagonally(RealMatrix m,
boolean lowerRightConcatenation)
Diagonally concatenates this matrix and another matrix
m , placing it in the lower
right or upper left part of the concatenated matrix. |
RealMatrix |
concatenateDiagonally(RealMatrix m,
boolean rightConcatenation,
boolean lowerConcatenation)
Diagonally or anti-diagonally concatenates this matrix and another matrix
m . |
RealMatrix |
concatenateHorizontally(RealMatrix m)
Horizontally concatenates this matrix and another matrix
m , placing it in the right
part of the concatenated matrix. |
RealMatrix |
concatenateHorizontally(RealMatrix m,
boolean rightConcatenation)
Horizontally concatenates this matrix and another matrix
m , , placing it in the left
or right part of the concatenated matrix. |
RealMatrix |
concatenateVertically(RealMatrix m)
Vertically concatenates this matrix and another matrix
m , placing it in the lower
part of the concatenated matrix. |
RealMatrix |
concatenateVertically(RealMatrix m,
boolean lowerConcatenation)
Vertically concatenates this matrix and another matrix
m , placing it in the lower or
upper part of the concatenated matrix. |
RealMatrix |
copy()
Returns a deep copy of this matrix.
|
void |
copySubMatrix(int[] selectedRows,
int[] selectedColumns,
double[][] destination)
Copies a submatrix into a given 2D array.
|
void |
copySubMatrix(int[] selectedRows,
int[] selectedColumns,
double[][] destination,
int startRowDest,
int startColumnDest)
Copies a submatrix into a given 2D array.
|
void |
copySubMatrix(int startRow,
int endRow,
int startColumn,
int endColumn,
double[][] destination)
Copies a submatrix into a given 2D array.
|
void |
copySubMatrix(int startRow,
int endRow,
int startColumn,
int endColumn,
double[][] destination,
int startRowDest,
int startColumnDest)
Copies a submatrix into a given 2D array.
|
RealMatrix |
createMatrix(int rowDimension,
int columnDimension)
Creates a new matrix of the same type as this matrix.
|
boolean |
equals(RealMatrix m,
double relativeTolerance,
double absoluteTolerance)
Is this matrix numerically equivalent to another matrix?
|
RealMatrix |
getAbs()
Returns the corresponding absolute values matrix.
|
double[] |
getColumn(int column)
Gets the entries of a given column.
|
RealMatrix |
getColumnMatrix(int column)
Gets the entries of a given column as a column matrix.
|
RealVector |
getColumnVector(int column)
Gets the entries of a given column as a vector.
|
double[][] |
getData()
Returns a 2D array containing the entries of the matrix.
|
double[][] |
getData(boolean forceCopy)
Returns a 2D array containing the entries of the matrix.
|
Function<RealMatrix,Decomposition> |
getDefaultDecomposition()
Gets the decomposition builder the
getInverse() method uses
by default when computing the inverse of the matrix. |
double[] |
getDiagonal()
Gets the diagonal vector from this matrix.
|
double |
getEntry(int row,
int column)
Gets the entry at the specified row and column.
|
double |
getFrobeniusNorm()
Returns the Frobenius norm of
the matrix.
|
RealMatrix |
getInverse()
Gets the inverse (or pseudo-inverse) of this matrix using the default decomposition.
|
RealMatrix |
getInverse(Function<RealMatrix,Decomposition> decompositionBuilder)
Gets the inverse (or pseudo-inverse) of this matrix using the given decomposition algorithm.
|
default double |
getMax()
Returns the maximum value of the matrix.
|
double |
getMax(boolean absValue)
Returns the maximum value of the matrix.
|
default double |
getMin()
Returns the minimum value of the matrix.
|
double |
getMin(boolean absValue)
Returns the minimum value of the matrix.
|
double |
getNorm()
Returns the maximum
absolute row sum norm of the matrix.
|
double[] |
getRow(int row)
Gets the entries of a given row.
|
RealMatrix |
getRowMatrix(int row)
Gets the entries of a given row as a row matrix.
|
RealVector |
getRowVector(int row)
Gets the entries of a given row as a vector.
|
RealMatrix |
getSubMatrix(int[] selectedRows,
int[] selectedColumns)
Gets a submatrix.
|
RealMatrix |
getSubMatrix(int startRow,
int endRow,
int startColumn,
int endColumn)
Gets a submatrix.
|
double |
getTrace()
Returns the trace of the matrix
(the sum of the elements on the main diagonal).
|
boolean |
isAntisymmetric(double relativeTolerance,
double absoluteTolerance)
Is this a antisymmetric matrix?
|
boolean |
isDiagonal(double absoluteTolerance)
Is this a diagonal matrix?
|
boolean |
isInvertible(double relativeTolerance)
Is this an invertible matrix?
|
boolean |
isOrthogonal(double normalityThreshold,
double orthogonalityThreshold)
Is this an orthogonal matrix?
|
boolean |
isSymmetric()
Is this a symmetric matrix?
|
boolean |
isSymmetric(double relativeTolerance)
Is this a symmetric matrix?
|
boolean |
isSymmetric(double relativeTolerance,
double absoluteTolerance)
Is this a symmetric matrix?
|
RealMatrix |
multiply(RealMatrix m)
Returns the result of postmultiplying this matrix by the matrix
m . |
RealMatrix |
multiply(RealMatrix m,
boolean toTranspose)
Returns the result of postmultiplying this matrix by the matrix
m or its transpose
m T. |
RealMatrix |
multiply(RealMatrix m,
boolean toTranspose,
double d)
Returns the result of postmultiplying this matrix by the matrix
m or its transpose
m T, then by the scalar d . |
void |
multiplyEntry(int row,
int column,
double factor)
Multiplies (in place) the specified entry of
this matrix by a given value. |
double[] |
operate(double[] v)
Returns the result of postmultiplying this matrix by the vector
v . |
RealVector |
operate(RealVector v)
Returns the result of postmultiplying this matrix by the vector
v . |
RealMatrix |
power(int p)
Returns the the result of multiplying this matrix with itself
p times. |
double[] |
preMultiply(double[] v)
Returns the result of premultiplying this matrix by the vector
v . |
RealMatrix |
preMultiply(RealMatrix m)
Returns the result of premultiplying this matrix by the matrix
m . |
RealVector |
preMultiply(RealVector v)
Returns the result of premultiplying this matrix by the vector
v . |
RealMatrix |
scalarAdd(double d)
Returns the result of adding a scalar
d to the entries of this matrix. |
RealMatrix |
scalarMultiply(double d)
Returns the result of multiplying the entries of this matrix by the scalar
d . |
void |
setColumn(int column,
double[] array)
Replaces the entries of a given column with the entries of the specified data array.
|
void |
setColumnMatrix(int column,
RealMatrix matrix)
Replaces the entries of a given column with the entries of the specified column matrix.
|
void |
setColumnVector(int column,
RealVector vector)
Replaces the entries of a given column with the entries of the specified vector.
|
void |
setDefaultDecomposition(Function<RealMatrix,Decomposition> defaultDecompositionBuilder)
Sets the decomposition builder the
getInverse() method should
use by default when computing the inverse of the matrix. |
void |
setEntry(int row,
int column,
double value)
Sets the entry at the specified row and column to a new value.
|
void |
setRow(int row,
double[] array)
Replaces the entries of a given row with the entries of the specified data array.
|
void |
setRowMatrix(int row,
RealMatrix matrix)
Replaces the entries of a given row with the entries of the specified row matrix.
|
void |
setRowVector(int row,
RealVector vector)
Replaces the entries of a given row with the entries of the specified vector.
|
void |
setSubMatrix(double[][] subMatrix,
int row,
int column)
Replaces part of the matrix with a given submatrix, starting at the specified row and column.
|
RealMatrix |
subtract(RealMatrix m)
Returns the result of subtracting the matrix
m from this matrix. |
String |
toString(RealMatrixFormat realMatrixFormat)
Gets a string representation of this matrix using the specified format.
|
RealMatrix |
transpose()
Returns the transpose of this matrix.
|
RealMatrix |
transpose(boolean forceCopy)
Returns the transpose of this matrix.
|
double |
walkInColumnOrder(RealMatrixChangingVisitor visitor)
Visits (and possibly change) all matrix entries in column order.
|
double |
walkInColumnOrder(RealMatrixChangingVisitor visitor,
int startRow,
int endRow,
int startColumn,
int endColumn)
Visits (and possibly change) some matrix entries in column order.
|
double |
walkInColumnOrder(RealMatrixPreservingVisitor visitor)
Visits (but don't change) all matrix entries in column order.
|
double |
walkInColumnOrder(RealMatrixPreservingVisitor visitor,
int startRow,
int endRow,
int startColumn,
int endColumn)
Visits (but don't change) some matrix entries in column order.
|
double |
walkInOptimizedOrder(RealMatrixChangingVisitor visitor)
Visits (and possibly change) all matrix entries using the fastest possible order.
|
double |
walkInOptimizedOrder(RealMatrixChangingVisitor visitor,
int startRow,
int endRow,
int startColumn,
int endColumn)
Visits (and possibly change) some matrix entries using the fastest possible order.
|
double |
walkInOptimizedOrder(RealMatrixPreservingVisitor visitor)
Visits (but don't change) all matrix entries using the fastest possible order.
|
double |
walkInOptimizedOrder(RealMatrixPreservingVisitor visitor,
int startRow,
int endRow,
int startColumn,
int endColumn)
Visits (but don't change) some matrix entries using the fastest possible order.
|
double |
walkInRowOrder(RealMatrixChangingVisitor visitor)
Visits (and possibly change) all matrix entries in row order.
|
double |
walkInRowOrder(RealMatrixChangingVisitor visitor,
int startRow,
int endRow,
int startColumn,
int endColumn)
Visits (and possibly change) some matrix entries in row order.
|
double |
walkInRowOrder(RealMatrixPreservingVisitor visitor)
Visits (but don't change) all matrix entries in row order.
|
double |
walkInRowOrder(RealMatrixPreservingVisitor visitor,
int startRow,
int endRow,
int startColumn,
int endColumn)
Visits (but don't change) some matrix entries in row order.
|
getColumnDimension, getRowDimension, isSquare
RealMatrix createMatrix(int rowDimension, int columnDimension)
The returned matrix is filled with zeros. Its size is determined by the specified row and column dimensions, which must both be strictly positive. Additional constraints on the dimensions may apply depending on the implementation (for example, symmetric matrices must be square, which implies that the row and column dimensions must be equal).
rowDimension
- the number of rows in the new matrixcolumnDimension
- the number of columns in the new matrixNotStrictlyPositiveException
- if row or column dimension is not positive.RealMatrix copy()
RealMatrix add(RealMatrix m)
m
to this matrix.m
- the matrix to be addedthis
+m
MatrixDimensionMismatchException
- if the matrix M is not the same size as this matrixRealMatrix subtract(RealMatrix m)
m
from this matrix.m
- the matrix to be subtractedthis
-m
MatrixDimensionMismatchException
- if the matrix m
is not the same size as this matrixRealMatrix scalarAdd(double d)
d
to the entries of this matrix.d
- the scalar value to be added to the entries of this matrixthis
+d
RealMatrix scalarMultiply(double d)
d
.d
- the scalar value by which to multiply the entries of this matrix bythis
×d
RealMatrix multiply(RealMatrix m)
m
.m
- the matrix by which to postmultiply this matrix bythis
×m
DimensionMismatchException
- if the matrices are not multiplication compatibleRealMatrix multiply(RealMatrix m, boolean toTranspose)
m
or its transpose
m
T.m
- the matrix by which to postmultiply this matrix bytoTranspose
- whether to compute the product this
×m
(toTranspose=false
), or the product this
×m
T (toTranspose=true
)this
×m
or this
×m
TDimensionMismatchException
- if the matrices are not multiplication compatibleRealMatrix multiply(RealMatrix m, boolean toTranspose, double d)
m
or its transpose
m
T, then by the scalar d
.m
- the matrix by which to multiply this matrix bytoTranspose
- whether to compute the product this
×m
×d
(
toTranspose=false
), or the product this
×m
T×d
(toTranspose=true
)d
- the scalar by which to multiply the resulting matrix bythis
×m
×d
or
this
×m
T×d
DimensionMismatchException
- if the matrices are not multiplication compatibleRealMatrix preMultiply(RealMatrix m)
m
.m
- the matrix M by which to premultiply this matrix bym
×this
DimensionMismatchException
- if the matrices are not multiplication compatibleRealMatrix power(int p)
p
times.
The exponent p
must be positive or equal to zero.
This operation is only supported for square matrices.
Depending on the underlying storage, numerical instabilities might occur for high powers.
p
- the exponent p
to which this matrix is to be raisedp
NotPositiveException
- if the exponent p
is negativeNonSquareMatrixException
- if this matrix is not squareRealMatrix concatenateHorizontally(RealMatrix m)
m
, placing it in the right
part of the concatenated matrix.m
- the matrix to be concatenated with this matrixDimensionMismatchException
- if the matrices have different row dimensionsRealMatrix concatenateHorizontally(RealMatrix m, boolean rightConcatenation)
m
, , placing it in the left
or right part of the concatenated matrix.
The way the two matrices are concatenated depends on the provided argument:
The matrix m
is placed in the right part of the concatenated matrix if
rightConcatenation
is set to true
, and in its left part if it is set to
false
.
Usage examples:
this.concatenateHorizontally(m, true) => [this, m] this.concatenateHorizontally(m, false) => [m, this]
m
- the matrix to be concatenated with this matrixrightConcatenation
- whether the matrix m
is to be placed in the right (true
) or left (
false
) part of the concatenated matrixDimensionMismatchException
- if the matrices have different row dimensionsRealMatrix concatenateVertically(RealMatrix m)
m
, placing it in the lower
part of the concatenated matrix.m
- the matrix to be concatenated with this matrixDimensionMismatchException
- if the matrices have different column dimensionsRealMatrix concatenateVertically(RealMatrix m, boolean lowerConcatenation)
m
, placing it in the lower or
upper part of the concatenated matrix.
The way the two matrices are concatenated depends on the provided argument:
The matrix m
is placed in the lower part of the concatenated matrix if
lowerConcatenation
is set to true
, and in its upper part if it is set to
false
.
Usage examples:
this.concatenateVertically(m, true) => [this] [ m] this.concatenateVertically(m, false) => [ m] [this]
m
- the matrix to be concatenated with this matrixlowerConcatenation
- whether the matrix m
is to be placed in the lower (true
) or upper (
false
) part of the concatenated matrixDimensionMismatchException
- if the matrices have different row dimensionsRealMatrix concatenateDiagonally(RealMatrix m)
m
, placing it in the lower
right part of the concatenated matrix.m
- the matrix to be concatenated with this matrixRealMatrix concatenateDiagonally(RealMatrix m, boolean lowerRightConcatenation)
m
, placing it in the lower
right or upper left part of the concatenated matrix.
The way the two matrices are concatenated depends on the provided argument:
The matrix m
is placed in the lower right part of the concatenated matrix if
lowerRightConcatenation
is set to true
, and in its upper left part if it is
set to false
.
Usage examples:
this.concatenateDiagonally(m, true) => [this, 0] [ 0, m] this.concatenateDiagonally(m, false) => [m, 0] [0, this]
m
- the matrix to be concatenated with this matrixlowerRightConcatenation
- whether the matrix m
is to be placed in the lower right (true
) or
upper left (false
) part of the concatenated matrixRealMatrix concatenateDiagonally(RealMatrix m, boolean rightConcatenation, boolean lowerConcatenation)
m
.
The way the two matrices are concatenated depends on the provided arguments:
The matrix m
is placed in the right part of the concatenated matrix if
rightConcatenation
is set to true
, and in its left part if it is set to
false
. Similarly, the matrix m
is placed in the lower part of the
concatenated matrix if lowerConcatenation
is set to true
, and in its upper
part if it is set to false
. This matrix is then placed in the opposite part of the
concatenated matrix (as an example, if the provided matrix is placed in the upper left part,
this matrix will be placed in the lower right part, the remaining parts being filled with
zeros).
Usage examples:
// Diagonal concatenation this.concatenateDiagonally(m, true, true) => [this, 0] [ 0, m] this.concatenateDiagonally(m, false, false) => [m, 0] [0, this] // Anti-diagonal concatenation this.concatenateDiagonally(m, false, true) => [0, this] [m, 0] this.concatenateDiagonally(m, true, false) => [ 0, m] [this, 0]
m
- the matrix to be concatenated with this matrixrightConcatenation
- whether the matrix m
is to be placed in the right (true
) or left (
false
) part of the concatenated matrixlowerConcatenation
- whether the matrix m
is to be placed in the lower (true
) or upper (
false
) part of the concatenated matrixvoid setDefaultDecomposition(Function<RealMatrix,Decomposition> defaultDecompositionBuilder)
getInverse()
method should
use by default when computing the inverse of the matrix.defaultDecompositionBuilder
- the default decomposition builderFunction<RealMatrix,Decomposition> getDefaultDecomposition()
getInverse()
method uses
by default when computing the inverse of the matrix.RealMatrix getInverse()
The default decomposition builder can be changed using the
setDefaultDecomposition
method.
SingularMatrixException
- if the matrix is singulargetDefaultDecomposition()
,
setDefaultDecomposition(Function)
RealMatrix getInverse(Function<RealMatrix,Decomposition> decompositionBuilder)
The decomposition builder is a function capable of generating new instances of the decomposition algorithm to be used for the computation of the inverse matrix (like the QRDecomposition or the EigenDecomposition, for instance).
decompositionBuilder
- the decomposition builder to useSingularMatrixException
- if the matrix is singulardouble[][] getData()
double[][] getData(boolean forceCopy)
If forceCopy
is true
, the returned array is guaranteed to be free of
references to any internal data array (thus, can be safely modified). Otherwise, the returned
array may contain references to internal data arrays (for optimization purposes). Note that
setting forceCopy
to false
does not guarantee the returned array references
an internal data array. For instance, implementations that do not store the entries of the
matrix in a 2D array have to rebuild a new array each time this method is called, regardless
of this parameter.
forceCopy
- if true
, the entries of the matrix are systematically stored in a new array;
otherwise the returned array may reference internal data arraysdouble getTrace()
The trace of the matrix is only defined for square matrices.
NonSquareMatrixException
- if the matrix is not squaredouble getNorm()
double getFrobeniusNorm()
default double getMin()
double getMin(boolean absValue)
absValue
- Indicates if the absolute minimum value should be returneddefault double getMax()
double getMax(boolean absValue)
absValue
- Indicates if the absolute maximum value should be returnedRealMatrix getAbs()
RealMatrix getSubMatrix(int startRow, int endRow, int startColumn, int endColumn)
Rows and columns are indicated counting from 0 to n-1.
startRow
- the initial row indexendRow
- the final row index (inclusive)startColumn
- the initial column indexendColumn
- the final column index (inclusive)OutOfRangeException
- if the row/column indices are not validNumberIsTooSmallException
- if endRow < startRow
or endColumn < startColumn
.RealMatrix getSubMatrix(int[] selectedRows, int[] selectedColumns)
Rows and columns are indicated counting from 0 to n-1.
selectedRows
- the selected row indicesselectedColumns
- the selected column indicesNullArgumentException
- if the row or column selections are null
NoDataException
- if the row or column selections are empty (zero length)OutOfRangeException
- if the selected indices are not validdouble[] getDiagonal()
Note: The matrix needs to be square.
NonSquareMatrixException
- if the matrix is not squarevoid copySubMatrix(int startRow, int endRow, int startColumn, int endColumn, double[][] destination)
Rows and columns are indicated counting from 0 to n-1. The submatrix data is copied in the upper-left part of the destination array. Elements which are not overwritten by the submatrix data are left unchanged (for example, if the destination array is larger than the size of the extracted submatrix).
startRow
- the initial row indexendRow
- the final row index (inclusive)startColumn
- the initial column indexendColumn
- the final column index (inclusive)destination
- the 2D array where the submatrix data should be copiedOutOfRangeException
- if the row/column indices are not validNumberIsTooSmallException
- if endRow < startRow
or endColumn < startColumn
MatrixDimensionMismatchException
- if the destination array is too smallvoid copySubMatrix(int startRow, int endRow, int startColumn, int endColumn, double[][] destination, int startRowDest, int startColumnDest)
Rows and columns are indicated counting from 0 to n-1. The submatrix data is copied in the upper-left part of the destination array, starting at the specified row/column indices. Elements which are not overwritten by the submatrix data are left unchanged (for example, if the destination array is larger than the size of the extracted submatrix).
startRow
- the initial row indexendRow
- the final row index (inclusive)startColumn
- the initial column indexendColumn
- the final column index (inclusive)destination
- the 2D array where the submatrix data should be copiedstartRowDest
- the initial row index of the destination arraystartColumnDest
- the initial column index of the destination arrayOutOfRangeException
- if the row/column indices are not validNumberIsTooSmallException
- if endRow < startRow
or endColumn < startColumn
.MatrixDimensionMismatchException
- if the destination array is too smallvoid copySubMatrix(int[] selectedRows, int[] selectedColumns, double[][] destination)
Rows and columns are indicated counting from 0 to n-1. The submatrix data is copied in the upper-left part of the destination array. Elements which are not overwritten by the submatrix data are left unchanged (for example, if the destination array is larger than the size of the extracted submatrix).
selectedRows
- the selected row indicesselectedColumns
- the selected column indicesdestination
- the 2D array where the submatrix data should be copiedNullArgumentException
- if the row or column selections are null
NoDataException
- if the row or column selections are empty (zero length)OutOfRangeException
- if the selected indices are not validMatrixDimensionMismatchException
- if the destination array is too smallvoid copySubMatrix(int[] selectedRows, int[] selectedColumns, double[][] destination, int startRowDest, int startColumnDest)
Rows and columns are indicated counting from 0 to n-1. The submatrix data is copied in the upper-left part of the destination array, starting at the specified row/column indices. Elements which are not overwritten by the submatrix data are left unchanged (for example, if the destination array is larger than the size of the extracted submatrix).
selectedRows
- the selected row indicesselectedColumns
- the selected column indicesdestination
- the 2D array where the submatrix data should be copiedstartRowDest
- the initial row index of the destination arraystartColumnDest
- the initial column index of the destination arrayNullArgumentException
- if the row or column selections are null
NoDataException
- if the row or column selections are empty (zero length)OutOfRangeException
- if the selected indices are not validMatrixDimensionMismatchException
- if the destination array is too smallvoid setSubMatrix(double[][] subMatrix, int row, int column)
Rows and columns are indicated counting from 0 to n-1.
Usage example:
// Initial matrix matrix = [a00, a10, a20] [a10, a11, a21] [a20, a21, a22] // Submatrix subMatrix = [b00, b01] [b10, b11] // Replace part of the initial matrix matrix.setSubMatrix(subMatrix, 1, 1) =>[a00, a10, a20] [a10, b00, b01] [a20, b10, b11]
subMatrix
- the array containing the submatrix replacement datarow
- the row coordinate of the top, left element to be replacedcolumn
- the column coordinate of the top, left element to be replacedNullArgumentException
- if the input submatrix array is null
NoDataException
- if the input submatrix array is emptyDimensionMismatchException
- if the rows of the input submatrix array have different lengthsOutOfRangeException
- if the input submatrix array does not fit into this matrix when starting from the
specified top, left elementRealMatrix getRowMatrix(int row)
Row indices start at 0.
row
- the index of the row to be fetchedOutOfRangeException
- if the specified row index is invalidvoid setRowMatrix(int row, RealMatrix matrix)
Row indices start at 0.
The provided matrix must have one row and the same number of columns as this matrix.
row
- the index of the row to be replacedmatrix
- the row matrix to be copiedOutOfRangeException
- if the specified row index is invalidMatrixDimensionMismatchException
- if the row dimension of the provided matrix is not 1, or if its column dimension does
not match the column dimension of this matrixRealMatrix getColumnMatrix(int column)
Column indices start at 0.
column
- the index of the column to be fetchedOutOfRangeException
- if the specified column index is invalidvoid setColumnMatrix(int column, RealMatrix matrix)
Column indices start at 0.
The provided matrix must have one column and the same number of rows as this matrix.
column
- the index of the column to be replacedmatrix
- the column matrix to be copiedOutOfRangeException
- if the specified column index is invalidMatrixDimensionMismatchException
- if the column dimension of the provided matrix is not 1, or if its row dimension does
not match the row dimension of this matrixRealVector getRowVector(int row)
Row indices start at 0.
row
- the index of the row to be fetchedOutOfRangeException
- if the specified row index is invalidvoid setRowVector(int row, RealVector vector)
Row indices start at 0.
The size of the provided vector must match the column dimension of this matrix.
row
- the index of the row to be replacedvector
- the row vector to be copiedOutOfRangeException
- if the specified row index is invalidMatrixDimensionMismatchException
- if the dimension of the provided vector does not match the column dimension of this
matrixRealVector getColumnVector(int column)
Column indices start at 0.
column
- the index of the column to be fetchedOutOfRangeException
- if the specified column index is invalidvoid setColumnVector(int column, RealVector vector)
Column indices start at 0.
The size of the provided vector must match the row dimension of this matrix.
column
- the index of the column to be replacedvector
- the column vector to be copiedOutOfRangeException
- if the specified column index is invalidMatrixDimensionMismatchException
- if the dimension of the provided vector does not match the row dimension of this
matrixdouble[] getRow(int row)
Row indices start at 0.
row
- the index of the row to be fetchedOutOfRangeException
- if the specified row index is invalidvoid setRow(int row, double[] array)
Row indices start at 0.
The size of the provided data array must match the column dimension of this matrix.
row
- the index of the row to be replacedarray
- the row data array to be copiedOutOfRangeException
- if the specified row index is invalidMatrixDimensionMismatchException
- if the length of the provided data array does not match the column dimension of this
matrixdouble[] getColumn(int column)
Column indices start at 0.
column
- the index of the column to be fetchedOutOfRangeException
- if the specified column index is invalidvoid setColumn(int column, double[] array)
Column indices start at 0.
The size of the provided data array must match the row dimension of this matrix.
column
- the index of the column to be replacedarray
- the column data array to be copiedOutOfRangeException
- if the specified column index is invalidMatrixDimensionMismatchException
- if the length of the provided data array does not match the row dimension of this
matrixdouble getEntry(int row, int column)
Row and column indices start at 0.
row
- the row index of entry to be fetchedcolumn
- the column index of entry to be fetchedOutOfRangeException
- if the row or column index is not validvoid setEntry(int row, int column, double value)
Row and column indices start at 0.
row
- the row index of entry to be setcolumn
- the column index of entry to be setvalue
- the new value of the entryOutOfRangeException
- if the row or column index is not validvoid addToEntry(int row, int column, double increment)
Row and column indices start at 0.
row
- the row index of the entry to be modifiedcolumn
- the column index of the entry to be modifiedincrement
- the value to add to the matrix entryOutOfRangeException
- if the row or column index is not validvoid multiplyEntry(int row, int column, double factor)
this
matrix by a given value.
Row and column indices start at 0.
row
- the row index of the entry to be modifiedcolumn
- the column index of the entry to be modifiedfactor
- the multiplication factor for the matrix entryOutOfRangeException
- if the row or column index is not validRealMatrix transpose()
RealMatrix transpose(boolean forceCopy)
If forceCopy
is true
, the returned matrix is guaranteed to be a new instance,
which can be modified without any risk of impacting the current instance. Otherwise, this
method may simply return the current instance when the matrix is its own transpose (symmetric
matrix).
forceCopy
- if true
, the transpose of the matrix is systematically stored in a new matrix;
otherwise the method may return the current instance when the matrix is its own
transposeboolean isOrthogonal(double normalityThreshold, double orthogonalityThreshold)
This method indicates if this matrix is orthogonal, taking into account the specified
tolerances.
To do so, the method checks if the columns of the matrix form an orthonormal set (that is,
the column vectors are orthogonal to each other and their norm is numerically equal to 1).
This method systematically returns false
for non-square matrices.
normalityThreshold
- the relative tolerance to take into account when checking the normality of the the
column vectorsorthogonalityThreshold
- the absolute tolerance to take into account when checking the mutual orthogonality of
the the column vectorstrue
if this is an orthogonal matrix, false
otherwiseboolean isDiagonal(double absoluteTolerance)
This method indicates if the matrix is diagonal, taking into account the specified tolerance.
To do so, the method checks if the off-diagonal elements are numerically equal to zero.
This method systematically returns false
for non-square matrices.
absoluteTolerance
- the absolute threshold above which the absolute value of an off-diagonal element is
considered to be strictly positivetrue
if this is a diagonal matrix, false
otherwiseboolean isInvertible(double relativeTolerance)
This method indicates if the matrix is invertible, taking into account the specified
tolerance.
To do so, the method checks the linear independence between the column vectors of the matrix.
Two columns are considered to be linearly dependent if their dot product is numerically equal
to the product of their norm.
This method systematically returns false
for non-square matrices.
relativeTolerance
- the relative tolerance to take into account when checking the independence of the
column vectorstrue
if this is an invertible matrix, false
otherwiseboolean isSymmetric()
This method indicates if the matrix is symmetric.
To do so, the method checks that symmetric off-diagonal elements are numerically equal. Two
elements are considered to have different values if their absolute and relative differences
are both above the default tolerances.
This method systematically returns false
for non-square matrices.
true
if this is a symmetric matrix, false
otherwiseboolean isSymmetric(double relativeTolerance)
This method indicates if the matrix is symmetric.
To do so, the method checks that symmetric off-diagonal elements are numerically equal. Two
elements are considered to have different values if their relative difference is above the
specified tolerance.
This method systematically returns false
for non-square matrices.
relativeTolerance
- the relative tolerance to take into account when comparing off-diagonal elementstrue
if this is a symmetric matrix, false
otherwiseboolean isSymmetric(double relativeTolerance, double absoluteTolerance)
This method indicates if the matrix is symmetric.
To do so, the method checks that symmetric off-diagonal elements are numerically equal. Two
elements are considered to have different values if their absolute and relative differences
are both above the specified tolerances.
This method systematically returns false
for non-square matrices.
relativeTolerance
- the relative tolerance to take into account when comparing off-diagonal elementsabsoluteTolerance
- the absolute tolerance to take into account when comparing off-diagonal elementstrue
if this is a symmetric matrix, false
otherwiseboolean isAntisymmetric(double relativeTolerance, double absoluteTolerance)
This method indicates if the matrix is antisymmetric.
To do so, the method checks that symmetric off-diagonal elements have numerically equal
values but opposite signs, and that diagonal elements are numerically equal to zero. Two
off-diagonal elements are considered to have different values if their absolute and relative
differences are both above the specified tolerances. Diagonal elements are considered to be
different from zero if their absolute value is greater than the specified absolute tolerance.
This method systematically returns false
for non-square matrices.
relativeTolerance
- the relative tolerance to take into account when comparing off-diagonal elementsabsoluteTolerance
- the absolute tolerance to take into account when comparing off-diagonal elements, and
when checking if diagonal elements are
equal to zerotrue
if this is an antisymmetric matrix, false
otherwisedouble[] operate(double[] v)
v
.v
- the vector by which to multiply this matrix bythis
×v
DimensionMismatchException
- if the length of provided array does not match the column dimension of this matrixRealVector operate(RealVector v)
v
.v
- the vector by which to multiply this matrix bythis
×v
DimensionMismatchException
- if the dimension of the provided vector does not match the column dimension of this
matrixdouble[] preMultiply(double[] v)
v
.v
- the row vector by which to premultiply this matrix byv
×this
DimensionMismatchException
- if the length of the provided array does not match the row dimension of this matrixRealVector preMultiply(RealVector v)
v
.v
- the vector by which to premultiply this matrix byv
×this
DimensionMismatchException
- if the dimension of the provided vector does not match the row dimension of this
matrixdouble walkInRowOrder(RealMatrixChangingVisitor visitor)
Row order starts at upper left element, iterating through all elements of a row from left to right before going to the leftmost element of the next row.
visitor
- the visitor used to process all matrix entriesRealMatrixChangingVisitor.end()
at the end of the walkwalkInRowOrder(RealMatrixPreservingVisitor)
,
walkInRowOrder(RealMatrixChangingVisitor, int, int, int, int)
,
walkInRowOrder(RealMatrixPreservingVisitor, int, int, int, int)
,
walkInColumnOrder(RealMatrixChangingVisitor)
,
walkInColumnOrder(RealMatrixPreservingVisitor)
,
walkInColumnOrder(RealMatrixChangingVisitor, int, int, int, int)
,
walkInColumnOrder(RealMatrixPreservingVisitor, int, int, int, int)
,
walkInOptimizedOrder(RealMatrixChangingVisitor)
,
walkInOptimizedOrder(RealMatrixPreservingVisitor)
,
walkInOptimizedOrder(RealMatrixChangingVisitor, int, int, int, int)
,
walkInOptimizedOrder(RealMatrixPreservingVisitor, int, int, int, int)
double walkInRowOrder(RealMatrixPreservingVisitor visitor)
Row order starts at upper left element, iterating through all elements of a row from left to right before going to the leftmost element of the next row.
visitor
- the visitor used to process all matrix entriesRealMatrixPreservingVisitor.end()
at the end of the
walkwalkInRowOrder(RealMatrixChangingVisitor)
,
walkInRowOrder(RealMatrixChangingVisitor, int, int, int, int)
,
walkInRowOrder(RealMatrixPreservingVisitor, int, int, int, int)
,
walkInColumnOrder(RealMatrixChangingVisitor)
,
walkInColumnOrder(RealMatrixPreservingVisitor)
,
walkInColumnOrder(RealMatrixChangingVisitor, int, int, int, int)
,
walkInColumnOrder(RealMatrixPreservingVisitor, int, int, int, int)
,
walkInOptimizedOrder(RealMatrixChangingVisitor)
,
walkInOptimizedOrder(RealMatrixPreservingVisitor)
,
walkInOptimizedOrder(RealMatrixChangingVisitor, int, int, int, int)
,
walkInOptimizedOrder(RealMatrixPreservingVisitor, int, int, int, int)
double walkInRowOrder(RealMatrixChangingVisitor visitor, int startRow, int endRow, int startColumn, int endColumn)
Row order starts at upper left element, iterating through all elements of a row from left to right before going to the leftmost element of the next row.
visitor
- the visitor used to process all matrix entriesstartRow
- the initial row indexendRow
- the final row index (inclusive)startColumn
- the initial column indexendColumn
- the final column indexRealMatrixChangingVisitor.end()
at the end of the walkOutOfRangeException
- if the specified indices are not validNumberIsTooSmallException
- if endRow < startRow
or endColumn < startColumn
walkInRowOrder(RealMatrixChangingVisitor)
,
walkInRowOrder(RealMatrixPreservingVisitor)
,
walkInRowOrder(RealMatrixPreservingVisitor, int, int, int, int)
,
walkInColumnOrder(RealMatrixChangingVisitor)
,
walkInColumnOrder(RealMatrixPreservingVisitor)
,
walkInColumnOrder(RealMatrixChangingVisitor, int, int, int, int)
,
walkInColumnOrder(RealMatrixPreservingVisitor, int, int, int, int)
,
walkInOptimizedOrder(RealMatrixChangingVisitor)
,
walkInOptimizedOrder(RealMatrixPreservingVisitor)
,
walkInOptimizedOrder(RealMatrixChangingVisitor, int, int, int, int)
,
walkInOptimizedOrder(RealMatrixPreservingVisitor, int, int, int, int)
double walkInRowOrder(RealMatrixPreservingVisitor visitor, int startRow, int endRow, int startColumn, int endColumn)
Row order starts at upper left element, iterating through all elements of a row from left to right before going to the leftmost element of the next row.
visitor
- the visitor used to process all matrix entriesstartRow
- the initial row indexendRow
- the final row index (inclusive)startColumn
- the initial column indexendColumn
- the final column indexRealMatrixPreservingVisitor.end()
at the end of the
walkOutOfRangeException
- if the specified indices are not validNumberIsTooSmallException
- if endRow < startRow
or endColumn < startColumn
walkInRowOrder(RealMatrixChangingVisitor)
,
walkInRowOrder(RealMatrixPreservingVisitor)
,
walkInRowOrder(RealMatrixChangingVisitor, int, int, int, int)
,
walkInColumnOrder(RealMatrixChangingVisitor)
,
walkInColumnOrder(RealMatrixPreservingVisitor)
,
walkInColumnOrder(RealMatrixChangingVisitor, int, int, int, int)
,
walkInColumnOrder(RealMatrixPreservingVisitor, int, int, int, int)
,
walkInOptimizedOrder(RealMatrixChangingVisitor)
,
walkInOptimizedOrder(RealMatrixPreservingVisitor)
,
walkInOptimizedOrder(RealMatrixChangingVisitor, int, int, int, int)
,
walkInOptimizedOrder(RealMatrixPreservingVisitor, int, int, int, int)
double walkInColumnOrder(RealMatrixChangingVisitor visitor)
Column order starts at upper left element, iterating through all elements of a column from top to bottom before going to the topmost element of the next column.
visitor
- the visitor used to process all matrix entriesRealMatrixChangingVisitor.end()
at the end of the walkwalkInRowOrder(RealMatrixChangingVisitor)
,
walkInRowOrder(RealMatrixPreservingVisitor)
,
walkInRowOrder(RealMatrixChangingVisitor, int, int, int, int)
,
walkInRowOrder(RealMatrixPreservingVisitor, int, int, int, int)
,
walkInColumnOrder(RealMatrixPreservingVisitor)
,
walkInColumnOrder(RealMatrixChangingVisitor, int, int, int, int)
,
walkInColumnOrder(RealMatrixPreservingVisitor, int, int, int, int)
,
walkInOptimizedOrder(RealMatrixChangingVisitor)
,
walkInOptimizedOrder(RealMatrixPreservingVisitor)
,
walkInOptimizedOrder(RealMatrixChangingVisitor, int, int, int, int)
,
walkInOptimizedOrder(RealMatrixPreservingVisitor, int, int, int, int)
double walkInColumnOrder(RealMatrixPreservingVisitor visitor)
Column order starts at upper left element, iterating through all elements of a column from top to bottom before going to the topmost element of the next column.
visitor
- the visitor used to process all matrix entriesRealMatrixPreservingVisitor.end()
at the end of the
walkwalkInRowOrder(RealMatrixChangingVisitor)
,
walkInRowOrder(RealMatrixPreservingVisitor)
,
walkInRowOrder(RealMatrixChangingVisitor, int, int, int, int)
,
walkInRowOrder(RealMatrixPreservingVisitor, int, int, int, int)
,
walkInColumnOrder(RealMatrixChangingVisitor)
,
walkInColumnOrder(RealMatrixChangingVisitor, int, int, int, int)
,
walkInColumnOrder(RealMatrixPreservingVisitor, int, int, int, int)
,
walkInOptimizedOrder(RealMatrixChangingVisitor)
,
walkInOptimizedOrder(RealMatrixPreservingVisitor)
,
walkInOptimizedOrder(RealMatrixChangingVisitor, int, int, int, int)
,
walkInOptimizedOrder(RealMatrixPreservingVisitor, int, int, int, int)
double walkInColumnOrder(RealMatrixChangingVisitor visitor, int startRow, int endRow, int startColumn, int endColumn)
Column order starts at upper left element, iterating through all elements of a column from top to bottom before going to the topmost element of the next column.
visitor
- the visitor used to process all matrix entriesstartRow
- the initial row indexendRow
- the final row index (inclusive)startColumn
- the initial column indexendColumn
- the final column indexRealMatrixChangingVisitor.end()
at the end of the walkOutOfRangeException
- if the specified indices are not validNumberIsTooSmallException
- if endRow < startRow
or endColumn < startColumn
walkInRowOrder(RealMatrixChangingVisitor)
,
walkInRowOrder(RealMatrixPreservingVisitor)
,
walkInRowOrder(RealMatrixChangingVisitor, int, int, int, int)
,
walkInRowOrder(RealMatrixPreservingVisitor, int, int, int, int)
,
walkInColumnOrder(RealMatrixChangingVisitor)
,
walkInColumnOrder(RealMatrixPreservingVisitor)
,
walkInColumnOrder(RealMatrixPreservingVisitor, int, int, int, int)
,
walkInOptimizedOrder(RealMatrixChangingVisitor)
,
walkInOptimizedOrder(RealMatrixPreservingVisitor)
,
walkInOptimizedOrder(RealMatrixChangingVisitor, int, int, int, int)
,
walkInOptimizedOrder(RealMatrixPreservingVisitor, int, int, int, int)
double walkInColumnOrder(RealMatrixPreservingVisitor visitor, int startRow, int endRow, int startColumn, int endColumn)
Column order starts at upper left element, iterating through all elements of a column from top to bottom before going to the topmost element of the next column.
visitor
- the visitor used to process all matrix entriesstartRow
- the initial row indexendRow
- the final row index (inclusive)startColumn
- the initial column indexendColumn
- the final column indexRealMatrixPreservingVisitor.end()
at the end of the
walkOutOfRangeException
- if the specified indices are not validNumberIsTooSmallException
- if endRow < startRow
or endColumn < startColumn
walkInRowOrder(RealMatrixChangingVisitor)
,
walkInRowOrder(RealMatrixPreservingVisitor)
,
walkInRowOrder(RealMatrixChangingVisitor, int, int, int, int)
,
walkInRowOrder(RealMatrixPreservingVisitor, int, int, int, int)
,
walkInColumnOrder(RealMatrixChangingVisitor)
,
walkInColumnOrder(RealMatrixPreservingVisitor)
,
walkInColumnOrder(RealMatrixChangingVisitor, int, int, int, int)
,
walkInOptimizedOrder(RealMatrixChangingVisitor)
,
walkInOptimizedOrder(RealMatrixPreservingVisitor)
,
walkInOptimizedOrder(RealMatrixChangingVisitor, int, int, int, int)
,
walkInOptimizedOrder(RealMatrixPreservingVisitor, int, int, int, int)
double walkInOptimizedOrder(RealMatrixChangingVisitor visitor)
The fastest walking order depends on the exact matrix class. It may be different from traditional row or column orders.
visitor
- the visitor used to process all matrix entriesRealMatrixChangingVisitor.end()
at the end of the walkwalkInRowOrder(RealMatrixChangingVisitor)
,
walkInRowOrder(RealMatrixPreservingVisitor)
,
walkInRowOrder(RealMatrixChangingVisitor, int, int, int, int)
,
walkInRowOrder(RealMatrixPreservingVisitor, int, int, int, int)
,
walkInColumnOrder(RealMatrixChangingVisitor)
,
walkInColumnOrder(RealMatrixPreservingVisitor)
,
walkInColumnOrder(RealMatrixChangingVisitor, int, int, int, int)
,
walkInColumnOrder(RealMatrixPreservingVisitor, int, int, int, int)
,
walkInOptimizedOrder(RealMatrixPreservingVisitor)
,
walkInOptimizedOrder(RealMatrixChangingVisitor, int, int, int, int)
,
walkInOptimizedOrder(RealMatrixPreservingVisitor, int, int, int, int)
double walkInOptimizedOrder(RealMatrixPreservingVisitor visitor)
The fastest walking order depends on the exact matrix class. It may be different from traditional row or column orders.
visitor
- the visitor used to process all matrix entriesRealMatrixPreservingVisitor.end()
at the end of the
walkwalkInRowOrder(RealMatrixChangingVisitor)
,
walkInRowOrder(RealMatrixPreservingVisitor)
,
walkInRowOrder(RealMatrixChangingVisitor, int, int, int, int)
,
walkInRowOrder(RealMatrixPreservingVisitor, int, int, int, int)
,
walkInColumnOrder(RealMatrixChangingVisitor)
,
walkInColumnOrder(RealMatrixPreservingVisitor)
,
walkInColumnOrder(RealMatrixChangingVisitor, int, int, int, int)
,
walkInColumnOrder(RealMatrixPreservingVisitor, int, int, int, int)
,
walkInOptimizedOrder(RealMatrixChangingVisitor)
,
walkInOptimizedOrder(RealMatrixChangingVisitor, int, int, int, int)
,
walkInOptimizedOrder(RealMatrixPreservingVisitor, int, int, int, int)
double walkInOptimizedOrder(RealMatrixChangingVisitor visitor, int startRow, int endRow, int startColumn, int endColumn)
The fastest walking order depends on the exact matrix class. It may be different from traditional row or column orders.
visitor
- the visitor used to process all matrix entriesstartRow
- the initial row indexendRow
- the final row index (inclusive)startColumn
- the initial column indexendColumn
- the final column index (inclusive)RealMatrixChangingVisitor.end()
at the end of the walkOutOfRangeException
- if the specified indices are not validNumberIsTooSmallException
- if endRow < startRow
or endColumn < startColumn
walkInRowOrder(RealMatrixChangingVisitor)
,
walkInRowOrder(RealMatrixPreservingVisitor)
,
walkInRowOrder(RealMatrixChangingVisitor, int, int, int, int)
,
walkInRowOrder(RealMatrixPreservingVisitor, int, int, int, int)
,
walkInColumnOrder(RealMatrixChangingVisitor)
,
walkInColumnOrder(RealMatrixPreservingVisitor)
,
walkInColumnOrder(RealMatrixChangingVisitor, int, int, int, int)
,
walkInColumnOrder(RealMatrixPreservingVisitor, int, int, int, int)
,
walkInOptimizedOrder(RealMatrixChangingVisitor)
,
walkInOptimizedOrder(RealMatrixPreservingVisitor)
,
walkInOptimizedOrder(RealMatrixPreservingVisitor, int, int, int, int)
double walkInOptimizedOrder(RealMatrixPreservingVisitor visitor, int startRow, int endRow, int startColumn, int endColumn)
The fastest walking order depends on the exact matrix class. It may be different from traditional row or column orders.
visitor
- the visitor used to process all matrix entriesstartRow
- the initial row indexendRow
- the final row index (inclusive)startColumn
- the initial column indexendColumn
- the final column index (inclusive)RealMatrixPreservingVisitor.end()
at the end of the
walkOutOfRangeException
- if the specified indices are not validNumberIsTooSmallException
- if endRow < startRow
or endColumn < startColumn
walkInRowOrder(RealMatrixChangingVisitor)
,
walkInRowOrder(RealMatrixPreservingVisitor)
,
walkInRowOrder(RealMatrixChangingVisitor, int, int, int, int)
,
walkInRowOrder(RealMatrixPreservingVisitor, int, int, int, int)
,
walkInColumnOrder(RealMatrixChangingVisitor)
,
walkInColumnOrder(RealMatrixPreservingVisitor)
,
walkInColumnOrder(RealMatrixChangingVisitor, int, int, int, int)
,
walkInColumnOrder(RealMatrixPreservingVisitor, int, int, int, int)
,
walkInOptimizedOrder(RealMatrixChangingVisitor)
,
walkInOptimizedOrder(RealMatrixPreservingVisitor)
,
walkInOptimizedOrder(RealMatrixChangingVisitor, int, int, int, int)
String toString(RealMatrixFormat realMatrixFormat)
Several predefined matrix formats are available in MatrixUtils.
realMatrixFormat
- the matrix format to be usedMatrixUtils.JAVA_FORMAT
,
MatrixUtils.OCTAVE_FORMAT
,
MatrixUtils.VISUAL_FORMAT
,
MatrixUtils.SUMMARY_FORMAT
boolean equals(RealMatrix m, double relativeTolerance, double absoluteTolerance)
This method indicates if this matrix is equal to another matrix.
To do so, the method checks that the two matrices have the same row/column dimensions, and
that all entries are numerically equal. Two elements are considered to have different values
if their absolute and relative differences are both above the specified tolerances.
m
- the matrix to be tested for equalityrelativeTolerance
- the relative tolerance to take into account when comparing the entries of the matricesabsoluteTolerance
- the absolute tolerance to take into account when comparing the entries of the matricestrue
if the tested matrix is numerically equivalent to this matrix,
false
otherwiseCopyright © 2023 CNES. All rights reserved.