Exemplo n.º 1
0
        void CompositeSolver <T>(Matrix <T> matrixA, Vector <T> vectorB, IIterativeSolver <T> solver) where T : struct, IEquatable <T>, IFormattable
        {
            var formatProvider = (CultureInfo)CultureInfo.InvariantCulture.Clone();

            formatProvider.TextInfo.ListSeparator = " ";

            Console.WriteLine(@"Matrix 'A' with coefficients");
            Console.WriteLine(matrixA.ToString("#0.00\t", formatProvider));
            Console.WriteLine();
            Console.WriteLine(@"Vector 'b' with the constant terms");
            Console.WriteLine(vectorB.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            var        iterationCountStopCriterion = new IterationCountStopCriterion <T>(1000);
            var        residualStopCriterion       = new ResidualStopCriterion <T>(1e-10);
            var        monitor = new Iterator <T>(iterationCountStopCriterion, residualStopCriterion);
            Vector <T> resultX = matrixA.SolveIterative(vectorB, solver, monitor);

            Console.WriteLine(@"2. Solver status of the iterations");
            Console.WriteLine(monitor.Status);
            Console.WriteLine();

            Console.WriteLine(@"3. Solution result vector of the matrix equation");
            Console.WriteLine(resultX.ToString("#0.00\t", formatProvider));
            Console.WriteLine();
        }
Exemplo n.º 2
0
        public void Solve(TypeOfFixation type, IBoundaryCondition conditions, ILoad load)
        {
            globalMatrix = solver.GlobalMatrix;
            results      = new double[length];

            SetLoads(load);
            SetBoundaryConditions(type, conditions);

            //List<double> nonZeroRows = globalMatrix.Storage.EnumerateNonZero().ToList();

            var iterationCountStopCriterion = new IterationCountStopCriterion <double>(length >> 1);
            var residualStopCriterion       = new ResidualStopCriterion <double>(ACCURACY);

            var monitor = new Iterator <double>(iterationCountStopCriterion, residualStopCriterion);

            var solverM = new TFQMR();

            //Vector<double> vectorResults = globalMatrix.LU().Solve(Vector.Build.DenseOfArray(loads));
            Vector <double> vectorResults = globalMatrix
                                            .SolveIterative(Vector.Build.DenseOfArray(loads), solverM, monitor);

            results = vectorResults.ToArray();
            for (int i = 0; i < results.Length; i++)
            {
                if (globalMatrix[i, i] == 1.0)
                {
                    results[i] = 0.0;
                }
            }
        }
        public void DetermineStatusWithIllegalIterationNumberThrowsArgumentOutOfRangeException()
        {
            var criterion = new IterationCountStopCriterion<float>(10);
            Assert.IsNotNull(criterion, "A criterion should have been created");

            Assert.That(() => criterion.DetermineStatus(-1, Vector<float>.Build.Dense(3, 1), Vector<float>.Build.Dense(3, 2), Vector<float>.Build.Dense(3, 3)), Throws.TypeOf<ArgumentOutOfRangeException>());
        }
        public void DetermineStatusWithIllegalIterationNumberThrowsArgumentOutOfRangeException()
        {
            var criterion = new IterationCountStopCriterion<double>(10);
            Assert.IsNotNull(criterion, "A criterion should have been created");

            Assert.That(() => criterion.DetermineStatus(-1, Vector<double>.Build.Dense(3, 1), Vector<double>.Build.Dense(3, 2), Vector<double>.Build.Dense(3, 3)), Throws.TypeOf<ArgumentOutOfRangeException>());
        }
        public void ResetMaximumIterations()
        {
            var criterion = new IterationCountStopCriterion<double>(10);
            Assert.IsNotNull(criterion, "A criterion should have been created");
            Assert.AreEqual(10, criterion.MaximumNumberOfIterations, "Incorrect maximum number of iterations");

            criterion.ResetMaximumNumberOfIterationsToDefault();
            Assert.AreNotEqual(10, criterion.MaximumNumberOfIterations, "Should have reset");
            Assert.AreEqual(IterationCountStopCriterion<double>.DefaultMaximumNumberOfIterations, criterion.MaximumNumberOfIterations, "Reset to the wrong value");
        }
        public void ResetMaximumIterations()
        {
            var criterion = new IterationCountStopCriterion<float>(10);
            Assert.IsNotNull(criterion, "A criterion should have been created");
            Assert.AreEqual(10, criterion.MaximumNumberOfIterations, "Incorrect maximum number of iterations");

            criterion.ResetMaximumNumberOfIterationsToDefault();
            Assert.AreNotEqual(10, criterion.MaximumNumberOfIterations, "Should have reset");
            Assert.AreEqual(IterationCountStopCriterion<float>.DefaultMaximumNumberOfIterations, criterion.MaximumNumberOfIterations, "Reset to the wrong value");
        }
        public void DetermineStatus()
        {
            var criterion = new IterationCountStopCriterion<double>(10);
            Assert.IsNotNull(criterion, "A criterion should have been created");

            var status = criterion.DetermineStatus(5, Vector<double>.Build.Dense(3, 1), Vector<double>.Build.Dense(3, 2), Vector<double>.Build.Dense(3, 3));
            Assert.AreEqual(IterationStatus.Continue, status, "Should be running");

            var status2 = criterion.DetermineStatus(10, Vector<double>.Build.Dense(3, 1), Vector<double>.Build.Dense(3, 2), Vector<double>.Build.Dense(3, 3));
            Assert.AreEqual(IterationStatus.StoppedWithoutConvergence, status2, "Should be finished");
        }
        public void ResetCalculationState()
        {
            var criterion = new IterationCountStopCriterion<double>(10);
            Assert.IsNotNull(criterion, "A criterion should have been created");

            var status = criterion.DetermineStatus(5, Vector<double>.Build.Dense(3, 1), Vector<double>.Build.Dense(3, 2), Vector<double>.Build.Dense(3, 3));
            Assert.AreEqual(IterationStatus.Continue, status, "Should be running");

            criterion.Reset();
            Assert.AreEqual(IterationStatus.Continue, criterion.Status, "Should not have started");
        }
Exemplo n.º 9
0
        private Complex[] CalculateSystemOfLinearEquations(Complex[,] matrixSystem, Complex[] matrixRightSide)
        {
            var matrixA = DenseMatrix.OfArray(matrixSystem);
            var vectorB = new DenseVector(matrixRightSide);
            var iterationCountStopCriterion = new IterationCountStopCriterion <Complex>(1000);
            var residualStopCriterion       = new ResidualStopCriterion <Complex>(1e-10);
            var monitor = new Iterator <Complex>(iterationCountStopCriterion, residualStopCriterion);
            var solver  = new BiCgStab();

            return(matrixA.SolveIterative(vectorB, solver, monitor).ToArray());
        }
Exemplo n.º 10
0
        // Method to set up parameters for iterative solver
        // Code for this method taken from the lecture slides (Lectures 5 and 6, solving 1D Heat Equation)
        private void SetUpSolver()
        {
            // Stop after 1000 iterations
            IterationCountStopCriterion <double> iterationCountStopCriterion
                = new IterationCountStopCriterion <double>(1000);

            // Stop after the error is less than 1e-8
            ResidualStopCriterion <double> residualStopCriterion
                = new ResidualStopCriterion <double>(1e-8);

            monitor = new Iterator <double>(iterationCountStopCriterion, residualStopCriterion);
            solver  = new BiCgStab();
        }
Exemplo n.º 11
0
        //Method to set up parameters for iterative solver
        private void SetUpSolver()
        {
            // Stop calculation if 1000 iterations reached during calculation
            IterationCountStopCriterion <double> iterationCountStopCriterion
                = new IterationCountStopCriterion <double>(1000);

            // Stop calculation if residuals are below 1e-8
            // i.e. the calculation is considered converged
            ResidualStopCriterion <double> residualStopCriterion
                = new ResidualStopCriterion <double>(1e-8);

            // Create monitor with defined stop criteria
            monitor = new Iterator <double>(iterationCountStopCriterion, residualStopCriterion);
            solver  = new BiCgStab();
        }
Exemplo n.º 12
0
    private void SetUpSolver()
    {
        // Stop calculation if 1000 iterations reached during calculation
        IterationCountStopCriterion <double> iterationCountStopCriterion = new IterationCountStopCriterion <double>(100);

        // Stop calculation if residuals are below 1E-10 --> the calculation is considered converged
        ResidualStopCriterion <double> residualStopCriterion = new ResidualStopCriterion <double>(1e-8);

        // Create monitor with defined stop criteria
        monitor = new Iterator <double>(iterationCountStopCriterion, residualStopCriterion);

        // Load all suitable solvers from current assembly. Below in this example, there is user-defined solver
        // "class UserBiCgStab : IIterativeSolverSetup<double>" which uses regular BiCgStab solver. But user may create any other solver
        // and solver setup classes which implement IIterativeSolverSetup<T> and pass assembly to next function:
        solver = new BiCgStab();
    }
Exemplo n.º 13
0
        public void solve()
        {
            Matrix <float> A = null;
            Vector <float> b = null;
            Vector <float> x = null;

            IIterationStopCriterion <float> count_stop_criterion    = new IterationCountStopCriterion <float>(5000);
            IIterationStopCriterion <float> residual_stop_criterion = new ResidualStopCriterion <float>(1e-10f);
            Iterator <float>        iterator       = new Iterator <float>(count_stop_criterion, residual_stop_criterion);
            IPreconditioner <float> preconditioner = null;



            BiCgStab solver = new BiCgStab();

            solver.Solve(A, b, x, iterator, preconditioner);
        }
        public void Clone()
        {
            var criterion = new IterationCountStopCriterion<Complex>(10);
            Assert.IsNotNull(criterion, "A criterion should have been created");
            Assert.AreEqual(10, criterion.MaximumNumberOfIterations, "Incorrect maximum");

            var clone = criterion.Clone();
            Assert.IsInstanceOf(typeof (IterationCountStopCriterion<Complex>), clone, "Wrong criterion type");

            var clonedCriterion = clone as IterationCountStopCriterion<Complex>;
            Assert.IsNotNull(clonedCriterion);

            // ReSharper disable PossibleNullReferenceException
            Assert.AreEqual(criterion.MaximumNumberOfIterations, clonedCriterion.MaximumNumberOfIterations, "Clone failed");

            // ReSharper restore PossibleNullReferenceException
        }
        public void Clone()
        {
            var criterion = new IterationCountStopCriterion<double>(10);
            Assert.IsNotNull(criterion, "A criterion should have been created");
            Assert.AreEqual(10, criterion.MaximumNumberOfIterations, "Incorrect maximum");

            var clone = criterion.Clone();
            Assert.IsInstanceOf(typeof (IterationCountStopCriterion<double>), clone, "Wrong criterion type");

            var clonedCriterion = clone as IterationCountStopCriterion<double>;
            Assert.IsNotNull(clonedCriterion);

            // ReSharper disable PossibleNullReferenceException
            Assert.AreEqual(criterion.MaximumNumberOfIterations, clonedCriterion.MaximumNumberOfIterations, "Clone failed");

            // ReSharper restore PossibleNullReferenceException
        }
Exemplo n.º 16
0
        static int Main(string[] args)
        {
            if (args.Length < 1 || args.Length > 2)
            {
                Console.WriteLine("Use: LinearEquationSolver.exe <matrix.csv> [<number-of-iterations>]");
                return(2);
            }

            Table table = Table.Load(args[0], new ReadSettings(Delimiter.Comma, false, false, FSharpOption <int> .None, ReadSettings.Default.ColumnTypes));

            if (table.Count <= 1)
            {
                throw new Exception("Expecting 2 or more columns");
            }


            var n = args.Length >= 2 ? int.Parse(args[1], CultureInfo.InvariantCulture) : 1;

            var columns = table.Select(column => column.Rows.AsReal as IEnumerable <double>);
            var A       = Matrix <double> .Build.DenseOfColumns(columns.Where((_, i) => i < table.Count - 1));

            var b = Vector <double> .Build.DenseOfEnumerable(columns.Last());

            var iterationCountStopCriterion = new IterationCountStopCriterion <double>(1000);
            var residualStopCriterion       = new ResidualStopCriterion <double>(1e-10);
            var monitor = new Iterator <double>(iterationCountStopCriterion, residualStopCriterion);
            var solver  = new CompositeSolver(SolverSetup <double> .LoadFromAssembly(System.Reflection.Assembly.GetExecutingAssembly()));

            Vector <double> x = null;

            for (var i = 0; i < n; i++)
            {
                //x = A.Solve(b);
                x = A.SolveIterative(b, solver, monitor);
            }

            Table result = Table.OfColumns(new[] { Column.Create("x", x.ToArray(), FSharpOption <int> .None) });

            Table.Save(result, "result.csv");

            return(0);
        }
 public void Create()
 {
     var criterion = new IterationCountStopCriterion<float>(10);
     Assert.IsNotNull(criterion, "A criterion should have been created");
 }
        public void ResetCalculationState()
        {
            var criterion = new IterationCountStopCriterion<float>(10);
            Assert.IsNotNull(criterion, "A criterion should have been created");

            var status = criterion.DetermineStatus(5, Vector<float>.Build.Dense(3, 1), Vector<float>.Build.Dense(3, 2), Vector<float>.Build.Dense(3, 3));
            Assert.AreEqual(IterationStatus.Continue, status, "Should be running");

            criterion.Reset();
            Assert.AreEqual(IterationStatus.Continue, criterion.Status, "Should not have started");
        }
Exemplo n.º 19
0
 private void InitializeSolver()
 {
     result = Vector<double>.Build.Dense(n * m);
       Control.LinearAlgebraProvider = new OpenBlasLinearAlgebraProvider();
     //Control.UseNativeMKL();
     //Control.LinearAlgebraProvider = new MklLinearAlgebraProvider();
     //Control.UseManaged();
     var iterationCountStopCriterion = new IterationCountStopCriterion<double>(1000);
     var residualStopCriterion = new ResidualStopCriterion<double>(1e-7);
     monitor = new Iterator<double>(iterationCountStopCriterion, residualStopCriterion);
     solver = new BiCgStab();
     preconditioner = new MILU0Preconditioner();
 }
Exemplo n.º 20
0
        /// <summary>
        /// Run example
        /// </summary>
        public void Run()
        {
            // Format matrix output to console
            var formatProvider = (CultureInfo)CultureInfo.InvariantCulture.Clone();
            formatProvider.TextInfo.ListSeparator = " ";

            // Solve next system of linear equations (Ax=b):
            // 5*x + 2*y - 4*z = -7
            // 3*x - 7*y + 6*z = 38
            // 4*x + 1*y + 5*z = 43

            // Create matrix "A" with coefficients
            var matrixA = DenseMatrix.OfArray(new[,] { { 5.00, 2.00, -4.00 }, { 3.00, -7.00, 6.00 }, { 4.00, 1.00, 5.00 } });
            Console.WriteLine(@"Matrix 'A' with coefficients");
            Console.WriteLine(matrixA.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // Create vector "b" with the constant terms.
            var vectorB = new DenseVector(new[] { -7.0, 38.0, 43.0 });
            Console.WriteLine(@"Vector 'b' with the constant terms");
            Console.WriteLine(vectorB.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // Create stop criteria to monitor an iterative calculation. There are next available stop criteria:
            // - DivergenceStopCriterion: monitors an iterative calculation for signs of divergence;
            // - FailureStopCriterion: monitors residuals for NaN's;
            // - IterationCountStopCriterion: monitors the numbers of iteration steps;
            // - ResidualStopCriterion: monitors residuals if calculation is considered converged;

            // Stop calculation if 1000 iterations reached during calculation
            var iterationCountStopCriterion = new IterationCountStopCriterion<double>(1000);

            // Stop calculation if residuals are below 1E-10 --> the calculation is considered converged
            var residualStopCriterion = new ResidualStopCriterion<double>(1e-10);

            // Create monitor with defined stop criteria
            var monitor = new Iterator<double>(iterationCountStopCriterion, residualStopCriterion);

            // Create Multiple-Lanczos Bi-Conjugate Gradient Stabilized solver
            var solver = new MlkBiCgStab();

            // 1. Solve the matrix equation
            var resultX = matrixA.SolveIterative(vectorB, solver, monitor);
            Console.WriteLine(@"1. Solve the matrix equation");
            Console.WriteLine();

            // 2. Check solver status of the iterations.
            // Solver has property IterationResult which contains the status of the iteration once the calculation is finished.
            // Possible values are:
            // - CalculationCancelled: calculation was cancelled by the user;
            // - CalculationConverged: calculation has converged to the desired convergence levels;
            // - CalculationDiverged: calculation diverged;
            // - CalculationFailure: calculation has failed for some reason;
            // - CalculationIndetermined: calculation is indetermined, not started or stopped;
            // - CalculationRunning: calculation is running and no results are yet known;
            // - CalculationStoppedWithoutConvergence: calculation has been stopped due to reaching the stopping limits, but that convergence was not achieved;
            Console.WriteLine(@"2. Solver status of the iterations");
            Console.WriteLine(monitor.Status);
            Console.WriteLine();

            // 3. Solution result vector of the matrix equation
            Console.WriteLine(@"3. Solution result vector of the matrix equation");
            Console.WriteLine(resultX.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 4. Verify result. Multiply coefficient matrix "A" by result vector "x"
            var reconstructVecorB = matrixA*resultX;
            Console.WriteLine(@"4. Multiply coefficient matrix 'A' by result vector 'x'");
            Console.WriteLine(reconstructVecorB.ToString("#0.00\t", formatProvider));
            Console.WriteLine();
        }
Exemplo n.º 21
0
        /// <summary>
        /// Run example
        /// </summary>
        /// <seealso cref="http://en.wikipedia.org/wiki/Biconjugate_gradient_stabilized_method">Biconjugate gradient stabilized method</seealso>
        public void Run()
        {
            // Format matrix output to console
            var formatProvider = (CultureInfo)CultureInfo.InvariantCulture.Clone();

            formatProvider.TextInfo.ListSeparator = " ";

            // Solve next system of linear equations (Ax=b):
            // 5*x + 2*y - 4*z = -7
            // 3*x - 7*y + 6*z = 38
            // 4*x + 1*y + 5*z = 43

            // Create matrix "A" with coefficients
            var matrixA = DenseMatrix.OfArray(new[, ] {
                { 5.00, 2.00, -4.00 }, { 3.00, -7.00, 6.00 }, { 4.00, 1.00, 5.00 }
            });

            Console.WriteLine(@"Matrix 'A' with coefficients");
            Console.WriteLine(matrixA.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // Create vector "b" with the constant terms.
            var vectorB = new DenseVector(new[] { -7.0, 38.0, 43.0 });

            Console.WriteLine(@"Vector 'b' with the constant terms");
            Console.WriteLine(vectorB.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // Create stop criteria to monitor an iterative calculation. There are next available stop criteria:
            // - DivergenceStopCriterion: monitors an iterative calculation for signs of divergence;
            // - FailureStopCriterion: monitors residuals for NaN's;
            // - IterationCountStopCriterion: monitors the numbers of iteration steps;
            // - ResidualStopCriterion: monitors residuals if calculation is considered converged;

            // Stop calculation if 1000 iterations reached during calculation
            var iterationCountStopCriterion = new IterationCountStopCriterion <double>(1000);

            // Stop calculation if residuals are below 1E-10 --> the calculation is considered converged
            var residualStopCriterion = new ResidualStopCriterion <double>(1e-10);

            // Create monitor with defined stop criteria
            var monitor = new Iterator <double>(iterationCountStopCriterion, residualStopCriterion);

            // Create Bi-Conjugate Gradient Stabilized solver
            var solver = new BiCgStab();

            // 1. Solve the matrix equation
            var resultX = matrixA.SolveIterative(vectorB, solver, monitor);

            Console.WriteLine(@"1. Solve the matrix equation");
            Console.WriteLine();

            // 2. Check solver status of the iterations.
            // Solver has property IterationResult which contains the status of the iteration once the calculation is finished.
            // Possible values are:
            // - CalculationCancelled: calculation was cancelled by the user;
            // - CalculationConverged: calculation has converged to the desired convergence levels;
            // - CalculationDiverged: calculation diverged;
            // - CalculationFailure: calculation has failed for some reason;
            // - CalculationIndetermined: calculation is indetermined, not started or stopped;
            // - CalculationRunning: calculation is running and no results are yet known;
            // - CalculationStoppedWithoutConvergence: calculation has been stopped due to reaching the stopping limits, but that convergence was not achieved;
            Console.WriteLine(@"2. Solver status of the iterations");
            Console.WriteLine(monitor.Status);
            Console.WriteLine();

            // 3. Solution result vector of the matrix equation
            Console.WriteLine(@"3. Solution result vector of the matrix equation");
            Console.WriteLine(resultX.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 4. Verify result. Multiply coefficient matrix "A" by result vector "x"
            var reconstructVecorB = matrixA * resultX;

            Console.WriteLine(@"4. Multiply coefficient matrix 'A' by result vector 'x'");
            Console.WriteLine(reconstructVecorB.ToString("#0.00\t", formatProvider));
            Console.WriteLine();
        }
        public void DetermineStatus()
        {
            var criterion = new IterationCountStopCriterion<float>(10);
            Assert.IsNotNull(criterion, "A criterion should have been created");

            var status = criterion.DetermineStatus(5, Vector<float>.Build.Dense(3, 1), Vector<float>.Build.Dense(3, 2), Vector<float>.Build.Dense(3, 3));
            Assert.AreEqual(IterationStatus.Continue, status, "Should be running");

            var status2 = criterion.DetermineStatus(10, Vector<float>.Build.Dense(3, 1), Vector<float>.Build.Dense(3, 2), Vector<float>.Build.Dense(3, 3));
            Assert.AreEqual(IterationStatus.StoppedWithoutConvergence, status2, "Should be finished");
        }
        public void Create()
        {
            var criterion = new IterationCountStopCriterion <Complex32>(10);

            Assert.IsNotNull(criterion, "A criterion should have been created");
        }
        public override void ExecuteExample()
        {
            // <seealso cref="http://en.wikipedia.org/wiki/Biconjugate_gradient_stabilized_method">Biconjugate gradient stabilized method</seealso>
            MathDisplay.WriteLine("<b>Biconjugate gradient stabilised iterative solver</b>");

            // Format matrix output to console
            var formatProvider = (CultureInfo)CultureInfo.InvariantCulture.Clone();

            formatProvider.TextInfo.ListSeparator = " ";

            // Solve next system of linear equations (Ax=b):
            // 5*x + 2*y - 4*z = -7
            // 3*x - 7*y + 6*z = 38
            // 4*x + 1*y + 5*z = 43

            // Create matrix "A" with coefficients
            var matrixA = DenseMatrix.OfArray(new[, ] {
                { 5.00, 2.00, -4.00 }, { 3.00, -7.00, 6.00 }, { 4.00, 1.00, 5.00 }
            });

            MathDisplay.WriteLine(@"Matrix 'A' with coefficients");
            MathDisplay.WriteLine(matrixA.ToString("#0.00\t", formatProvider));
            MathDisplay.WriteLine();

            // Create vector "b" with the constant terms.
            var vectorB = new DenseVector(new[] { -7.0, 38.0, 43.0 });

            MathDisplay.WriteLine(@"Vector 'b' with the constant terms");
            MathDisplay.WriteLine(vectorB.ToString("#0.00\t", formatProvider));
            MathDisplay.WriteLine();

            // Create stop criteria to monitor an iterative calculation. There are next available stop criteria:
            // - DivergenceStopCriterion: monitors an iterative calculation for signs of divergence;
            // - FailureStopCriterion: monitors residuals for NaN's;
            // - IterationCountStopCriterion: monitors the numbers of iteration steps;
            // - ResidualStopCriterion: monitors residuals if calculation is considered converged;

            // Stop calculation if 1000 iterations reached during calculation
            var iterationCountStopCriterion = new IterationCountStopCriterion <double>(1000);

            // Stop calculation if residuals are below 1E-10 --> the calculation is considered converged
            var residualStopCriterion = new ResidualStopCriterion <double>(1e-10);

            // Create monitor with defined stop criteria
            var monitor = new Iterator <double>(iterationCountStopCriterion, residualStopCriterion);

            // Create Bi-Conjugate Gradient Stabilized solver
            var solverBiCgStab = new BiCgStab();

            // 1. Solve the matrix equation
            var resultX = matrixA.SolveIterative(vectorB, solverBiCgStab, monitor);

            MathDisplay.WriteLine(@"1. Solve the matrix equation");
            MathDisplay.WriteLine();

            // 2. Check solver status of the iterations.
            // Solver has property IterationResult which contains the status of the iteration once the calculation is finished.
            // Possible values are:
            // - CalculationCancelled: calculation was cancelled by the user;
            // - CalculationConverged: calculation has converged to the desired convergence levels;
            // - CalculationDiverged: calculation diverged;
            // - CalculationFailure: calculation has failed for some reason;
            // - CalculationIndetermined: calculation is indetermined, not started or stopped;
            // - CalculationRunning: calculation is running and no results are yet known;
            // - CalculationStoppedWithoutConvergence: calculation has been stopped due to reaching the stopping limits, but that convergence was not achieved;
            MathDisplay.WriteLine(@"2. Solver status of the iterations");
            MathDisplay.WriteLine(monitor.Status.ToString());
            MathDisplay.WriteLine();

            // 3. Solution result vector of the matrix equation
            MathDisplay.WriteLine(@"3. Solution result vector of the matrix equation");
            MathDisplay.WriteLine(resultX.ToString("#0.00\t", formatProvider));
            MathDisplay.WriteLine();

            // 4. Verify result. Multiply coefficient matrix "A" by result vector "x"
            var reconstructVecorB = matrixA * resultX;

            MathDisplay.WriteLine(@"4. Multiply coefficient matrix 'A' by result vector 'x'");
            MathDisplay.WriteLine(reconstructVecorB.ToString("#0.00\t", formatProvider));
            MathDisplay.WriteLine();



            MathDisplay.WriteLine("<b>Generalized product biconjugate gradient solver</b>");

            // Solve next system of linear equations (Ax=b):
            // 5*x + 2*y - 4*z = -7
            // 3*x - 7*y + 6*z = 38
            // 4*x + 1*y + 5*z = 43

            // Create matrix "A" with coefficients
            matrixA = DenseMatrix.OfArray(new[, ] {
                { 5.00, 2.00, -4.00 }, { 3.00, -7.00, 6.00 }, { 4.00, 1.00, 5.00 }
            });
            MathDisplay.WriteLine(@"Matrix 'A' with coefficients");
            MathDisplay.WriteLine(matrixA.ToString("#0.00\t", formatProvider));
            MathDisplay.WriteLine();

            // Create vector "b" with the constant terms.
            vectorB = new DenseVector(new[] { -7.0, 38.0, 43.0 });
            MathDisplay.WriteLine(@"Vector 'b' with the constant terms");
            MathDisplay.WriteLine(vectorB.ToString("#0.00\t", formatProvider));
            MathDisplay.WriteLine();

            // Create stop criteria to monitor an iterative calculation. There are next available stop criteria:
            // - DivergenceStopCriterion: monitors an iterative calculation for signs of divergence;
            // - FailureStopCriterion: monitors residuals for NaN's;
            // - IterationCountStopCriterion: monitors the numbers of iteration steps;
            // - ResidualStopCriterion: monitors residuals if calculation is considered converged;

            // Stop calculation if 1000 iterations reached during calculation
            iterationCountStopCriterion = new IterationCountStopCriterion <double>(1000);

            // Stop calculation if residuals are below 1E-10 --> the calculation is considered converged
            residualStopCriterion = new ResidualStopCriterion <double>(1e-10);

            // Create monitor with defined stop criteria
            monitor = new Iterator <double>(iterationCountStopCriterion, residualStopCriterion);

            // Create Generalized Product Bi-Conjugate Gradient solver
            var solverGpBiCg = new GpBiCg();

            // 1. Solve the matrix equation
            resultX = matrixA.SolveIterative(vectorB, solverGpBiCg, monitor);
            MathDisplay.WriteLine(@"1. Solve the matrix equation");
            MathDisplay.WriteLine();

            // 2. Check solver status of the iterations.
            // Solver has property IterationResult which contains the status of the iteration once the calculation is finished.
            // Possible values are:
            // - CalculationCancelled: calculation was cancelled by the user;
            // - CalculationConverged: calculation has converged to the desired convergence levels;
            // - CalculationDiverged: calculation diverged;
            // - CalculationFailure: calculation has failed for some reason;
            // - CalculationIndetermined: calculation is indetermined, not started or stopped;
            // - CalculationRunning: calculation is running and no results are yet known;
            // - CalculationStoppedWithoutConvergence: calculation has been stopped due to reaching the stopping limits, but that convergence was not achieved;
            MathDisplay.WriteLine(@"2. Solver status of the iterations");
            MathDisplay.WriteLine(monitor.Status.ToString());
            MathDisplay.WriteLine();

            // 3. Solution result vector of the matrix equation
            MathDisplay.WriteLine(@"3. Solution result vector of the matrix equation");
            MathDisplay.WriteLine(resultX.ToString("#0.00\t", formatProvider));
            MathDisplay.WriteLine();

            // 4. Verify result. Multiply coefficient matrix "A" by result vector "x"
            reconstructVecorB = matrixA * resultX;
            MathDisplay.WriteLine(@"4. Multiply coefficient matrix 'A' by result vector 'x'");
            MathDisplay.WriteLine(reconstructVecorB.ToString("#0.00\t", formatProvider));
            MathDisplay.WriteLine();


            MathDisplay.WriteLine("<b>Composite linear equation solver</b>");

            // Solve next system of linear equations (Ax=b):
            // 5*x + 2*y - 4*z = -7
            // 3*x - 7*y + 6*z = 38
            // 4*x + 1*y + 5*z = 43

            // Create matrix "A" with coefficients
            matrixA = DenseMatrix.OfArray(new[, ] {
                { 5.00, 2.00, -4.00 }, { 3.00, -7.00, 6.00 }, { 4.00, 1.00, 5.00 }
            });
            MathDisplay.WriteLine(@"Matrix 'A' with coefficients");
            MathDisplay.WriteLine(matrixA.ToString("#0.00\t", formatProvider));
            MathDisplay.WriteLine();

            // Create vector "b" with the constant terms.
            vectorB = new DenseVector(new[] { -7.0, 38.0, 43.0 });
            MathDisplay.WriteLine(@"Vector 'b' with the constant terms");
            MathDisplay.WriteLine(vectorB.ToString("#0.00\t", formatProvider));
            MathDisplay.WriteLine();

            // Create stop criteria to monitor an iterative calculation. There are next available stop criteria:
            // - DivergenceStopCriterion: monitors an iterative calculation for signs of divergence;
            // - FailureStopCriterion: monitors residuals for NaN's;
            // - IterationCountStopCriterion: monitors the numbers of iteration steps;
            // - ResidualStopCriterion: monitors residuals if calculation is considered converged;

            // Stop calculation if 1000 iterations reached during calculation
            iterationCountStopCriterion = new IterationCountStopCriterion <double>(1000);

            // Stop calculation if residuals are below 1E-10 --> the calculation is considered converged
            residualStopCriterion = new ResidualStopCriterion <double>(1e-10);

            // Create monitor with defined stop criteria
            monitor = new Iterator <double>(iterationCountStopCriterion, residualStopCriterion);

            // Load all suitable solvers from current assembly. Below (see UserBiCgStab) there is a custom user-defined solver
            // "class UserBiCgStab : IIterativeSolverSetup<double>" which derives from the regular BiCgStab solver. However users can
            // create any other solver and solver setup classes that implement IIterativeSolverSetup<T> and load the assembly that
            // contains them using the following function:
            var solverComp = new CompositeSolver(SolverSetup <double> .LoadFromAssembly(Assembly.GetExecutingAssembly()));

            // 1. Solve the linear system
            resultX = matrixA.SolveIterative(vectorB, solverComp, monitor);
            MathDisplay.WriteLine(@"1. Solve the matrix equation");
            MathDisplay.WriteLine();

            // 2. Check solver status of the iterations.
            // Solver has property IterationResult which contains the status of the iteration once the calculation is finished.
            // Possible values are:
            // - CalculationCancelled: calculation was cancelled by the user;
            // - CalculationConverged: calculation has converged to the desired convergence levels;
            // - CalculationDiverged: calculation diverged;
            // - CalculationFailure: calculation has failed for some reason;
            // - CalculationIndetermined: calculation is indetermined, not started or stopped;
            // - CalculationRunning: calculation is running and no results are yet known;
            // - CalculationStoppedWithoutConvergence: calculation has been stopped due to reaching the stopping limits, but that convergence was not achieved;
            MathDisplay.WriteLine(@"2. Solver status of the iterations");
            MathDisplay.WriteLine(monitor.Status.ToString());
            MathDisplay.WriteLine();

            // 3. Solution result vector of the matrix equation
            MathDisplay.WriteLine(@"3. Solution result vector of the matrix equation");
            MathDisplay.WriteLine(resultX.ToString("#0.00\t", formatProvider));
            MathDisplay.WriteLine();

            // 4. Verify result. Multiply coefficient matrix "A" by result vector "x"
            reconstructVecorB = matrixA * resultX;
            MathDisplay.WriteLine(@"4. Multiply coefficient matrix 'A' by result vector 'x'");
            MathDisplay.WriteLine(reconstructVecorB.ToString("#0.00\t", formatProvider));
            MathDisplay.WriteLine();


            MathDisplay.WriteLine("<b>Multiple-Lanczos biconjugate gradient stabilised iterative solver</b>");

            // Solve next system of linear equations (Ax=b):
            // 5*x + 2*y - 4*z = -7
            // 3*x - 7*y + 6*z = 38
            // 4*x + 1*y + 5*z = 43

            // Create matrix "A" with coefficients
            matrixA = DenseMatrix.OfArray(new[, ] {
                { 5.00, 2.00, -4.00 }, { 3.00, -7.00, 6.00 }, { 4.00, 1.00, 5.00 }
            });
            MathDisplay.WriteLine(@"Matrix 'A' with coefficients");
            MathDisplay.WriteLine(matrixA.ToString("#0.00\t", formatProvider));
            MathDisplay.WriteLine();

            // Create vector "b" with the constant terms.
            vectorB = new DenseVector(new[] { -7.0, 38.0, 43.0 });
            MathDisplay.WriteLine(@"Vector 'b' with the constant terms");
            MathDisplay.WriteLine(vectorB.ToString("#0.00\t", formatProvider));
            MathDisplay.WriteLine();

            // Create stop criteria to monitor an iterative calculation. There are next available stop criteria:
            // - DivergenceStopCriterion: monitors an iterative calculation for signs of divergence;
            // - FailureStopCriterion: monitors residuals for NaN's;
            // - IterationCountStopCriterion: monitors the numbers of iteration steps;
            // - ResidualStopCriterion: monitors residuals if calculation is considered converged;

            // Stop calculation if 1000 iterations reached during calculation
            iterationCountStopCriterion = new IterationCountStopCriterion <double>(1000);

            // Stop calculation if residuals are below 1E-10 --> the calculation is considered converged
            residualStopCriterion = new ResidualStopCriterion <double>(1e-10);

            // Create monitor with defined stop criteria
            monitor = new Iterator <double>(iterationCountStopCriterion, residualStopCriterion);

            // Create Multiple-Lanczos Bi-Conjugate Gradient Stabilized solver
            var solverLanczos = new MlkBiCgStab();

            // 1. Solve the matrix equation
            resultX = matrixA.SolveIterative(vectorB, solverLanczos, monitor);
            MathDisplay.WriteLine(@"1. Solve the matrix equation");
            MathDisplay.WriteLine();

            // 2. Check solver status of the iterations.
            // Solver has property IterationResult which contains the status of the iteration once the calculation is finished.
            // Possible values are:
            // - CalculationCancelled: calculation was cancelled by the user;
            // - CalculationConverged: calculation has converged to the desired convergence levels;
            // - CalculationDiverged: calculation diverged;
            // - CalculationFailure: calculation has failed for some reason;
            // - CalculationIndetermined: calculation is indetermined, not started or stopped;
            // - CalculationRunning: calculation is running and no results are yet known;
            // - CalculationStoppedWithoutConvergence: calculation has been stopped due to reaching the stopping limits, but that convergence was not achieved;
            MathDisplay.WriteLine(@"2. Solver status of the iterations");
            MathDisplay.WriteLine(monitor.Status.ToString());
            MathDisplay.WriteLine();

            // 3. Solution result vector of the matrix equation
            MathDisplay.WriteLine(@"3. Solution result vector of the matrix equation");
            MathDisplay.WriteLine(resultX.ToString("#0.00\t", formatProvider));
            MathDisplay.WriteLine();

            // 4. Verify result. Multiply coefficient matrix "A" by result vector "x"
            reconstructVecorB = matrixA * resultX;
            MathDisplay.WriteLine(@"4. Multiply coefficient matrix 'A' by result vector 'x'");
            MathDisplay.WriteLine(reconstructVecorB.ToString("#0.00\t", formatProvider));
            MathDisplay.WriteLine();


            MathDisplay.WriteLine("<b>Transpose freee quasi-minimal residual iterative solver</b>");

            // Solve next system of linear equations (Ax=b):
            // 5*x + 2*y - 4*z = -7
            // 3*x - 7*y + 6*z = 38
            // 4*x + 1*y + 5*z = 43

            // Create matrix "A" with coefficients
            matrixA = DenseMatrix.OfArray(new[, ] {
                { 5.00, 2.00, -4.00 }, { 3.00, -7.00, 6.00 }, { 4.00, 1.00, 5.00 }
            });
            MathDisplay.WriteLine(@"Matrix 'A' with coefficients");
            MathDisplay.WriteLine(matrixA.ToString("#0.00\t", formatProvider));
            MathDisplay.WriteLine();

            // Create vector "b" with the constant terms.
            vectorB = new DenseVector(new[] { -7.0, 38.0, 43.0 });
            MathDisplay.WriteLine(@"Vector 'b' with the constant terms");
            MathDisplay.WriteLine(vectorB.ToString("#0.00\t", formatProvider));
            MathDisplay.WriteLine();

            // Create stop criteria to monitor an iterative calculation. There are next available stop criteria:
            // - DivergenceStopCriterion: monitors an iterative calculation for signs of divergence;
            // - FailureStopCriterion: monitors residuals for NaN's;
            // - IterationCountStopCriterion: monitors the numbers of iteration steps;
            // - ResidualStopCriterion: monitors residuals if calculation is considered converged;

            // Stop calculation if 1000 iterations reached during calculation
            iterationCountStopCriterion = new IterationCountStopCriterion <double>(1000);

            // Stop calculation if residuals are below 1E-10 --> the calculation is considered converged
            residualStopCriterion = new ResidualStopCriterion <double>(1e-10);

            // Create monitor with defined stop criteria
            monitor = new Iterator <double>(iterationCountStopCriterion, residualStopCriterion);

            // Create Transpose Free Quasi-Minimal Residual solver
            var solverTFQMR = new TFQMR();

            // 1. Solve the matrix equation
            resultX = matrixA.SolveIterative(vectorB, solverTFQMR, monitor);
            MathDisplay.WriteLine(@"1. Solve the matrix equation");
            MathDisplay.WriteLine();

            // 2. Check solver status of the iterations.
            // Solver has property IterationResult which contains the status of the iteration once the calculation is finished.
            // Possible values are:
            // - CalculationCancelled: calculation was cancelled by the user;
            // - CalculationConverged: calculation has converged to the desired convergence levels;
            // - CalculationDiverged: calculation diverged;
            // - CalculationFailure: calculation has failed for some reason;
            // - CalculationIndetermined: calculation is indetermined, not started or stopped;
            // - CalculationRunning: calculation is running and no results are yet known;
            // - CalculationStoppedWithoutConvergence: calculation has been stopped due to reaching the stopping limits, but that convergence was not achieved;
            MathDisplay.WriteLine(@"2. Solver status of the iterations");
            MathDisplay.WriteLine(monitor.Status.ToString());
            MathDisplay.WriteLine();

            // 3. Solution result vector of the matrix equation
            MathDisplay.WriteLine(@"3. Solution result vector of the matrix equation");
            MathDisplay.WriteLine(resultX.ToString("#0.00\t", formatProvider));
            MathDisplay.WriteLine();

            // 4. Verify result. Multiply coefficient matrix "A" by result vector "x"
            reconstructVecorB = matrixA * resultX;
            MathDisplay.WriteLine(@"4. Multiply coefficient matrix 'A' by result vector 'x'");
            MathDisplay.WriteLine(reconstructVecorB.ToString("#0.00\t", formatProvider));
            MathDisplay.WriteLine();
        }