## Class OGMatrixAlgebra

• public class OGMatrixAlgebra
extends MatrixAlgebra
A minimal implementation of matrix algebra.

This includes only some of the multiplications. For more advanced operations, such as calculating the inverse, use CommonsMatrixAlgebra.

• ### Constructor Summary

Constructors
Constructor Description
OGMatrixAlgebra()
• ### 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 matrix raised to a power, $\mathbf{A}^3 = \mathbf{A}\mathbf{A}\mathbf{A}$.
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

• #### OGMatrixAlgebra

public OGMatrixAlgebra()
• ### Method Detail

• #### getCondition

public double getCondition​(Matrix m)
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
Throws:
UnsupportedOperationException - always
• #### getDeterminant

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

public double getInnerProduct​(Matrix m1,
Matrix m2)
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)
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
Throws:
UnsupportedOperationException - always
• #### getNorm1

public double getNorm1​(Matrix m)
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
Throws:
UnsupportedOperationException - always
• #### getNorm2

public double getNorm2​(Matrix m)
For a vector, returns $L_2$ norm (also known as the Euclidean norm).

For a matrix, returns the spectral norm This is only implemented for DoubleArray.

Specified by:
getNorm2 in class MatrixAlgebra
Parameters:
m - A vector or matrix, not null
Returns:
the norm
Throws:
IllegalArgumentException - If the matrix is not a DoubleArray
• #### getNormInfinity

public double getNormInfinity​(Matrix m)
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
Throws:
UnsupportedOperationException - always
• #### getOuterProduct

public DoubleMatrix getOuterProduct​(Matrix m1,
Matrix m2)
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)
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
Throws:
UnsupportedOperationException - always
• #### getTrace

public double getTrace​(Matrix m)
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)
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$
• m1 = 1-D matrix, m2 = 2-D matrix, returns $\mathbf{C} = a^T\mathbf{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.
• #### getPower

public DoubleMatrix getPower​(Matrix m,
double p)
Returns a matrix raised to a power, $\mathbf{A}^3 = \mathbf{A}\mathbf{A}\mathbf{A}$.
Specified by:
getPower in class MatrixAlgebra
Parameters:
m - A square matrix, not null
p - The power
Returns:
The result
Throws:
UnsupportedOperationException - always