Example: Complex Sparse Cholesky Factorization

The Cholesky Factorization of a sparse hermitian positive definite matrix is used to solve a linear system. Some additional information about the Cholesky factorization is also computed.
import com.imsl.math.*;
import com.imsl.*;

public class  ComplexSparseCholeskyEx1  {
    public static void main(String args[]) throws IMSLException {
        
        ComplexSparseMatrix A = new ComplexSparseMatrix(3,3);
        
        A.set(0, 0, new Complex(2.0, 0.0));
        A.set(1, 0, new Complex(-1.0, -1.0));
        A.set(1, 1, new Complex(4.0, 0.0));
        A.set(2, 1, new Complex(1.0, -2.0));
        A.set(2, 2, new Complex(10.0, 0.0));

        Complex[] b = {
            new Complex(-2., 2.), new Complex(5., 15.), new Complex(36., 28.)};
        
        ComplexSparseCholesky cholesky = new ComplexSparseCholesky(A);
        
        // Choose Multifrontal method as numeric factorization method
        cholesky.setNumericFactorizationMethod(cholesky.MULTIFRONTAL_METHOD);
        
        // Compute solution
        Complex[] solution = cholesky.solve(b);
        
        PrintMatrix p = new PrintMatrix("Computed solution");
        p.print(solution);
        
        // Compute additional information about the factorization
        System.out.println("Smallest diagonal element of Cholesky factor: " +
                cholesky.getSmallestDiagonalElement());
        System.out.println("Largest diagonal element of Cholesky factor: " +
                cholesky.getLargestDiagonalElement());
        System.out.println("Number of nonzeros in Cholesky factor: " +
                cholesky.getNumberOfNonzeros());        
    }
}

Output

Computed solution
    0    
0  1+1i  
1  2+2i  
2  3+3i  

Smallest diagonal element of Cholesky factor: 1.4142135623730951
Largest diagonal element of Cholesky factor: 2.8867513459481287
Number of nonzeros in Cholesky factor: 5
Link to Java source.