Top Description Inners Fields Constructors Methods
org.apache.commons.math3.linear

public Class MatrixUtils

extends Object
Class Inheritance
Imports
java.io.IOException, .ObjectInputStream, .ObjectOutputStream, java.util.Arrays, org.apache.commons.math3.Field, .FieldElement, org.apache.commons.math3.exception.DimensionMismatchException, .MathArithmeticException, .NoDataException, .NullArgumentException, .NumberIsTooSmallException, .OutOfRangeException, .ZeroException, org.apache.commons.math3.exception.util.LocalizedFormats, org.apache.commons.math3.fraction.BigFraction, .Fraction, org.apache.commons.math3.util.FastMath, .MathArrays, .MathUtils, .Precision

A collection of static methods that operate on or return matrices.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class

Field Summary

Modifier and TypeField and Description
public static final RealMatrixFormat
DEFAULT_FORMAT

The default format for RealMatrix objects.

public static final RealMatrixFormat
OCTAVE_FORMAT

A format for RealMatrix objects compatible with octave.

Constructor Summary

AccessConstructor and Description
private
MatrixUtils()

Private constructor.

Method Summary

Modifier and TypeMethod and Description
public static Array2DRowRealMatrix

Returns:

the converted matrix.
bigFractionMatrixToRealMatrix
(final FieldMatrix<BigFraction>
Matrix to convert.
m
)

Convert a FieldMatrix/BigFraction matrix to a RealMatrix.

public static RealMatrix

Returns:

the inverse of m.
blockInverse
(RealMatrix
Matrix whose inverse must be computed.
m
,
int
Index that determines the "split" line and column. The element corresponding to this index will part of the upper-left sub-matrix.
splitIndex
)

Computes the inverse of the given matrix by splitting it into 4 sub-matrices.

public static void
checkAdditionCompatible(final AnyMatrix
Left hand side matrix.
left
,
final AnyMatrix
Right hand side matrix.
right
)

Check if matrices are addition compatible.

public static void
checkColumnIndex(final AnyMatrix
Matrix.
m
,
final int
Column index to check.
column
)

Check if a column index is valid.

public static void
checkMatrixIndex(final AnyMatrix
Matrix.
m
,
final int
Row index to check.
row
,
final int
Column index to check.
column
)

Check if matrix indices are valid.

public static void
checkMultiplicationCompatible(final AnyMatrix
Left hand side matrix.
left
,
final AnyMatrix
Right hand side matrix.
right
)

Check if matrices are multiplication compatible

public static void
checkRowIndex(final AnyMatrix
Matrix.
m
,
final int
Row index to check.
row
)

Check if a row index is valid.

public static void
checkSubMatrixIndex(final AnyMatrix
Matrix.
m
,
final int
Initial row index.
startRow
,
final int
Final row index.
endRow
,
final int
Initial column index.
startColumn
,
final int
Final column index.
endColumn
)

Check if submatrix ranges indices are valid.

public static void
checkSubMatrixIndex(final AnyMatrix
Matrix.
m
,
final int[]
Array of row indices.
selectedRows
,
final int[]
Array of column indices.
selectedColumns
)

Check if submatrix ranges indices are valid.

public static void
checkSubtractionCompatible(final AnyMatrix
Left hand side matrix.
left
,
final AnyMatrix
Right hand side matrix.
right
)

Check if matrices are subtraction compatible

public static void
checkSymmetric(RealMatrix
Matrix to check.
matrix
,
double
Relative tolerance.
eps
)

Checks whether a matrix is symmetric.

public static <
the type of the field elements
T extends FieldElement<T>
>
FieldMatrix<T>

Returns:

a columnData x 1 FieldMatrix
createColumnFieldMatrix
(final T[]
the input column data
columnData
)

Creates a column FieldMatrix using the data from the input array.

public static RealMatrix

Returns:

a columnData x 1 RealMatrix
createColumnRealMatrix
(double[]
the input column data
columnData
)

Creates a column RealMatrix using the data from the input array.

public static <
the type of the field elements
T extends FieldElement<T>
>
FieldMatrix<T>

Returns:

diagonal matrix
createFieldDiagonalMatrix
(final T[]
diagonal elements of the matrix (the array elements will be copied)
diagonal
)

Returns a diagonal matrix with specified elements.

public static <
the type of the field elements
T extends FieldElement<T>
>
FieldMatrix<T>

Returns:

identity matrix
createFieldIdentityMatrix
(final Field<T>
field to which the elements belong
field
,
final int
dimension of identity matrix to generate
dimension
)

Returns dimension x dimension identity matrix.

public static <
the type of the field elements
T extends FieldElement<T>
>
FieldMatrix<T>

Returns:

FieldMatrix with specified dimensions
createFieldMatrix
(final Field<T>
field to which the matrix elements belong
field
,
final int
number of rows of the matrix
rows
,
final int
number of columns of the matrix
columns
)

Returns a FieldMatrix with specified dimensions.

public static <
the type of the field elements
T extends FieldElement<T>
>
FieldMatrix<T>

Returns:

a matrix containing the values of the array.
createFieldMatrix
(T[][]
input array
data
)

Returns a FieldMatrix whose entries are the the values in the the input array.

public static <
the type of the field elements
T extends FieldElement<T>
>
FieldVector<T>

Returns:

a data.length FieldVector
createFieldVector
(final T[]
the input data
data
)

Creates a FieldVector using the data from the input array.

public static RealMatrix

Returns:

diagonal matrix
createRealDiagonalMatrix
(final double[]
diagonal elements of the matrix (the array elements will be copied)
diagonal
)

Returns a diagonal matrix with specified elements.

public static RealMatrix

Returns:

identity matrix
createRealIdentityMatrix
(int
dimension of identity matrix to generate
dimension
)

Returns dimension x dimension identity matrix.

public static RealMatrix

Returns:

RealMatrix with specified dimensions
createRealMatrix
(final int
number of rows of the matrix
rows
,
final int
number of columns of the matrix
columns
)

Returns a RealMatrix with specified dimensions.

public static RealMatrix

Returns:

RealMatrix containing the values of the array
createRealMatrix
(double[][]
input array
data
)

Returns a RealMatrix whose entries are the the values in the the input array.

public static RealVector

Returns:

a data.length RealVector
createRealVector
(double[]
the input data
data
)

Creates a RealVector using the data from the input array.

public static <
the type of the field elements
T extends FieldElement<T>
>
FieldMatrix<T>

Returns:

a 1 x rowData.length FieldMatrix
createRowFieldMatrix
(final T[]
the input row data
rowData
)

Create a row FieldMatrix using the data from the input array.

public static RealMatrix

Returns:

a 1 x rowData.length RealMatrix
createRowRealMatrix
(double[]
the input row data
rowData
)

Create a row RealMatrix using the data from the input array.

public static void
deserializeRealMatrix(final Object
instance in which the field must be set up
instance
,
final String
name of the field within the class (may be private and final)
fieldName
,
final ObjectInputStream
stream from which the real matrix should be read
ois
)

Deserialize a RealMatrix field in a class.

public static void
deserializeRealVector(final Object
instance in which the field must be set up
instance
,
final String
name of the field within the class (may be private and final)
fieldName
,
final ObjectInputStream
stream from which the real vector should be read
ois
)

Deserialize a RealVector field in a class.

public static Array2DRowRealMatrix

Returns:

the converted matrix.
fractionMatrixToRealMatrix
(final FieldMatrix<Fraction>
Matrix to convert.
m
)

Convert a FieldMatrix/Fraction matrix to a RealMatrix.

public static RealMatrix

Returns:

the inverse of matrix
inverse
(RealMatrix
Matrix whose inverse shall be computed
matrix
)

Computes the inverse of the given matrix.

public static RealMatrix

Returns:

the inverse of m
inverse
(RealMatrix
Matrix whose inverse shall be computed
matrix
,
double
Singularity threshold
threshold
)

Computes the inverse of the given matrix.

public static boolean

Returns:

true if matrix is symmetric.
isSymmetric
(RealMatrix
Matrix to check.
matrix
,
double
Relative tolerance.
eps
)

Checks whether a matrix is symmetric.

private static boolean

Returns:

true if matrix is symmetric.
isSymmetricInternal
(RealMatrix
Matrix to check.
matrix
,
double
Tolerance of the symmetry check.
relativeTolerance
,
boolean
If true, an exception will be raised if the matrix is not symmetric.
raiseException
)

Checks whether a matrix is symmetric, within a given relative tolerance.

public static void
serializeRealMatrix(final RealMatrix
real matrix to serialize
matrix
,
final ObjectOutputStream
stream where the real matrix should be written
oos
)

Serialize a RealMatrix.

public static void
serializeRealVector(final RealVector
real vector to serialize
vector
,
final ObjectOutputStream
stream where the real vector should be written
oos
)

Serialize a RealVector.

public static void
solveLowerTriangularSystem(RealMatrix
RealMatrix which is lower triangular
rm
,
RealVector
RealVector this is overwritten
b
)

Solve a system of composed of a Lower Triangular Matrix RealMatrix.

public static void
solveUpperTriangularSystem(RealMatrix
RealMatrix which is upper triangular
rm
,
RealVector
RealVector this is overwritten
b
)

Solver a system composed of an Upper Triangular Matrix RealMatrix.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait