public class DiagonalMatrix extends AbstractRealMatrix implements SymmetricMatrix
This implementation only stores the diagonal elements of the matrix. Setting any off-diagonal element to a value that is not 0 is forbidden (otherwise the matrix would not be diagonal anymore) and attempting to do so will systematically result in a MathUnsupportedOperationException being thrown. As a result, any method which modifies the entries of the matrix (setRow, setColumn, setSubMatrix, etc) will most likely fail, unless only the diagonal elements are actually modified.
This class is up-to-date with commons-math 3.6.1, but has been mostly rewritten since.
Constructor and Description |
---|
DiagonalMatrix(double[] diagonalElements)
Creates a matrix using the value of the provided array as diagonal elements.
|
DiagonalMatrix(double[] diagonalElements,
boolean copyArray)
Creates a matrix using the value of the provided array as diagonal elements.
|
DiagonalMatrix(int n)
Creates a matrix with the supplied dimension.
|
Modifier and Type | Method and Description |
---|---|
DiagonalMatrix |
add(DiagonalMatrix m)
Returns the result of adding the diagonal matrix
m to this matrix. |
RealMatrix |
add(RealMatrix m)
Returns the result of adding the matrix
m to this matrix. |
SymmetricMatrix |
add(SymmetricMatrix m)
Returns the result of adding the symmetric 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.
|
protected static void |
checkDataArray(double[] data)
Checks the validity of the provided data array.
|
RealMatrix |
concatenateDiagonally(RealMatrix m,
boolean rightConcatenation,
boolean lowerConcatenation)
Diagonally or anti-diagonally concatenates this matrix and another matrix
m . |
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,
boolean lowerConcatenation)
Vertically concatenates this matrix and another matrix
m , placing it in the lower or
upper part of the concatenated matrix. |
DiagonalMatrix |
copy()
Returns a deep copy of this matrix.
|
static DiagonalMatrix |
createIdentityMatrix(int n)
Creates an identity matrix of the specified dimension.
|
DiagonalMatrix |
createMatrix(int rowDimension,
int columnDimension)
Creates a new matrix of the same type as this matrix.
|
boolean |
equals(Object object)
Returns
true if the provided object is a RealMatrix instance with the
same dimensions as this matrix, whose entries are strictly equal to the entries of this
matrix (no absolute or relative tolerance is taken into account when comparing the entries). |
RealMatrix |
getAbs()
Returns the corresponding absolute values matrix.
|
double[] |
getColumn(int column)
Gets the entries of a given column.
|
int |
getColumnDimension()
Returns the dimension of the domain of this operator.
|
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[] |
getDataRef()
Gets a reference to the internal data array storing the diagonal elements 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.
|
DiagonalMatrix |
getInverse()
Gets the inverse (or pseudo-inverse) of this matrix using the default decomposition.
|
DiagonalMatrix |
getInverse(Function<RealMatrix,Decomposition> decompositionBuilder)
Gets the inverse (or pseudo-inverse) of this matrix using the given decomposition algorithm.
|
double |
getMax(boolean absValue)
Returns the maximum 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.
|
int |
getRowDimension()
Returns the dimension of the codomain of this operator.
|
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.
|
ArrayRowSymmetricMatrix |
getSubMatrix(int[] indices)
Extracts the submatrix corresponding to the specified indices.
|
RealMatrix |
getSubMatrix(int[] selectedRows,
int[] selectedColumns)
Gets a submatrix.
|
DiagonalMatrix |
getSubMatrix(int startIndex,
int endIndex)
Extracts the submatrix corresponding to the specified indices.
|
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).
|
int |
hashCode()
Computes a hash code for the matrix.
|
boolean |
isAntisymmetric(double absoluteTolerance)
Checks if this is an antisymmetric matrix.
|
boolean |
isAntisymmetric(double relativeTolerance,
double absoluteTolerance)
Is this a antisymmetric matrix?
|
boolean |
isDiagonal(double threshold)
Is this a diagonal matrix?
|
boolean |
isInvertible()
Checks if the matrix is invertible.
|
boolean |
isInvertible(double absoluteTolerance)
Checks if the matrix is invertible.
|
boolean |
isOrthogonal(double thresholdNorm,
double thresholdOrthogonality)
Is this an orthogonal matrix?
|
boolean |
isSingular()
Checks whether this diagonal matrix is singular or not.
|
boolean |
isSingular(double absoluteTolerance)
Checks whether this diagonal matrix is singular or not.
|
boolean |
isSquare()
Is this a square 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?
|
DiagonalMatrix |
multiply(DiagonalMatrix m,
double d)
Returns the result of postmultiplying this matrix by the diagonal matrix
m , then by
the scalar d . |
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 multiplying
this by the vector x . |
DiagonalMatrix |
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 . |
RealVector |
preMultiply(RealVector v)
Returns the result of premultiplying this matrix by the vector
v . |
ArrayRowSymmetricMatrix |
quadraticMultiplication(RealMatrix m)
Returns the result of the quadratic multiplication M×
this ×MT,
where M is the provided matrix. |
ArrayRowSymmetricMatrix |
quadraticMultiplication(RealMatrix m,
boolean isTranspose)
Returns the result of the quadratic multiplication M×
this ×MT,
where M or MT is the provided matrix. |
ArrayRowSymmetricMatrix |
scalarAdd(double d)
Returns the result of adding a scalar
d to the entries of this matrix. |
DiagonalMatrix |
scalarMultiply(double d)
Returns the result of multiplying the entries of this matrix by the scalar
d . |
void |
setEntry(int row,
int column,
double value)
Sets the entry at the specified row and column to a new value.
|
void |
setSubMatrix(double[][] subMatrix,
int row,
int column)
Replaces part of the matrix with a given submatrix, starting at the specified row and column.
|
DiagonalMatrix |
subtract(DiagonalMatrix m)
Returns the result of subtracting the diagonal matrix
m from this matrix. |
RealMatrix |
subtract(RealMatrix m)
Returns the result of subtracting the matrix
m from this matrix. |
SymmetricMatrix |
subtract(SymmetricMatrix m)
Returns the result of subtracting the symmetric matrix
m from this matrix. |
DiagonalMatrix |
transpose()
Returns the transpose of this matrix.
|
DiagonalMatrix |
transpose(boolean forceCopy)
Returns the transpose of this matrix.
|
checkDestinationArray, checkSquare, concatenateDiagonally, concatenateDiagonally, concatenateHorizontally, concatenateVertically, copySubMatrix, copySubMatrix, copySubMatrix, copySubMatrix, equals, getData, getDefaultDecomposition, multiply, multiply, preMultiply, setColumn, setColumnMatrix, setColumnVector, setDefaultDecomposition, setRow, setRowMatrix, setRowVector, toString, toString, walkInColumnOrder, walkInColumnOrder, walkInColumnOrder, walkInColumnOrder, walkInOptimizedOrder, walkInOptimizedOrder, walkInOptimizedOrder, walkInOptimizedOrder, walkInRowOrder, walkInRowOrder, walkInRowOrder, walkInRowOrder
isTransposable, operateTranspose
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
concatenateDiagonally, concatenateDiagonally, concatenateHorizontally, concatenateVertically, copySubMatrix, copySubMatrix, copySubMatrix, copySubMatrix, equals, getData, getDefaultDecomposition, getMax, getMin, multiply, multiply, preMultiply, setColumn, setColumnMatrix, setColumnVector, setDefaultDecomposition, setRow, setRowMatrix, setRowVector, toString, walkInColumnOrder, walkInColumnOrder, walkInColumnOrder, walkInColumnOrder, walkInOptimizedOrder, walkInOptimizedOrder, walkInOptimizedOrder, walkInOptimizedOrder, walkInRowOrder, walkInRowOrder, walkInRowOrder, walkInRowOrder
public DiagonalMatrix(int n)
n
- the dimension of the matrixNotStrictlyPositiveException
- if the provided dimension is not positivepublic DiagonalMatrix(double[] diagonalElements)
The input array is copied, not referenced.
diagonalElements
- the diagonal elements of the matrixNullArgumentException
- if diagonalElements
is null
public DiagonalMatrix(double[] diagonalElements, boolean copyArray)
If an array is created specifically for this constructor (in order to be embedded in the
created instance and not used directly), copyArray
may be set to false
. This
will improve performance as no new array will be built and no data will be copied.
diagonalElements
- the diagonal elements of the matrixcopyArray
- if true
, the input array will be copied, otherwise it will be referencedNullArgumentException
- if diagonalElements
is null
protected static void checkDataArray(double[] data)
To be valid, the array must not be null
or empty.
data
- the data array to be checkedNullArgumentException
- if the data array is null
NoDataException
- if the data array is emptypublic int getRowDimension()
getRowDimension
in interface AnyMatrix
getRowDimension
in class AbstractRealMatrix
public int getColumnDimension()
getColumnDimension
in interface AnyMatrix
getColumnDimension
in class AbstractRealMatrix
public double[][] getData()
getData
in interface RealMatrix
getData
in class AbstractRealMatrix
public double[] getDataRef()
This method is only provided for optimization purposes.
Any modification made on the returned array will change the values of this matrix.
public double[] getDiagonal()
Note: The matrix needs to be square.
getDiagonal
in interface RealMatrix
getDiagonal
in interface SymmetricMatrix
getDiagonal
in class AbstractRealMatrix
public double getTrace()
The trace of the matrix is only defined for square matrices.
getTrace
in interface RealMatrix
getTrace
in class AbstractRealMatrix
public double getNorm()
getNorm
in interface RealMatrix
getNorm
in class AbstractRealMatrix
public double getFrobeniusNorm()
getFrobeniusNorm
in interface RealMatrix
getFrobeniusNorm
in class AbstractRealMatrix
public double getMin(boolean absValue)
getMin
in interface RealMatrix
getMin
in class AbstractRealMatrix
absValue
- Indicates if the absolute minimum value should be returnedpublic double getMax(boolean absValue)
getMax
in interface RealMatrix
getMax
in class AbstractRealMatrix
absValue
- Indicates if the absolute maximum value should be returnedpublic RealMatrix getAbs()
getAbs
in interface RealMatrix
getAbs
in class AbstractRealMatrix
public double getEntry(int row, int column)
Row and column indices start at 0.
getEntry
in interface RealMatrix
getEntry
in class AbstractRealMatrix
row
- the row index of entry to be fetchedcolumn
- the column index of entry to be fetchedpublic void setEntry(int row, int column, double value)
Row and column indices start at 0.
Important:
This method throws a NumberIsTooLargeException when asked to set an
extra-diagonal element to a non-zero value, since this operation is not allowed when dealing
with diagonal matrices (the properties of the matrix are not guaranteed to be preserved).
setEntry
in interface RealMatrix
setEntry
in class AbstractRealMatrix
row
- the row index of entry to be setcolumn
- the column index of entry to be setvalue
- the new value of the entryNumberIsTooLargeException
- if the method is asked to set an extra-diagonal element to a non-zero valuepublic void addToEntry(int row, int column, double increment)
Row and column indices start at 0.
Important:
This method throws a NumberIsTooLargeException when asked to add a non-zero
value to an extra-diagonal element, since this operation is not allowed when dealing with
diagonal matrices (the properties of the matrix are not guaranteed to be preserved).
addToEntry
in interface RealMatrix
addToEntry
in class AbstractRealMatrix
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 entryNumberIsTooLargeException
- if the method is asked to add a non-zero value to an extra-diagonal elementpublic void multiplyEntry(int row, int column, double factor)
this
matrix by a given value.
Row and column indices start at 0.
multiplyEntry
in interface RealMatrix
multiplyEntry
in class AbstractRealMatrix
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 entrypublic double[] getRow(int row)
Row indices start at 0.
getRow
in interface RealMatrix
getRow
in class AbstractRealMatrix
row
- the index of the row to be fetchedpublic RealVector getRowVector(int row)
Row indices start at 0.
getRowVector
in interface RealMatrix
getRowVector
in class AbstractRealMatrix
row
- the index of the row to be fetchedpublic RealMatrix getRowMatrix(int row)
Row indices start at 0.
getRowMatrix
in interface RealMatrix
getRowMatrix
in class AbstractRealMatrix
row
- the index of the row to be fetchedpublic double[] getColumn(int column)
Column indices start at 0.
getColumn
in interface RealMatrix
getColumn
in class AbstractRealMatrix
column
- the index of the column to be fetchedpublic RealVector getColumnVector(int column)
Column indices start at 0.
getColumnVector
in interface RealMatrix
getColumnVector
in class AbstractRealMatrix
column
- the index of the column to be fetchedpublic RealMatrix getColumnMatrix(int column)
Column indices start at 0.
getColumnMatrix
in interface RealMatrix
getColumnMatrix
in class AbstractRealMatrix
column
- the index of the column to be fetchedpublic RealMatrix getSubMatrix(int startRow, int endRow, int startColumn, int endColumn)
Rows and columns are indicated counting from 0 to n-1.
The returned matrix is a DiagonalMatrix if the selected rows and columns are the same, and an Array2DRowRealMatrix or a BlockRealMatrix otherwise.
getSubMatrix
in interface RealMatrix
getSubMatrix
in class AbstractRealMatrix
startRow
- the initial row indexendRow
- the final row index (inclusive)startColumn
- the initial column indexendColumn
- the final column index (inclusive)public RealMatrix getSubMatrix(int[] selectedRows, int[] selectedColumns)
Rows and columns are indicated counting from 0 to n-1.
The returned matrix is an ArrayRowSymmetricMatrix if the selected rows and columns are the same (same indices, same order), and an Array2DRowRealMatrix or a BlockRealMatrix otherwise.
getSubMatrix
in interface RealMatrix
getSubMatrix
in class AbstractRealMatrix
selectedRows
- the selected row indicesselectedColumns
- the selected column indicespublic DiagonalMatrix getSubMatrix(int startIndex, int endIndex)
This method uses the same start/end indices to select the rows and columns to be extracted. These indices must be valid indices with respect to the dimensions of the matrix (valid indices range from 0 to n-1, with n the row/column dimension of the matrix). Calling this method is equivalent to calling RealMatrix.getSubMatrix(int, int, int, int) using the same start/end indices for the rows and columns. The extracted submatrix is guaranteed to be symmetric. It will also remain positive semi-definite if the initial matrix originally is.
Usage examples:
// Initial matrix matrix = [a00, a10, a20] [a10, a11, a21] [a20, a21, a22] // Submatrix extraction matrix.getSubMatrix(1, 2) => [a11, a21] [a21, a22]
getSubMatrix
in interface SymmetricMatrix
startIndex
- the initial row/column indexendIndex
- the final row/column index (inclusive)public ArrayRowSymmetricMatrix getSubMatrix(int[] indices)
This method uses a single index array to select the rows and columns to be extracted. All indices must be valid indices with respect to the dimensions of the matrix (valid indices range from 0 to n-1, with n the row/column dimension of the matrix). The provided index array is allowed to contain duplicates. Calling this method is equivalent to calling RealMatrix.getSubMatrix(int[], int[]) using the provided index array for the selected rows and columns. This method can be used to extract any submatrix and perform a symmetric reordering of its rows/columns. The extracted submatrix is guaranteed to be symmetric. It will also remain positive semi-definite if the initial matrix originally is.
Usage examples:
// Initial matrix matrix = [a00, a10, a20] [a10, a11, a21] [a20, a21, a22] // Submatrix extraction matrix.getSubMatrix([1, 2]) => [a11, a21] [a21, a22] // Rows/Columns permutation matrix.getSubMatrix([1, 2, 0]) => [a11, a21, a10] [a21, a22, a20] [a10, a20, a00] // Submatrix extraction (with duplicated indices) matrix.getSubMatrix([1, 2, 0, 1, 0]) => [a11, a21, a10, a11, a10] [a21, a22, a20, a21, a20] [a10, a20, a00, a10, a00] [a11, a21, a10, a11, a10] [a10, a20, a00, a10, a00]
getSubMatrix
in interface SymmetricMatrix
indices
- the selected indicespublic void setSubMatrix(double[][] subMatrix, int row, int column)
Important:
This method systematically throws a MathUnsupportedOperationException since this
operation is not safe when dealing with diagonal matrices (the properties of the matrix are
not guaranteed to be preserved).
setSubMatrix
in interface RealMatrix
setSubMatrix
in class AbstractRealMatrix
subMatrix
- the array containing the replacement data of the targeted submatrixrow
- the row coordinate of the top, left element to be replacedcolumn
- the column coordinate of the top, left element to be replacedMathUnsupportedOperationException
- systematically, since this operation is not supportedpublic ArrayRowSymmetricMatrix scalarAdd(double d)
d
to the entries of this matrix.
The returned matrix is an ArrayRowSymmetricMatrix.
scalarAdd
in interface RealMatrix
scalarAdd
in interface SymmetricMatrix
scalarAdd
in class AbstractRealMatrix
d
- the scalar value to be added to the entries of this matrixthis
+d
public DiagonalMatrix scalarMultiply(double d)
d
.scalarMultiply
in interface RealMatrix
scalarMultiply
in interface SymmetricMatrix
scalarMultiply
in class AbstractRealMatrix
d
- the scalar value by which to multiply the entries of this matrix bythis
×d
public RealMatrix add(RealMatrix m)
m
to this matrix.
The returned matrix is, in order of priority:
add
in interface RealMatrix
add
in class AbstractRealMatrix
m
- the matrix to be addedthis
+m
public SymmetricMatrix add(SymmetricMatrix m)
m
to this matrix.
The returned matrix is, in order of priority:
add
in interface SymmetricMatrix
m
- the matrix to be addedthis
+m
public DiagonalMatrix add(DiagonalMatrix m)
m
to this matrix.m
- the matrix to be addedthis
+m
MatrixDimensionMismatchException
- if the matrix m
is not the same size as this matrixpublic RealMatrix subtract(RealMatrix m)
m
from this matrix.
The returned matrix is, in order of priority:
subtract
in interface RealMatrix
subtract
in class AbstractRealMatrix
m
- the matrix to be subtractedthis
-m
public SymmetricMatrix subtract(SymmetricMatrix m)
m
from this matrix.
The returned matrix is, in order of priority:
subtract
in interface SymmetricMatrix
m
- the matrix to be subtractedthis
-m
public DiagonalMatrix subtract(DiagonalMatrix m)
m
from this matrix.m
- the matrix to be subtractedthis
- m
MatrixDimensionMismatchException
- if the matrix m
is not the same size as this matrixpublic RealMatrix multiply(RealMatrix m, boolean toTranspose, double d)
m
or its transpose
m
T, then by the scalar d
.multiply
in interface RealMatrix
multiply
in class AbstractRealMatrix
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
public DiagonalMatrix multiply(DiagonalMatrix m, double d)
m
, then by
the scalar d
.multiply
in class AbstractRealMatrix
m
- the diagonal matrix by which to multiply this matrix byd
- the scalar by which to multiply the resulting matrix bythis
×m
×d
or
this
×m
T×d
public ArrayRowSymmetricMatrix quadraticMultiplication(RealMatrix m)
this
×MT,
where M is the provided matrix.quadraticMultiplication
in interface SymmetricMatrix
m
- the matrix Mthis
×MTpublic ArrayRowSymmetricMatrix quadraticMultiplication(RealMatrix m, boolean isTranspose)
this
×MT,
where M or MT is the provided matrix.quadraticMultiplication
in interface SymmetricMatrix
m
- the matrix M or the matrix MTisTranspose
- if true
, assumes the provided matrix is MT, otherwise assumes it is
Mthis
×MTpublic double[] operate(double[] v)
v
.operate
in interface RealMatrix
operate
in class AbstractRealMatrix
v
- the vector by which to multiply this matrix bythis
×v
public RealVector operate(RealVector v)
this
by the vector x
.operate
in interface RealMatrix
operate
in class AbstractRealMatrix
v
- the vector to operate onthis
instance with x
public double[] preMultiply(double[] v)
v
.preMultiply
in interface RealMatrix
preMultiply
in class AbstractRealMatrix
v
- the row vector by which to premultiply this matrix byv
×this
public RealVector preMultiply(RealVector v)
v
.preMultiply
in interface RealMatrix
preMultiply
in class AbstractRealMatrix
v
- the vector by which to premultiply this matrix byv
×this
public DiagonalMatrix 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.
power
in interface RealMatrix
power
in interface SymmetricMatrix
power
in class AbstractRealMatrix
p
- the exponent p
to which this matrix is to be raisedp
public DiagonalMatrix 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).
createMatrix
in interface RealMatrix
createMatrix
in interface SymmetricMatrix
createMatrix
in class AbstractRealMatrix
rowDimension
- the number of rows in the new matrixcolumnDimension
- the number of columns in the new matrixpublic static DiagonalMatrix createIdentityMatrix(int n)
n
- the dimension of the identity matrixpublic DiagonalMatrix copy()
copy
in interface RealMatrix
copy
in interface SymmetricMatrix
copy
in class AbstractRealMatrix
public DiagonalMatrix transpose()
transpose
in interface RealMatrix
transpose
in interface SymmetricMatrix
transpose
in class AbstractRealMatrix
public DiagonalMatrix 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).
transpose
in interface RealMatrix
transpose
in interface SymmetricMatrix
transpose
in class AbstractRealMatrix
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
transposepublic RealMatrix 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]
concatenateHorizontally
in interface RealMatrix
concatenateHorizontally
in class AbstractRealMatrix
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 matrixpublic RealMatrix 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]
concatenateVertically
in interface RealMatrix
concatenateVertically
in class AbstractRealMatrix
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 matrixpublic RealMatrix 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]
concatenateDiagonally
in interface RealMatrix
concatenateDiagonally
in class AbstractRealMatrix
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 matrixpublic DiagonalMatrix getInverse()
The default decomposition builder can be changed using the
setDefaultDecomposition
method.
getInverse
in interface RealMatrix
getInverse
in interface SymmetricMatrix
getInverse
in class AbstractRealMatrix
RealMatrix.getDefaultDecomposition()
,
RealMatrix.setDefaultDecomposition(Function)
public DiagonalMatrix 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).
The provided decomposition algorithm is never used, since the computation of the inverse is straightforward for diagonal matrices.
getInverse
in interface RealMatrix
getInverse
in interface SymmetricMatrix
getInverse
in class AbstractRealMatrix
decompositionBuilder
- the decomposition builder to usepublic boolean isDiagonal(double threshold)
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.
isDiagonal
in interface RealMatrix
isDiagonal
in class AbstractRealMatrix
threshold
- 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
otherwisepublic boolean isSquare()
isSquare
in interface AnyMatrix
isSquare
in class AbstractRealMatrix
public boolean 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.
The absolute and relative tolerances both default to Precision.DOUBLE_COMPARISON_EPSILON.
isSymmetric
in interface RealMatrix
isSymmetric
in class AbstractRealMatrix
true
if this is a symmetric matrix, false
otherwisepublic boolean 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.
isSymmetric
in interface RealMatrix
isSymmetric
in class AbstractRealMatrix
relativeTolerance
- the relative tolerance to take into account when comparing off-diagonal elementstrue
if this is a symmetric matrix, false
otherwisepublic boolean 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.
isSymmetric
in interface RealMatrix
isSymmetric
in class AbstractRealMatrix
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
otherwisepublic boolean isAntisymmetric(double absoluteTolerance)
A diagonal matrix can only be antisymmetric if its diagonal elements are all equal to zero.
The specified absolute threshold is taken into account to assess if this is the case or not.
absoluteTolerance
- the absolute threshold to take into account when checking if the diagonal elements are
equal to zerotrue
if the matrix is antisymmetric, false
otherwisepublic boolean 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.
A diagonal matrix can only be antisymmetric if its diagonal elements are all equal to zero.
Only the absolute threshold is taken into account to assess if this is the case or not.
isAntisymmetric
in interface RealMatrix
isAntisymmetric
in class AbstractRealMatrix
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
otherwisepublic boolean isOrthogonal(double thresholdNorm, double thresholdOrthogonality)
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.
A diagonal matrix can only be orthogonal if its diagonal elements are all equal to +1 or -1.
isOrthogonal
in interface RealMatrix
isOrthogonal
in class AbstractRealMatrix
thresholdNorm
- the relative tolerance to take into account when checking the normality of the the
column vectorsthresholdOrthogonality
- the absolute tolerance to take into account when checking the mutual orthogonality of
the the column vectorstrue
if this is an orthogonal matrix, false
otherwisepublic boolean isSingular()
A diagonal matrix is singular if any of its diagonal elements is equal to 0.
The default absolute tolerance (Precision.SAFE_MIN) is taken into account when
checking the values.
true
if the matrix is singular, false
otherwisepublic boolean isSingular(double absoluteTolerance)
A diagonal matrix is singular if any of its diagonal elements is equal to 0.
The specified absolute tolerance is taken into account when checking the values.
absoluteTolerance
- the absolute tolerance to take into account when checking if an element is equal to 0true
if the matrix is singular, false
otherwisepublic boolean isInvertible()
A diagonal matrix is invertible if its diagonal elements are all different from zero.
The default absolute tolerance (Precision.SAFE_MIN) is taken into account when
checking the values.
true
if the matrix is invertible, false
otherwisepublic boolean isInvertible(double absoluteTolerance)
A diagonal matrix is invertible if its diagonal elements are all different from zero.
The specified absolute tolerance is taken into account when checking the values.
isInvertible
in interface RealMatrix
isInvertible
in class AbstractRealMatrix
absoluteTolerance
- the absolute tolerance to take into account when checking if an element is equal to 0true
if the matrix is invertible, false
otherwisepublic boolean equals(Object object)
true
if the provided object is a RealMatrix instance with the
same dimensions as this matrix, whose entries are strictly equal to the entries of this
matrix (no absolute or relative tolerance is taken into account when comparing the entries).equals
in class AbstractRealMatrix
object
- the object to be tested for equalitytrue
if the provided object is equal to this matrixpublic int hashCode()
hashCode
in class AbstractRealMatrix
Copyright © 2023 CNES. All rights reserved.