示例#1
0
文件: LUTests.cs 项目: zredb/C-Sharp
        public void EliminateIdentityEquation()
        {
            // Arrange
            var identityMatrix = new double[, ] {
                { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }
            };
            var coefficients = new double[] { 1, 2, 3 };

            // Act
            var solution = LU.Eliminate(identityMatrix, coefficients);

            // Assert
            Assert.AreEqual(coefficients, solution);
        }
示例#2
0
文件: LUTests.cs 项目: zredb/C-Sharp
        public void FailOnEliminateEquationWithNonSquareMatrix()
        {
            // Arrange
            var nonSquareMatrix = new double[, ] {
                { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }, { 0, 0, 0 }
            };
            var coefficients = new double[] { 1, 2, 3, 4 };

            // Act
            void Act(double[,] source, double[] c) => LU.Eliminate(source, c);

            // Assert
            Assert.Throws <ArgumentException>(() => Act(nonSquareMatrix, coefficients));
        }
示例#3
0
文件: LUTests.cs 项目: zredb/C-Sharp
        public void EliminateEquation_Case4X4()
        {
            // Arrange
            var source = new double[, ] {
                { 1.0, 2.0, -3.0, -1.0 }, { 0.0, -3.0, 2.0, 6.0 }, { 0.0, 5.0, -6.0, -2.0 }, { 0.0, -1.0, 8.0, 1.0 }
            };
            var coefficients     = new double[] { 0.0, -8.0, 0.0, -8.0 };
            var expectedSolution = new double[] { -1.0, -2.0, -1.0, -2.0 };

            // Act
            var solution = LU.Eliminate(source, coefficients);

            // Assert
            Assert.IsTrue(VectorMembersAreEqual(expectedSolution, solution));
        }
示例#4
0
文件: LUTests.cs 项目: zredb/C-Sharp
        public void EliminateEquation_Case3X3()
        {
            // Arrange
            var source = new double[, ] {
                { 2, 1, -1 }, { -3, -1, 2 }, { -2, 1, 2 }
            };
            var coefficients     = new double[] { 8, -11, -3 };
            var expectedSolution = new double[] { 2, 3, -1 };

            // Act
            var solution = LU.Eliminate(source, coefficients);

            // Assert
            Assert.IsTrue(VectorMembersAreEqual(expectedSolution, solution));
        }