## Class CommonsMatrixAlgebra

• public class CommonsMatrixAlgebra
extends MatrixAlgebra
Provides matrix algebra by using the Commons library.
• ### Constructor Summary

Constructors
Constructor Description
CommonsMatrixAlgebra()
• ### Method Summary

All Methods
Modifier and Type Method Description
double getCondition​(Matrix m)
Returns the condition number of the matrix.
double getDeterminant​(Matrix m)
Returns the determinant of the matrix.
double getInnerProduct​(Matrix m1, Matrix m2)
Returns the inner (or dot) product.
DoubleMatrix getInverse​(Matrix m)
Returns the inverse (or pseudo-inverse) of the matrix.
double getNorm1​(Matrix m)
For a vector, returns the $L_1$ norm (also known as the Taxicab norm or Manhattan norm), i.e.
double getNorm2​(Matrix m)
For a vector, returns $L_2$ norm (also known as the Euclidean norm).
double getNormInfinity​(Matrix m)
For a vector, returns the $L_\infty$ norm.
DoubleMatrix getOuterProduct​(Matrix m1, Matrix m2)
Returns the outer product.
DoubleMatrix getPower​(Matrix m, double p)
Returns a real matrix raised to some real power Currently this method is limited to symmetric matrices only as Commons Math does not support the diagonalization of asymmetric matrices.
DoubleMatrix getPower​(Matrix m, int p)
Returns a matrix raised to an integer power, e.g.
double getTrace​(Matrix m)
Returns the trace (i.e.
DoubleMatrix getTranspose​(Matrix m)
Returns the transpose of a matrix.
Matrix multiply​(Matrix m1, Matrix m2)
Multiplies two matrices.
• ### Methods inherited from class com.opengamma.strata.math.impl.matrix.MatrixAlgebra

add, divide, kroneckerProduct, matrixTransposeMultiplyMatrix, scale, subtract
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### Constructor Detail

• #### CommonsMatrixAlgebra

public CommonsMatrixAlgebra()
• ### Method Detail

• #### getCondition

public double getCondition​(Matrix m)
Description copied from class: MatrixAlgebra
Returns the condition number of the matrix.
Specified by:
getCondition in class MatrixAlgebra
Parameters:
m - A matrix, not null
Returns:
The condition number of the matrix
• #### getDeterminant

public double getDeterminant​(Matrix m)
Description copied from class: MatrixAlgebra
Returns the determinant of the matrix.
Specified by:
getDeterminant in class MatrixAlgebra
Parameters:
m - A matrix, not null
Returns:
The determinant of the matrix
• #### getInnerProduct

public double getInnerProduct​(Matrix m1,
Matrix m2)
Description copied from class: MatrixAlgebra
Returns the inner (or dot) product.
Specified by:
getInnerProduct in class MatrixAlgebra
Parameters:
m1 - A vector, not null
m2 - A vector, not null
Returns:
The scalar dot product
• #### getInverse

public DoubleMatrix getInverse​(Matrix m)
Description copied from class: MatrixAlgebra
Returns the inverse (or pseudo-inverse) of the matrix.
Specified by:
getInverse in class MatrixAlgebra
Parameters:
m - A matrix, not null
Returns:
The inverse matrix
• #### getNorm1

public double getNorm1​(Matrix m)
Description copied from class: MatrixAlgebra
For a vector, returns the $L_1$ norm (also known as the Taxicab norm or Manhattan norm), i.e. $\Sigma |x_i|$.

For a matrix, returns the maximum absolute column sum norm of the matrix.

Specified by:
getNorm1 in class MatrixAlgebra
Parameters:
m - A vector or matrix, not null
Returns:
The $L_1$ norm
• #### getNorm2

public double getNorm2​(Matrix m)
Description copied from class: MatrixAlgebra
For a vector, returns $L_2$ norm (also known as the Euclidean norm).

For a matrix, returns the spectral norm

Specified by:
getNorm2 in class MatrixAlgebra
Parameters:
m - A vector or matrix, not null
Returns:
the norm
• #### getNormInfinity

public double getNormInfinity​(Matrix m)
Description copied from class: MatrixAlgebra
For a vector, returns the $L_\infty$ norm. $L_\infty$ norm is the maximum of the absolute values of the elements.

For a matrix, returns the maximum absolute row sum norm

Specified by:
getNormInfinity in class MatrixAlgebra
Parameters:
m - a vector or a matrix, not null
Returns:
the norm
• #### getOuterProduct

public DoubleMatrix getOuterProduct​(Matrix m1,
Matrix m2)
Description copied from class: MatrixAlgebra
Returns the outer product.
Specified by:
getOuterProduct in class MatrixAlgebra
Parameters:
m1 - A vector, not null
m2 - A vector, not null
Returns:
The outer product
• #### getPower

public DoubleMatrix getPower​(Matrix m,
int p)
Description copied from class: MatrixAlgebra
Returns a matrix raised to an integer power, e.g. $\mathbf{A}^3 = \mathbf{A}\mathbf{A}\mathbf{A}$.
Specified by:
getPower in class MatrixAlgebra
Parameters:
m - A square matrix, not null
p - An integer power
Returns:
The result
• #### getPower

public DoubleMatrix getPower​(Matrix m,
double p)
Returns a real matrix raised to some real power Currently this method is limited to symmetric matrices only as Commons Math does not support the diagonalization of asymmetric matrices.
Specified by:
getPower in class MatrixAlgebra
Parameters:
m - The symmetric matrix to take the power of.
p - The power to raise to matrix to
Returns:
The result
• #### getTrace

public double getTrace​(Matrix m)
Description copied from class: MatrixAlgebra
Returns the trace (i.e. sum of diagonal elements) of a matrix.
Specified by:
getTrace in class MatrixAlgebra
Parameters:
m - A matrix, not null. The matrix must be square.
Returns:
The trace
• #### getTranspose

public DoubleMatrix getTranspose​(Matrix m)
Description copied from class: MatrixAlgebra
Returns the transpose of a matrix.
Specified by:
getTranspose in class MatrixAlgebra
Parameters:
m - A matrix, not null
Returns:
The transpose matrix
• #### multiply

public Matrix multiply​(Matrix m1,
Matrix m2)
Multiplies two matrices. The following combinations of input matrices m1 and m2 are allowed:
• m1 = 2-D matrix, m2 = 2-D matrix, returns $\mathbf{C} = \mathbf{AB}$
• m1 = 2-D matrix, m2 = 1-D matrix, returns $\mathbf{C} = \mathbf{A}b$
Specified by:
multiply in class MatrixAlgebra
Parameters:
m1 - The first matrix, not null.
m2 - The second matrix, not null.
Returns:
The product of the two matrices.