public void SetValueTo42_ValueIs42() { var matrix = new ColumnMatrix(10, 0.0); matrix[3] = 42.0; Assert.That(matrix[3], Is.EqualTo(42.0)); }
public void InitWith42_AllValuesAre42() { var matrix = new ColumnMatrix(10, 42.0); Assert.That(matrix.All(value => value == 42.0)); Assert.That(matrix.Count(), Is.EqualTo(10)); }
public Solution Solve() { var columnMatrix = new ColumnMatrix(RightHandSide.Size, 0.0); var result = SolverDllImport.Solve(CoefficientMatrix.Handle, RightHandSide.Handle, columnMatrix.Handle); Solution = new Solution(columnMatrix, (SolveResult)result); return(Solution); }
public void Multiplication_Size3SolutionSize2_Throws() { var matrix = CreateMatrixWithSize(3); var solution = new ColumnMatrix(new double[2] { 1, 2 }); Assert.Throws <InvalidMatrixOperationException>(() => { var r = matrix * solution; }); }
public void Multiplication_IdentityMatrixSolutionSize3_ResultMatchesSolution() { var matrix = CreateMatrixWithSize(3); matrix[0, 0] = 1.0; matrix[1, 1] = 1.0; matrix[2, 2] = 1.0; var solution = new ColumnMatrix(new double[3] { 1, 2, 3 }); var result = matrix * solution; Assert.That(result[0], Is.EqualTo(1.0).Within(0.01).Percent); Assert.That(result[1], Is.EqualTo(2.0).Within(0.01).Percent); Assert.That(result[2], Is.EqualTo(3.0).Within(0.01).Percent); }
public static SystemOfLinearEquationsSolver Solver_2Times2_Example3() { var matrix = CreateMatrixWithSize(2); matrix.SetValue(0, 0, 0.0); matrix.SetValue(0, 1, 0.0); matrix.SetValue(1, 0, 0.0); matrix.SetValue(1, 1, 0.0); var result = new ColumnMatrix(2, 0.0) { [0] = 10.0, [1] = 20.0 }; var solver = new SystemOfLinearEquationsSolver( matrix, result); return(solver); }
public void Multiplication_ResultMatchesSolution() { var matrix = CreateMatrixWithSize(3); matrix[0, 0] = 0.0; matrix[0, 1] = 1.0; matrix[0, 2] = 2.0; matrix[1, 0] = 3.0; matrix[1, 1] = -4.0; matrix[1, 2] = 5.0; matrix[2, 0] = 6.0; matrix[2, 1] = 7.0; matrix[2, 2] = -8.0; var solution = new ColumnMatrix(new double[3] { 1, 2, 3 }); var result = matrix * solution; Assert.That(result[0], Is.EqualTo(8.0).Within(0.01).Percent); Assert.That(result[1], Is.EqualTo(10.0).Within(0.01).Percent); Assert.That(result[2], Is.EqualTo(-4.0).Within(0.01).Percent); }
public SystemOfLinearEquationsSolver(CoefficientMatrix A, ColumnMatrix b) { CoefficientMatrix = A; RightHandSide = b; Solution = null; }