public void Test6()
        {
            MatrixD A = new MatrixD(new double[, ] {
                { -21, 2, -4, 0 },
                { 2, 3, 0.1, -1 },
                { 2, 10, 111.1, -11 },
                { 23, 112, 111.1, -143 }
            });
            VectorD b = new VectorD(new double[] { 20, 28, -12, 0.1 });

            SorMethodD solver = new SorMethodD();

            solver.MaxNumberOfIterations = 4;
            VectorD x = solver.Solve(A, null, b);

            VectorD solution = MatrixD.SolveLinearEquations(A, b);

            Assert.IsFalse(VectorD.AreNumericallyEqual(solution, x));
            Assert.AreEqual(4, solver.NumberOfIterations);

            // Compare with Gauss-Seidel. Must be equal.
            GaussSeidelMethodD gsSolver = new GaussSeidelMethodD();

            gsSolver.MaxNumberOfIterations = 4;
            VectorD gsSolution = gsSolver.Solve(A, null, b);

            Assert.IsTrue(VectorD.AreNumericallyEqual(gsSolution, x));
        }
        public void Test1()
        {
            MatrixD A = new MatrixD(new double[,] { { 4 } });
              VectorD b = new VectorD(new double[] { 20 });

              GaussSeidelMethodD solver = new GaussSeidelMethodD();
              VectorD x = solver.Solve(A, null, b);

              Assert.IsTrue(VectorD.AreNumericallyEqual(new VectorD(1, 5), x));
              Assert.AreEqual(2, solver.NumberOfIterations);
        }
        public void Test4()
        {
            MatrixD A = new MatrixD(new double[,] { { -12, 2 },
                                              { 2, 3 }});
              VectorD b = new VectorD(new double[] { 20, 28 });

              GaussSeidelMethodD solver = new GaussSeidelMethodD();
              VectorD x = solver.Solve(A, null, b);

              VectorD solution = MatrixD.SolveLinearEquations(A, b);
              Assert.IsTrue(VectorD.AreNumericallyEqual(solution, x));
        }
        public void Test1()
        {
            MatrixD A = new MatrixD(new double[, ] {
                { 4 }
            });
            VectorD b = new VectorD(new double[] { 20 });

            GaussSeidelMethodD solver = new GaussSeidelMethodD();
            VectorD            x      = solver.Solve(A, null, b);

            Assert.IsTrue(VectorD.AreNumericallyEqual(new VectorD(1, 5), x));
            Assert.AreEqual(2, solver.NumberOfIterations);
        }
        public void Test5()
        {
            MatrixD A = new MatrixD(new double[,] { { -21, 2, -4, 0 },
                                              { 2, 3, 0.1, -1 },
                                              { 2, 10, 111.1, -11 },
                                              { 23, 112, 111.1, -143 }});
              VectorD b = new VectorD(new double[] { 20, 28, -12, 0.1 });

              GaussSeidelMethodD solver = new GaussSeidelMethodD();
              VectorD x = solver.Solve(A, null, b);

              VectorD solution = MatrixD.SolveLinearEquations(A, b);
              Assert.IsTrue(VectorD.AreNumericallyEqual(solution, x));
        }
        public void Test4()
        {
            MatrixD A = new MatrixD(new double[, ] {
                { -12, 2 },
                { 2, 3 }
            });
            VectorD b = new VectorD(new double[] { 20, 28 });

            GaussSeidelMethodD solver = new GaussSeidelMethodD();
            VectorD            x      = solver.Solve(A, null, b);

            VectorD solution = MatrixD.SolveLinearEquations(A, b);

            Assert.IsTrue(VectorD.AreNumericallyEqual(solution, x));
        }
        public void Test5()
        {
            MatrixD A = new MatrixD(new double[, ] {
                { -21, 2, -4, 0 },
                { 2, 3, 0.1, -1 },
                { 2, 10, 111.1, -11 },
                { 23, 112, 111.1, -143 }
            });
            VectorD b = new VectorD(new double[] { 20, 28, -12, 0.1 });

            GaussSeidelMethodD solver = new GaussSeidelMethodD();
            VectorD            x      = solver.Solve(A, null, b);

            VectorD solution = MatrixD.SolveLinearEquations(A, b);

            Assert.IsTrue(VectorD.AreNumericallyEqual(solution, x));
        }
        public void Test7()
        {
            MatrixD A = new MatrixD(new double[, ] {
                { -21, 2, -4, 0 },
                { 2, 3, 0.1, -1 },
                { 2, 10, 111.1, -11 },
                { 23, 112, 111.1, -143 }
            });
            VectorD b = new VectorD(new double[] { 20, 28, -12, 0.1 });

            GaussSeidelMethodD solver = new GaussSeidelMethodD();

            solver.Epsilon = 0.0001;
            VectorD x = solver.Solve(A, null, b);

            VectorD solution = MatrixD.SolveLinearEquations(A, b);

            Assert.IsTrue(VectorD.AreNumericallyEqual(solution, x, 0.1));
            Assert.IsFalse(VectorD.AreNumericallyEqual(solution, x));
            Assert.Greater(26, solver.NumberOfIterations); // For normal accuracy (EpsilonD) we need 26 iterations.
        }
 public void TestArgumentException3()
 {
     GaussSeidelMethodD solver = new GaussSeidelMethodD();
     VectorD            x      = solver.Solve(new MatrixD(3, 3), new VectorD(4), new VectorD(3));
 }
 public void TestArgumentNullException2()
 {
     GaussSeidelMethodD solver = new GaussSeidelMethodD();
     VectorD            x      = solver.Solve(new MatrixD(), null, null);
 }
 public void TestArgumentNullException()
 {
     GaussSeidelMethodD solver = new GaussSeidelMethodD();
     VectorD            x      = solver.Solve(null, null, new VectorD());
 }
Beispiel #12
0
        public void Test9()
        {
            MatrixD A = new MatrixD(new double[,] { { -21, 2, -4, 0 },
                                              { 2, 3, 0.1, -1 },
                                              { 2, 10, 111.1, -11 },
                                              { 23, 112, 111.1, -143 }});
              VectorD b = new VectorD(new double[] { 20, 28, -12, 0.1 });

              SorMethodD solver = new SorMethodD();
              solver.RelaxationFactor = 1.5;
              solver.MaxNumberOfIterations = 4;
              VectorD x = solver.Solve(A, null, b);

              VectorD solution = MatrixD.SolveLinearEquations(A, b);
              Assert.IsFalse(VectorD.AreNumericallyEqual(solution, x));
              Assert.AreEqual(4, solver.NumberOfIterations);

              // Compare with Gauss-Seidel. Should be unequal because the relaxation factor is not 1.
              GaussSeidelMethodD gsSolver = new GaussSeidelMethodD();
              solver.MaxNumberOfIterations = 4;
              VectorD gsSolution = gsSolver.Solve(A, null, b);
              Assert.IsFalse(VectorD.AreNumericallyEqual(gsSolution, x));
        }
 public void TestArgumentNullException2()
 {
     GaussSeidelMethodD solver = new GaussSeidelMethodD();
       VectorD x = solver.Solve(new MatrixD(), null, null);
 }
 public void TestArgumentNullException()
 {
     GaussSeidelMethodD solver = new GaussSeidelMethodD();
       VectorD x = solver.Solve(null, null, new VectorD());
 }
 public void TestArgumentException3()
 {
     GaussSeidelMethodD solver = new GaussSeidelMethodD();
       VectorD x = solver.Solve(new MatrixD(3, 3), new VectorD(4), new VectorD(3));
 }
        public void Test7()
        {
            MatrixD A = new MatrixD(new double[,] { { -21, 2, -4, 0 },
                                              { 2, 3, 0.1, -1 },
                                              { 2, 10, 111.1, -11 },
                                              { 23, 112, 111.1, -143 }});
              VectorD b = new VectorD(new double[] { 20, 28, -12, 0.1 });

              GaussSeidelMethodD solver = new GaussSeidelMethodD();
              solver.Epsilon = 0.0001;
              VectorD x = solver.Solve(A, null, b);

              VectorD solution = MatrixD.SolveLinearEquations(A, b);
              Assert.IsTrue(VectorD.AreNumericallyEqual(solution, x, 0.1));
              Assert.IsFalse(VectorD.AreNumericallyEqual(solution, x));
              Assert.Greater(26, solver.NumberOfIterations); // For normal accuracy (EpsilonD) we need 26 iterations.
        }