Package org.drip.numerical.linearalgebra
Class R1MatrixUtil
java.lang.Object
org.drip.numerical.linearalgebra.R1MatrixUtil
public class R1MatrixUtil
extends java.lang.Object
R1MatrixUtil implements R1 Matrix manipulation routines. It exports the following
functionality:
- Matrix Inversion using Closed form solutions (for low-dimension matrices), or using Gaussian elimination
- Matrix Product
- Matrix Diagonalization and Diagonal Pivoting
- Matrix Regularization through Row Addition/Row Swap
- Module = Computational Core Module
- Library = Numerical Analysis Library
- Project = Numerical Quadrature, Differentiation, Eigenization, Linear Algebra, and Utilities
- Package = Linear Algebra Matrix Transform Library
- Author:
- Lakshmi Krishnamurthy
-
Constructor Summary
Constructors Constructor Description R1MatrixUtil() -
Method Summary
Modifier and Type Method Description static double[][]Add(double[][] a, double[][] b)Compute the Addition of the Input Matricesstatic booleanBottomLeft(int rowIndex, int columnIndex, int size)Indicate if the Cell corresponds to Bottom Left Location in the Matrixstatic double[][]CholeskyBanachiewiczFactorization(double[][] aadblA)Compute the Cholesky-Banachiewicz Factorization of the specified Matrix.static double[][]CrossProduct(double[] vector1, double[] vector2)Compute the Cross Product between the Specified Vectorsstatic double[][]Diagonal(double[][] squareMatrix)Retrieve the Diagonal Elements in a Square Matrixstatic booleanDiagonalizeRow(int iQ, double[][] aadblZ2XJack, double[][] aadblZ2YJack)Diagonalize the specified row in the source matrix, and apply comparable operations to the targetstatic doubleDotProduct(double[] adblA, double[] adblE)Dot Product of Vectors A and Estatic double[][]Invert(double[][] aadblA, java.lang.String strMethod)Invert the input matrix using the specified Methodstatic double[][]Invert2DMatrixUsingCramerRule(double[][] aadblA)Invert a 2D Matrix using Cramer's Rulestatic double[][]InvertUsingGaussianElimination(double[][] aadblSource)Invert the Source Matrix using Gaussian Eliminationstatic booleanIsDiagonal(double[][] matrix)Indicate if the Specified Matrix is Diagonalstatic booleanIsPeriodicTridiagonal(double[][] squareMatrix)Indicate if the Input Matrix is Square and satisfies Periodic Tridiagonal Conditionsstatic booleanIsSquare(double[][] matrix)Indicate if the Input Matrix is Squarestatic booleanIsSquareSymmetric(double[][] squareMatrix)Indicate if the Input Matrix is Square and Symmetricstatic booleanIsTridiagonal(double[][] squareMatrix)Indicate if the Input Matrix is Square and Tridiagonalstatic double[][]JacobiIteration(double[][] squareMatrix)Construct a Jacobi Iteration Matrix from the Square Matrixstatic double[][]MakeSquareDiagonal(double[] adblA)Make a Square Diagonal Matrix from a Rowstatic doubleModulus(double[] v)Compute the Modulus of the Input Vectorstatic booleanNegativeOrZero(double[] adbl)Indicate if the Array Entries are Negative or Zerostatic double[]Normalize(double[] adbl)Normalize the Input Vectorstatic MatrixComplementTransformPivotDiagonal(double[][] aadblA)Pivot the Diagonal of the Input Matrixstatic booleanPositiveLinearlyIndependent(double[] adbl)Indicate if the Array Entries are Positive Linearly Independentstatic booleanPositiveOrZero(double[] adbl)Indicate if the Array Entries are Positive or Zerostatic double[][]Power(double[][] a, int k)Compute the Power of the Input Matrixstatic double[]Product(double[][] a, double[] b)Compute the Product of an Input Matrix and a Vectorstatic double[][]Product(double[][] a, double[][] b)Compute the Product of the input matricesstatic double[][]Product(double[] a, double[][] b)Compute the Product of an Input Vector and a Matrixstatic double[]Project(double[] adblA, double[] adblE)Project the Vector A along the Vector Estatic QRQRDecomposition(double[][] a)Perform a QR Decomposition on the Input Matrixstatic double[][]QRGrahamSchmidtOrthogonalization(double[][] a)Orthogonalize the Specified Matrix Using the QR Graham-Schmidt Methodstatic double[][]QRGrahamSchmidtOrthonormalization(double[][] a)Orthonormalize the Specified Matrix Using the QR Graham-Schmidt Methodstatic intRank(double[][] aadblSource)Compute the Rank of the Matrixstatic doubleRayleighQuotient(double[][] matrix, double[] eigenvector)Compute the Rayleigh Quotient given the Matrix and one of its Eigenvectorstatic booleanRegularizeUsingRowAddition(MatrixComplementTransform mct)Regularize the specified diagonal entry of the input matrix using Row Additionstatic booleanRegularizeUsingRowSwap(MatrixComplementTransform mct)Regularize the specified diagonal entry of the input matrix using Row Swappingstatic QRRQDecomposition(double[][] a)Perform a RQ Decomposition on the Input Matrixstatic double[][]RQGrahamSchmidtOrthogonalization(double[][] a)Orthogonalize the Specified Matrix Using the RQ Graham-Schmidt Methodstatic double[][]RQGrahamSchmidtOrthonormalization(double[][] a)Orthonormalize the Specified Matrix Using the RQ Graham-Schmidt Methodstatic double[]Scale1D(double[] vector, double scaleFactor)Scale the Entries of the Input Vector by the Factorstatic double[][]Scale2D(double[][] matrix, double scaleFactor)Scale the Entries of the Input Matrix by the Factorstatic double[][]StrictlyLowerTriangular(double[][] squareMatrix)Retrieve the Strictly Lower Triangular Elements in a Square Matrixstatic double[][]StrictlyUpperTriangular(double[][] squareMatrix)Retrieve the Strictly Upper Triangular Elements in a Square Matrixstatic double[][]Subtract(double[][] a, double[][] b)Compute the Subtraction of the Input Matricesstatic doubleSum(double[] adbl)Compute the Sum of the Input Vectorstatic double[][]Sum(double[][] aadblA, double[][] aadblB)Compute the Sum of the input matricesstatic booleanTopRight(int rowIndex, int columnIndex, int size)Indicate if the Cell corresponds to Top ight Location in the Matrixstatic doubleTrace(double[][] a)Compute the Trace of the Input Matrixstatic double[][]Transpose(double[][] r2Array)Transpose the specified Square Matrixstatic double[][]UnsafeAdd(double[][] a, double[][] b)Compute the Addition of the Input Matrices.static doubleUnsafeDotProduct(double[] a, double[] e)Dot Product of Vectors A and E.static doubleUnsafeModulus(double[] v)Compute the Modulus of the Vector.static double[][]UnsafePower(double[][] a, int k)Compute the Power of the Input Matrix.static double[]UnsafeProduct(double[][] a, double[] b)Compute the Product of an Input Matrix and a Vector.static double[][]UnsafeProduct(double[][] a, double[][] b)Compute the Product of the Input Matrices.static double[][]UnsafeProduct(double[] a, double[][] b)Compute the Product of an Input Vector and a Matrix.static double[]UnsafeProjectVOnU(double[] u, double[] v)Compute the Projection Vector on V induced by U.static double[][]UnsafeQRGrahamSchmidtOrthogonalization(double[][] a)Orthogonalize the Specified Matrix Using the QR Graham-Schmidt Method.static double[][]UnsafeRQGrahamSchmidtOrthogonalization(double[][] a)Orthogonalize the Specified Matrix Using the RQ Graham-Schmidt Method.static double[][]UnsafeSubtract(double[][] a, double[][] b)Compute the Subtraction of the Input Matrices.static doubleUnsafeTrace(double[][] a)Compute the Trace of the Input Matrix.static double[][]UnsafeTranspose(double[][] r2Array)Transpose the specified Square Matrix.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
R1MatrixUtil
public R1MatrixUtil()
-
-
Method Details
-
UnsafeDotProduct
public static final double UnsafeDotProduct(double[] a, double[] e)Dot Product of Vectors A and E. Unsafe Methods do not validate the Input Arguments, so use caution in applying these Methods- Parameters:
a- Vector Ae- Vector E- Returns:
- The Dot Product
-
UnsafeProjectVOnU
public static final double[] UnsafeProjectVOnU(double[] u, double[] v)Compute the Projection Vector on V induced by U. Unsafe Methods do not validate the Input Arguments, so use caution in applying these Methods- Parameters:
u- Vector Uv- Vector V- Returns:
- The Projection Vector
-
UnsafeModulus
public static final double UnsafeModulus(double[] v)Compute the Modulus of the Vector. Unsafe Methods do not validate the Input Arguments, so use caution in applying these Methods- Parameters:
v- Vector V- Returns:
- Modulus of the Vector
-
UnsafeProduct
public static final double[][] UnsafeProduct(double[][] a, double[][] b)Compute the Product of the Input Matrices. Unsafe Methods do not validate the Input Arguments, so use caution in applying these Methods- Parameters:
a- Vector Ab- Vector B- Returns:
- The Product Matrix
-
UnsafeProduct
public static final double[] UnsafeProduct(double[][] a, double[] b)Compute the Product of an Input Matrix and a Vector. Unsafe Methods do not validate the Input Arguments, so use caution in applying these Methods- Parameters:
a- Matrix Ab- Vector B- Returns:
- The Product
-
UnsafeProduct
public static final double[][] UnsafeProduct(double[] a, double[][] b)Compute the Product of an Input Vector and a Matrix. Unsafe Methods do not validate the Input Arguments, so use caution in applying these Methods- Parameters:
a- Column Ab- Matrix B- Returns:
- The Product
-
UnsafeAdd
public static final double[][] UnsafeAdd(double[][] a, double[][] b)Compute the Addition of the Input Matrices. Unsafe Methods do not validate the Input Arguments, so use caution in applying these Methods- Parameters:
a- Vector Ab- Vector B- Returns:
- The Addition Matrix
-
UnsafeSubtract
public static final double[][] UnsafeSubtract(double[][] a, double[][] b)Compute the Subtraction of the Input Matrices. Unsafe Methods do not validate the Input Arguments, so use caution in applying these Methods- Parameters:
a- Vector Ab- Vector B- Returns:
- The Subtraction Matrix
-
UnsafePower
public static final double[][] UnsafePower(double[][] a, int k)Compute the Power of the Input Matrix. Unsafe Methods do not validate the Input Arguments, so use caution in applying these Methods- Parameters:
a- Vector Ak- Power Exponent- Returns:
- The Power Matrix
-
UnsafeTrace
public static final double UnsafeTrace(double[][] a) throws java.lang.ExceptionCompute the Trace of the Input Matrix. Unsafe Methods do not validate the Input Arguments, so use caution in applying these Methods- Parameters:
a- Vector A- Returns:
- The Trace
- Throws:
java.lang.Exception- Thrown if Trace cannot be Calculated
-
UnsafeRQGrahamSchmidtOrthogonalization
public static final double[][] UnsafeRQGrahamSchmidtOrthogonalization(double[][] a)Orthogonalize the Specified Matrix Using the RQ Graham-Schmidt Method. Unsafe Methods do not validate the Input Arguments, so use caution in applying these Methods- Parameters:
a- The Input Matrix- Returns:
- The RQ Orthogonalized Matrix
-
UnsafeQRGrahamSchmidtOrthogonalization
public static final double[][] UnsafeQRGrahamSchmidtOrthogonalization(double[][] a)Orthogonalize the Specified Matrix Using the QR Graham-Schmidt Method. Unsafe Methods do not validate the Input Arguments, so use caution in applying these Methods- Parameters:
a- The Input Matrix- Returns:
- The QR Orthogonalized Matrix
-
UnsafeTranspose
public static final double[][] UnsafeTranspose(double[][] r2Array)Transpose the specified Square Matrix. Unsafe Methods do not validate the Input Arguments, so use caution in applying these Methods- Parameters:
r2Array- The Input R2 Array- Returns:
- The Transpose of the Input R2 Array
-
BottomLeft
public static final boolean BottomLeft(int rowIndex, int columnIndex, int size)Indicate if the Cell corresponds to Bottom Left Location in the Matrix- Parameters:
rowIndex- Row IndexcolumnIndex- Column Indexsize- Matrix Size- Returns:
- TRUE - The Cell corresponds to Bottom Left
-
TopRight
public static final boolean TopRight(int rowIndex, int columnIndex, int size)Indicate if the Cell corresponds to Top ight Location in the Matrix- Parameters:
rowIndex- Row IndexcolumnIndex- Column Indexsize- Matrix Size- Returns:
- TRUE - The Cell corresponds to Top Right
-
DiagonalizeRow
public static final boolean DiagonalizeRow(int iQ, double[][] aadblZ2XJack, double[][] aadblZ2YJack)Diagonalize the specified row in the source matrix, and apply comparable operations to the target- Parameters:
iQ- Row in the Source MatrixaadblZ2XJack- Source MatrixaadblZ2YJack- Target Matrix- Returns:
- TRUE - Diagonalization was successful
-
Product
public static final double[] Product(double[][] a, double[] b)Compute the Product of an Input Matrix and a Vector- Parameters:
a- Matrix Ab- Array B- Returns:
- The Product
-
Product
public static final double[][] Product(double[] a, double[][] b)Compute the Product of an Input Vector and a Matrix- Parameters:
a- Vector Ab- Matrix B- Returns:
- The Product
-
Product
public static final double[][] Product(double[][] a, double[][] b)Compute the Product of the input matrices- Parameters:
a- Matrix Ab- Matrix B- Returns:
- The Product
-
Add
public static final double[][] Add(double[][] a, double[][] b)Compute the Addition of the Input Matrices- Parameters:
a- Matrix Ab- Matrix B- Returns:
- The Addition
-
Subtract
public static final double[][] Subtract(double[][] a, double[][] b)Compute the Subtraction of the Input Matrices- Parameters:
a- Matrix Ab- Matrix B- Returns:
- The Subtraction
-
Power
public static final double[][] Power(double[][] a, int k)Compute the Power of the Input Matrix- Parameters:
a- Matrix Ak- Power Exponent- Returns:
- The Matrix Power
-
Trace
public static final double Trace(double[][] a) throws java.lang.ExceptionCompute the Trace of the Input Matrix- Parameters:
a- Vector A- Returns:
- The Trace
- Throws:
java.lang.Exception- Thrown if Trace cannot be Calculated
-
Sum
public static final double[][] Sum(double[][] aadblA, double[][] aadblB)Compute the Sum of the input matrices- Parameters:
aadblA- Matrix AaadblB- Matrix B- Returns:
- The Sum
-
MakeSquareDiagonal
public static final double[][] MakeSquareDiagonal(double[] adblA)Make a Square Diagonal Matrix from a Row- Parameters:
adblA- The Row Array- Returns:
- The corresponding Square Diagonal Matrix
-
Invert2DMatrixUsingCramerRule
public static final double[][] Invert2DMatrixUsingCramerRule(double[][] aadblA)Invert a 2D Matrix using Cramer's Rule- Parameters:
aadblA- Input 2D Matrix- Returns:
- The Inverted Matrix
-
RegularizeUsingRowSwap
Regularize the specified diagonal entry of the input matrix using Row Swapping- Parameters:
mct- The Input Matrix Complement Transform- Returns:
- The Regularization was successful
-
RegularizeUsingRowAddition
Regularize the specified diagonal entry of the input matrix using Row Addition- Parameters:
mct- The Input Matrix Complement Transform- Returns:
- The Regularization was successful
-
PivotDiagonal
Pivot the Diagonal of the Input Matrix- Parameters:
aadblA- The Input Matrix- Returns:
- The Matrix Complement Transform Instance
-
InvertUsingGaussianElimination
public static final double[][] InvertUsingGaussianElimination(double[][] aadblSource)Invert the Source Matrix using Gaussian Elimination- Parameters:
aadblSource- Source Matrix- Returns:
- The Inverted Matrix
-
Invert
public static final double[][] Invert(double[][] aadblA, java.lang.String strMethod)Invert the input matrix using the specified Method- Parameters:
aadblA- Input MatrixstrMethod- The Inversion Method- Returns:
- The Inverted Matrix
-
Rank
public static final int Rank(double[][] aadblSource) throws java.lang.ExceptionCompute the Rank of the Matrix- Parameters:
aadblSource- Source Matrix- Returns:
- The Rank of the Matrix
- Throws:
java.lang.Exception- Thrown if the Rank Cannot be computed
-
Transpose
public static final double[][] Transpose(double[][] r2Array)Transpose the specified Square Matrix- Parameters:
r2Array- The Input R2 Array- Returns:
- The Transpose of the Square Matrix
-
CholeskyBanachiewiczFactorization
public static final double[][] CholeskyBanachiewiczFactorization(double[][] aadblA)Compute the Cholesky-Banachiewicz Factorization of the specified Matrix.- Parameters:
aadblA- The Input Matrix- Returns:
- The Factorized Matrix
-
DotProduct
public static final double DotProduct(double[] adblA, double[] adblE) throws java.lang.ExceptionDot Product of Vectors A and E- Parameters:
adblA- Vector AadblE- Vector E- Returns:
- The Dot Product
- Throws:
java.lang.Exception- Thrown if the Dot-Product cannot be computed
-
CrossProduct
public static final double[][] CrossProduct(double[] vector1, double[] vector2)Compute the Cross Product between the Specified Vectors- Parameters:
vector1- Vector #1vector2- Vector #2- Returns:
- The Cross Product
-
Project
public static final double[] Project(double[] adblA, double[] adblE)Project the Vector A along the Vector E- Parameters:
adblA- Vector AadblE- Vector E- Returns:
- The Vector of Projection of A along E
-
Sum
public static final double Sum(double[] adbl) throws java.lang.ExceptionCompute the Sum of the Input Vector- Parameters:
adbl- The Input Vector- Returns:
- TRUE - The Sum of the Input Vector
- Throws:
java.lang.Exception- Thrown if the Inputs are Invalid
-
Modulus
public static final double Modulus(double[] v) throws java.lang.ExceptionCompute the Modulus of the Input Vector- Parameters:
v- The Input Vector- Returns:
- The Modulus of the Input Vector
- Throws:
java.lang.Exception- Thrown if the Inputs are Invalid
-
PositiveOrZero
public static final boolean PositiveOrZero(double[] adbl) throws java.lang.ExceptionIndicate if the Array Entries are Positive or Zero- Parameters:
adbl- The Array- Returns:
- TRUE - The Array Entries are Positive or Zero
- Throws:
java.lang.Exception- Thrown if the Inputs are Invalid
-
NegativeOrZero
public static final boolean NegativeOrZero(double[] adbl) throws java.lang.ExceptionIndicate if the Array Entries are Negative or Zero- Parameters:
adbl- The Array- Returns:
- The Array Entries are Negative or Zero
- Throws:
java.lang.Exception- Thrown if the Inputs are Invalid
-
PositiveLinearlyIndependent
public static final boolean PositiveLinearlyIndependent(double[] adbl) throws java.lang.ExceptionIndicate if the Array Entries are Positive Linearly Independent- Parameters:
adbl- The Array- Returns:
- TRUE - The Array Entries are Positive Linearly Independent
- Throws:
java.lang.Exception- Thrown if the Inputs are Invalid
-
Normalize
public static final double[] Normalize(double[] adbl)Normalize the Input Vector- Parameters:
adbl- The Input Vector- Returns:
- The Normalized Vector
-
RQGrahamSchmidtOrthogonalization
public static final double[][] RQGrahamSchmidtOrthogonalization(double[][] a)Orthogonalize the Specified Matrix Using the RQ Graham-Schmidt Method- Parameters:
a- The Input Matrix- Returns:
- The RQ Orthogonalized Matrix
-
QRGrahamSchmidtOrthogonalization
public static final double[][] QRGrahamSchmidtOrthogonalization(double[][] a)Orthogonalize the Specified Matrix Using the QR Graham-Schmidt Method- Parameters:
a- The Input Matrix- Returns:
- The QR Orthogonalized Matrix
-
RQGrahamSchmidtOrthonormalization
public static final double[][] RQGrahamSchmidtOrthonormalization(double[][] a)Orthonormalize the Specified Matrix Using the RQ Graham-Schmidt Method- Parameters:
a- The Input Matrix- Returns:
- The RQ Orthonormalized Matrix
-
QRGrahamSchmidtOrthonormalization
public static final double[][] QRGrahamSchmidtOrthonormalization(double[][] a)Orthonormalize the Specified Matrix Using the QR Graham-Schmidt Method- Parameters:
a- The Input Matrix- Returns:
- The QR Orthonormalized Matrix
-
QRDecomposition
Perform a QR Decomposition on the Input Matrix- Parameters:
a- The Input Matrix- Returns:
- The Output of QR Decomposition
-
RQDecomposition
Perform a RQ Decomposition on the Input Matrix- Parameters:
a- The Input Matrix- Returns:
- The Output of RQ Decomposition
-
RayleighQuotient
public static final double RayleighQuotient(double[][] matrix, double[] eigenvector) throws java.lang.ExceptionCompute the Rayleigh Quotient given the Matrix and one of its Eigenvector- Parameters:
matrix- The Given Matrixeigenvector- The corresponding Eigenvector- Returns:
- The Computed Rayleigh Quotient
- Throws:
java.lang.Exception- Thrown if the Inputs are Invalid
-
Scale1D
public static final double[] Scale1D(double[] vector, double scaleFactor)Scale the Entries of the Input Vector by the Factor- Parameters:
vector- The Input VectorscaleFactor- The Scale Factor- Returns:
- The Scaled Matrix
-
Scale2D
public static final double[][] Scale2D(double[][] matrix, double scaleFactor)Scale the Entries of the Input Matrix by the Factor- Parameters:
matrix- The Input MatrixscaleFactor- The Scale Factor- Returns:
- The Scaled Matrix
-
IsDiagonal
public static final boolean IsDiagonal(double[][] matrix)Indicate if the Specified Matrix is Diagonal- Parameters:
matrix- The Matrix- Returns:
- TRUE - The Specified Matrix is Diagonal
-
IsSquare
public static final boolean IsSquare(double[][] matrix)Indicate if the Input Matrix is Square- Parameters:
matrix- Input Matrix- Returns:
- TRUE - Input Matrix is Square
-
Diagonal
public static final double[][] Diagonal(double[][] squareMatrix)Retrieve the Diagonal Elements in a Square Matrix- Parameters:
squareMatrix- Input Matrix- Returns:
- Diagonal Elements in a Square Matrix
-
StrictlyLowerTriangular
public static final double[][] StrictlyLowerTriangular(double[][] squareMatrix)Retrieve the Strictly Lower Triangular Elements in a Square Matrix- Parameters:
squareMatrix- Input Matrix- Returns:
- Strictly Lower Triangular Elements in a Square Matrix
-
StrictlyUpperTriangular
public static final double[][] StrictlyUpperTriangular(double[][] squareMatrix)Retrieve the Strictly Upper Triangular Elements in a Square Matrix- Parameters:
squareMatrix- Input Matrix- Returns:
- Strictly Upper Triangular Elements in a Square Matrix
-
JacobiIteration
public static final double[][] JacobiIteration(double[][] squareMatrix)Construct a Jacobi Iteration Matrix from the Square Matrix- Parameters:
squareMatrix- Square Matrix- Returns:
- Jacobi Iteration Matrix
-
IsSquareSymmetric
public static final boolean IsSquareSymmetric(double[][] squareMatrix)Indicate if the Input Matrix is Square and Symmetric- Parameters:
squareMatrix- Input Matrix- Returns:
- TRUE - Input Matrix is Square and Symmetric
-
IsTridiagonal
public static final boolean IsTridiagonal(double[][] squareMatrix)Indicate if the Input Matrix is Square and Tridiagonal- Parameters:
squareMatrix- Input Matrix- Returns:
- TRUE - Input Matrix is Square and Tridiagonal
-
IsPeriodicTridiagonal
public static final boolean IsPeriodicTridiagonal(double[][] squareMatrix)Indicate if the Input Matrix is Square and satisfies Periodic Tridiagonal Conditions- Parameters:
squareMatrix- Input Matrix- Returns:
- TRUE - Input Matrix is Square and satisfies Periodic Tridiagonal Conditions
-