public static void UnableToSolveSingularMatrix() { // Arrange var solver = new GaussJordanElimination(); var input = new double[, ] { { 0, 0, 0 }, { 0, 0, 0 } }; // Act var result = solver.Solve(input); // Assert Assert.IsFalse(result); }
public static void NonSquaredMatrixThrowsException() { // Arrange var solver = new GaussJordanElimination(); var input = new double[, ] { { 2, -1, 5 }, { 0, 2, 1 }, { 3, 17, 7 } }; // Act void Act() => solver.Solve(input); // Assert _ = Assert.Throws <ArgumentException>(Act); }
/// <summary> /// Finds the inverse of the given matrix using a linear equation solver. /// </summary> /// <param name="vector">Splitted words vector.</param> /// <param name="key">Key used for the cipher.</param> /// <returns></returns> private double[] MatrixDeCipher(double[] vector, double[,] key) { // To augment the original key with the given vector. var augM = new double[3, 4]; for (var i = 0; i < key.GetLength(0); i++) { for (var j = 0; j < key.GetLength(1); j++) { augM[i, j] = key[i, j]; } } for (var k = 0; k < vector.Length; k++) { augM[k, 3] = vector[k]; } _ = LinearEquationSolver.Solve(augM); return(new[] { augM[0, 3], augM[1, 3], augM[2, 3] }); }
/// <summary>Solves the linear equation system. If the system has no solution, the result is undefined.</summary> public void Solve() { GaussJordanElimination.Solve(Matrix, RightHandSide, Solution); }