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); }
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)); }
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)); }
public void EliminateEquation_Case4X4() { // Arrange var source = new[, ] { { 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[] { 0.0, -8.0, 0.0, -8.0 }; var expectedSolution = new[] { -1.0, -2.0, -1.0, -2.0 }; // Act var solution = Lu.Eliminate(source, coefficients); // Assert Assert.IsTrue(VectorMembersAreEqual(expectedSolution, solution)); }