wo80 / CSparse.NET

A concise library for solving sparse linear systems with direct methods.
GNU Lesser General Public License v2.1
58 stars 25 forks source link

MatrixSymmetricPositiveDefinite Exception is always thrown whenever cholesky factorization is used #4

Closed xahu closed 8 years ago

xahu commented 8 years ago

Hello, Here's a test case

[Test]
public void TestSparseCholesky()
{
    double[,] A = new double[,]
    {
        {1.0, 0.0, 4.0, 0.0 , 0.2 },
        {0.0, 1.0, 6.0, 0.0 , 0.0 },
        {4.0, 6.0, 6.0, 3.0 , 3.0 },
        {0.0, 0.0, 3.0, 0.5 , 0.0 },
        {0.2, 0.0, 3.0, 0.0 , 0.5 }
    };
    var x = new double[] { 1, 2, 3, 4, 5 };
    var y = new double[5];

    var ccs = Converter.ToCompressedColumnStorage(Converter.FromDenseArray(A));
    var chol = new CSparse.Double.Factorization.SparseCholesky(ccs, ColumnOrdering.MinimumDegreeAtPlusA);
    chol.Solve(x, y);
}
wo80 commented 8 years ago

Well, that's because the matrix is not positive definite.