Example: Cholesky Factorization

The Cholesky Factorization of a matrix is performed as well as its inverse.
import com.imsl.math.*;

public class CholeskyEx1 {
    public static void main(String args[]) throws com.imsl.IMSLException {
        double	a[][] = {
            { 1, -3,  2},
            {-3, 10, -5},
            { 2, -5,  6}
        };
        double	b[] = {27, -78, 64};
        
        // Compute the Cholesky factorization of A
        Cholesky	cholesky = new Cholesky(a);
        
        // Solve Ax = b
        double	x[] = cholesky.solve(b);
        new PrintMatrix("x").print(x);
        
        // Find the inverse of A.
        double	ainv[][] = cholesky.inverse();
        new PrintMatrix("ainv").print(ainv);
    }
}

Output

   x
   0   
0   1  
1  -4  
2   7  

     ainv
   0   1   2   
0  35   8  -5  
1   8   2  -1  
2  -5  -1   1  

Link to Java source.