package com.imsl.test.example.math; import com.imsl.math.*; import com.imsl.*; /** *

* Uses the Cholesky factorization of a complex * sparse matrix to solve a linear system. *

* 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. * * @see Code * @see Output * */ 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()); } }