Package jebl.math
Class MatrixCalc
java.lang.Object
jebl.math.MatrixCalc
- Author:
- Stephen A. Smith
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic double[][]
choleskyFactor
(double[][] inMatrix) Cholesky factorization (aka Cholesky Decomposition) This factorization can be used when square matrix is symmetric and positive definite.static double[]
choleskySolve
(double[][] matrix, double[] vector) Cholesky solve Once the matrix is decomposed with the above routine, one can solve the triangular factor with backsubstitution.static double[][]
copyMatrix
(double[][] matrix) copy one matrix into anotherstatic double[][]
deleteMatrixColumn
(double[][] matrix, int column) takes a matrix and deletes a columnstatic double[][]
deleteMatrixRow
(double[][] matrix, int row) takes a matrix and deletes a rowstatic double[]
getColumn
(double[][] matrix, int column) takes a matrix and gets a column, then returns it as a vectorstatic double
innerProduct
(double[] vector1, double[] vector2, int x) innerProdect calculates inner product of two vectors from i downstatic double[]
lowerSolve
(double[][] matrix, double[] vector, double diag) lower Solve forward elimination with (optional) default diagonal valuestatic double[][]
reverseMatrix
(double[][] matrix) reverse a matrixstatic double[]
reverseVector
(double[] vector) reverse a vectorstatic double
sumVector
(double[] vector) sum a vectorstatic double[]
upperSolve
(double[][] matrix, double[] vector, double diag) upperSolve back substitution with optional over-riding diagonal
-
Constructor Details
-
MatrixCalc
public MatrixCalc()
-
-
Method Details
-
choleskyFactor
public static double[][] choleskyFactor(double[][] inMatrix) throws MatrixCalcException.NotSquareMatrixException, MatrixCalcException.PositiveDefiniteException Cholesky factorization (aka Cholesky Decomposition) This factorization can be used when square matrix is symmetric and positive definite. It is much faster than other methods where symmetry is ignored (LU Decomposition).- Parameters:
inMatrix
- square symmetric matrix to perform cholesky factorization- Returns:
- resulting matrix
- Throws:
MatrixCalcException.NotSquareMatrixException
MatrixCalcException.PositiveDefiniteException
-
choleskySolve
public static double[] choleskySolve(double[][] matrix, double[] vector) throws MatrixCalcException.NotSquareMatrixException Cholesky solve Once the matrix is decomposed with the above routine, one can solve the triangular factor with backsubstitution. The forward (lowerSolve) and backward (upperSolve) are used for this.- Parameters:
matrix
- matrix to perform cholesky solve (probably used after factorization)vector
- vector to solve matrix * vector = return- Returns:
- the resulting vector
- Throws:
MatrixCalcException.NotSquareMatrixException
-
lowerSolve
public static double[] lowerSolve(double[][] matrix, double[] vector, double diag) lower Solve forward elimination with (optional) default diagonal value- Parameters:
matrix
- the matrix to perform the forward eliminationvector
-diag
- the default diagonal value- Returns:
- the resulting vector
-
upperSolve
public static double[] upperSolve(double[][] matrix, double[] vector, double diag) upperSolve back substitution with optional over-riding diagonal- Parameters:
matrix
- the matrix to perform the back substitutionvector
-diag
- the default diagonal value- Returns:
- the resulting vector
-
innerProduct
public static double innerProduct(double[] vector1, double[] vector2, int x) throws IndexOutOfBoundsException innerProdect calculates inner product of two vectors from i down- Parameters:
vector1
- the first vectorvector2
- the second vectorx
- the starting int- Returns:
- the inner product of the two vectors starting from x
- Throws:
IndexOutOfBoundsException
-
getColumn
public static double[] getColumn(double[][] matrix, int column) takes a matrix and gets a column, then returns it as a vector- Parameters:
matrix
- the matrix from which the column will be returnedcolumn
- the number of the column to return- Returns:
- the column as a vector from the input matrix
-
deleteMatrixRow
public static double[][] deleteMatrixRow(double[][] matrix, int row) takes a matrix and deletes a row- Parameters:
matrix
- the matrix from which to delete the rowrow
- the number of the row to delete- Returns:
- the matrix with deleted row
-
deleteMatrixColumn
public static double[][] deleteMatrixColumn(double[][] matrix, int column) takes a matrix and deletes a column- Parameters:
matrix
- the matrix from which to delete the columncolumn
- the number of the column to delete- Returns:
- the matrix with deleted column
-
reverseVector
public static double[] reverseVector(double[] vector) reverse a vector- Parameters:
vector
- the vector to reverse- Returns:
- the reversed vector
-
reverseMatrix
public static double[][] reverseMatrix(double[][] matrix) reverse a matrix- Parameters:
matrix
- the matrix to reverse- Returns:
- the reversed matrix
-
sumVector
public static double sumVector(double[] vector) sum a vector- Parameters:
vector
- the input vector- Returns:
- the sum of the vector
-
copyMatrix
public static double[][] copyMatrix(double[][] matrix) copy one matrix into another- Parameters:
matrix
- the matrix to copy- Returns:
- the copied matrix
-