public static void PreconditioningPosDefSparse() { Console.WriteLine("Assessing correctness and efficiency of preconditioned MINRES:\n"); var A = Matrix.CreateFromArray(SparsePosDef10by10.Matrix); var b = Vector.CreateFromArray(SparsePosDef10by10.Rhs); var xExpected = Vector.CreateFromArray(SparsePosDef10by10.Lhs); var M = new JacobiPreconditioner(A.GetDiagonalAsArray()); var minres = new MinRes(A.NumRows, 1e-10, 0, true, false); // Without preconditioning Console.WriteLine("Sparse pos-def system WITHOUT preconditioning:"); (IVector xSimple, MinresStatistics statsSimple) = minres.Solve(A, b); Console.Write(statsSimple); if (xSimple != null) { CheckSolution(xExpected, xSimple); } Console.WriteLine(); // With preconditioning Console.WriteLine("Sparse pos-def system WITH preconditioning:"); (IVector xPrec, MinresStatistics statsPrec) = minres.Solve(A, b, M); Console.Write(statsPrec); if (xPrec != null) { CheckSolution(xExpected, xPrec); } Console.WriteLine(); }
private static void TestIndefiniteSystem(LinearAlgebraProviderChoice providers) { TestSettings.RunMultiproviderTest(providers, delegate() { var comparer = new MatrixComparer(1E-4); double residualTolerance = 1e-8; (Matrix A, Vector b, Vector xExpected, IPreconditioner M) = DiagonalIndefinite.BuildIndefiniteSystem(20); var minres = new MinRes(A.NumRows, residualTolerance, 0, false, false); (IVector xComputed, MinresStatistics stats) = minres.Solve(A, b); comparer.AssertEqual(xExpected, xComputed); }); }
private static void TestPosDefSparseSystem(LinearAlgebraProviderChoice providers) { TestSettings.RunMultiproviderTest(providers, delegate() { var comparer = new MatrixComparer(1E-6); int n = SparsePosDef10by10.Order; var A = Matrix.CreateFromArray(SparsePosDef10by10.Matrix); var b = Vector.CreateFromArray(SparsePosDef10by10.Rhs); var xExpected = Vector.CreateFromArray(SparsePosDef10by10.Lhs); var minres = new MinRes(n, 1e-10, 0, false, false); (IVector xComputed, MinresStatistics stats) = minres.Solve(A, b); comparer.AssertEqual(xExpected, xComputed); }); }
public static void PreconditioningIndefinite() { Console.WriteLine("Dense pos-def system WITHOUT preconditioning:"); (Matrix A, Vector b, Vector xExpected, IPreconditioner M) = DiagonalIndefinite.BuildIndefiniteSystem(2000); var minres = new MinRes(A.NumRows, 1e-10, 0, true, false); // Without preconditioning (IVector xSimple, MinresStatistics statsSimple) = minres.Solve(A, b); Console.Write(statsSimple); if (xSimple != null) { CheckSolution(xExpected, xSimple); } Console.WriteLine(); // With preconditioning (IVector xPrec, MinresStatistics statsPrec) = minres.Solve(A, b, M); Console.Write(statsPrec); if (xPrec != null) { CheckSolution(xExpected, xPrec); } Console.WriteLine(); }