jebl.math
Class MatrixCalc

java.lang.Object
  extended by jebl.math.MatrixCalc

public final class MatrixCalc
extends Object

Author:
Stephen A. Smith

Constructor Summary
MatrixCalc()
           
 
Method Summary
static 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 another
static double[][] deleteMatrixColumn(double[][] matrix, int column)
          takes a matrix and deletes a column
static double[][] deleteMatrixRow(double[][] matrix, int row)
          takes a matrix and deletes a row
static double[] getColumn(double[][] matrix, int column)
          takes a matrix and gets a column, then returns it as a vector
static double innerProduct(double[] vector1, double[] vector2, int x)
          innerProdect calculates inner product of two vectors from i down
static double[] lowerSolve(double[][] matrix, double[] vector, double diag)
          lower Solve forward elimination with (optional) default diagonal value
static double[][] reverseMatrix(double[][] matrix)
          reverse a matrix
static double[] reverseVector(double[] vector)
          reverse a vector
static double sumVector(double[] vector)
          sum a vector
static double[] upperSolve(double[][] matrix, double[] vector, double diag)
          upperSolve back substitution with optional over-riding diagonal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MatrixCalc

public MatrixCalc()
Method Detail

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 elimination
vector -
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 substitution
vector -
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 vector
vector2 - the second vector
x - 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 returned
column - 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 row
row - 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 column
column - 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