Example: Complex Sparse Cholesky Factorization
The Cholesky Factorization of a sparse Hermitian positive definite matrix is computed. Some additional information about the Cholesky factorization is also computed.
using System;
using Imsl.Math;
public class ComplexSparseCholeskyEx1
{
public static void Main(String[] args)
{
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.0, 2.0), new Complex(5.0, 15.0),
new Complex(36.0, 28.0)};
ComplexSparseCholesky cholesky = new ComplexSparseCholesky(A);
// Choose Multifrontal method as numeric factorization method
cholesky.NumericFactorizationMethod =
ComplexSparseCholesky.NumericFactorization.MultiFrontalMethod;
// Compute solution
Complex[] solution = cholesky.Solve(b);
PrintMatrix p = new PrintMatrix("Computed solution");
p.Print(solution);
// Compute additional information about the factorization
Console.Out.Write("Smallest diagonal element of Cholesky factor: ");
Console.Out.WriteLine(cholesky.SmallestDiagonalElement);
Console.Out.Write("Largest diagonal element of Cholesky factor: ");
Console.Out.WriteLine(cholesky.LargestDiagonalElement);
Console.Out.Write("Number of nonzeros in Cholesky factor: ");
Console.Out.WriteLine(cholesky.NumberOfNonzeros);
}
}
Output
Computed solution
0
0 1+1i
1 2+2i
2 3+3i
Smallest diagonal element of Cholesky factor: 1.4142135623731
Largest diagonal element of Cholesky factor: 2.88675134594813
Number of nonzeros in Cholesky factor: 5
Link to C# source.