public void InverseTestNaN() { int n = 5; var I = Matrix.Identity(n); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { double[,] value = Matrix.Magic(n); value[i, j] = double.NaN; var target = new LuDecomposition(value); Assert.IsTrue(Matrix.IsEqual(target.Solve(I), target.Inverse())); var target2 = new JaggedLuDecomposition(value.ToJagged()); Assert.IsTrue(Matrix.IsEqual(target2.Solve(I.ToJagged()), target2.Inverse())); } } }
public void InverseTestNaN() { int n = 5; var I = Matrix.Identity(n); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { double[,] value = Matrix.Magic(n); value[i, j] = double.NaN; var target = new LuDecomposition(value); var solution = target.Solve(I); var inverse = target.Inverse(); Assert.IsTrue(Matrix.IsEqual(solution, inverse)); } } }
public void InverseTest() { double[,] value = { { 2, 3, 0 }, { -1, 2, 1 }, { 0, -1, 3 } }; double[,] expectedInverse = { { 0.3043, -0.3913, 0.1304 }, { 0.1304, 0.2609, -0.0870 }, { 0.0435, 0.0870, 0.3043 }, }; LuDecomposition target = new LuDecomposition(value); double[,] actualInverse = target.Inverse(); Assert.IsTrue(Matrix.IsEqual(expectedInverse, actualInverse, 0.001)); }