linear_algebra
Class Cholesky

java.lang.Object
  |
  +--linear_algebra.Cholesky

public class Cholesky
extends java.lang.Object

This class contains:

  1. a method that obtains the Cholesky factorization RR´, where R is a lower triangular matrix, of a symmetric positive definite matrix A.
  2. a method to invert a symmetric positive definite matrix.
  3. a method to solve Ax = b where A is a symmetric positive definite matrix.

This class was written by a statistician rather than a numerical analyst. I have tried to check the code carefully, but it may still contain bugs. Further, its stability and efficiency do not meet the standards of high quality numerical analysis software. When public domain Java numerical analysis routines become available from numerical analysts (e.g., the people who produce LAPACK), then THE CODE PRODUCED BY THE NUMERICAL ANALYSTS SHOULD BE USED.

Meanwhile, if you have suggestions for improving this code, please contact Steve Verrill at steve@ws10.fpl.fs.fed.us.


Constructor Summary
Cholesky()
           
 
Method Summary
 void factorPosDef(double[][] a, int n)
           This method factors the n by n symmetric positive definite matrix A as RR´ where R is a lower triangular matrix.
 void invertPosDef(double[][] a, int n, boolean factored)
           This method obtains the inverse of an n by n symmetric positive definite matrix A.

On entrance: If factored == false, the lower triangle of a[ ][ ] should contain the lower triangle of A.
If factored == true, the lower triangle of a[ ][ ] should contain a lower triangular matrix R such that RR´ = A.
 void solvePosDef(double[][] a, double[] b, double[] y, int n, boolean factored)
           This method solves the equation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Cholesky

public Cholesky()
Method Detail

factorPosDef

public void factorPosDef(double[][] a,
                         int n)
                  throws NotPosDefException

This method factors the n by n symmetric positive definite matrix A as RR´ where R is a lower triangular matrix. The method assumes that at least the lower triangle of A is filled on entry. On exit, the lower triangle of A has been replaced by R.

Parameters:
n - The order of the matrix a[ ][ ].
Throws:
NotPosDefException - if the factorization cannot be completed.

solvePosDef

public void solvePosDef(double[][] a,
                        double[] b,
                        double[] y,
                        int n,
                        boolean factored)
                 throws NotPosDefException

This method solves the equation


      Ax = b

where A is a known n by n symmetric positive definite matrix, and b is a known vector of length n.

On entrance:
If factored == false, the lower triangle of a[ ][ ] should contain the lower triangle of A.
If factored == true, the lower triangle of a[ ][ ] should contain a lower triangular matrix R such that RR´ = A.
On exit:
The elements of b have been replaced by the elements of x.

The method proceeds by first factoring A as RR´ where R is a lower triangular matrix. Thus Ax = b is equivalent to R(R´x) = b. Then the method performs two additional operations. First it solves Ry = b for y. Then it solves R´x = y for x. It stores x in b.

Parameters:
b - On entrance b must contain the known b of Ax = b. On exit it contains the solution x to Ax = b.
y - A work vector of order at least n.
n - The order of A and b.
factored - On entrance, factored should be set to true if A already has been factored, false if A has not yet been factored.
Throws:
NotPosDefException - if A cannot be factored as RR´ for a full rank lower triangular matrix R.

invertPosDef

public void invertPosDef(double[][] a,
                         int n,
                         boolean factored)
                  throws NotPosDefException

This method obtains the inverse of an n by n symmetric positive definite matrix A.

On entrance:
If factored == false, the lower triangle of a[ ][ ] should contain the lower triangle of A.
If factored == true, the lower triangle of a[ ][ ] should contain a lower triangular matrix R such that RR´ = A.
On exit:
The lower triangle of a[ ][ ] has been replaced by the lower triangle of the inverse of A.

Parameters:
n - The order of A.
factored - On entrance, factored should be set to true if A already has been factored, false if A has not yet been factored.
Throws:
NotPosDefException - if A cannot be factored as RR´ for a full rank lower triangular matrix R.