public void SolveTest() { float[][] value = { new float[] { 2, 3, 0 }, new float[] { -1, 2, 1 }, new float[] { 0, -1, 3 } }; float[][] rhs = { new float[] { 1, 2, 3 }, new float[] { 3, 2, 1 }, new float[] { 5, 0, 1 }, }; float[][] expected = { new float[] { -0.2174f, -0.1739f, 0.6522f }, new float[] { 0.4783f, 0.7826f, 0.5652f }, new float[] { 1.8261f, 0.2609f, 0.5217f }, }; JaggedLuDecompositionF target = new JaggedLuDecompositionF(value); float[][] actual = target.Solve(rhs); Assert.IsTrue(Matrix.IsEqual(expected, actual, 0.001)); }
public void SolveTest5() { float[][] value = { new float[] { 2.1f, 3.1f }, new float[] { 1.6f, 4.2f }, new float[] { 2.1f, 5.1f }, }; float[] rhs = { 6.1f, 4.3f, 2.1f }; float[] expected = { 3.1839f, -0.1891f }; JaggedLuDecompositionF target = new JaggedLuDecompositionF(value); bool thrown = false; try { float[] actual = target.Solve(rhs); } catch (InvalidOperationException) { thrown = true; } Assert.IsTrue(thrown); }
public void SolveTest4() { float[][] value = { new float[] { 2.1f, 3.1f }, new float[] { 1.6f, 4.2f }, }; float[] rhs = { 6.1f, 4.3f }; float[] expected = { 3.1839f, -0.1891f }; JaggedLuDecompositionF target = new JaggedLuDecompositionF(value); float[] actual = target.Solve(rhs); Assert.IsTrue(Matrix.IsEqual(expected, actual, 0.001)); }
public void InverseTestNaN() { int n = 5; var I = Matrix.Identity(n).ToSingle().ToJagged(); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { var value = Matrix.Magic(n).ToJagged().ToSingle(); value[i][j] = Single.NaN; var target = new JaggedLuDecompositionF(value); var solution = target.Solve(I); var inverse = target.Inverse(); Assert.IsTrue(Matrix.IsEqual(solution, inverse)); } } }
public void InverseTestNaN() { int n = 5; var I = Matrix.Identity(n).ToSingle().ToArray(); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { var value = Matrix.Magic(n).ToArray().ToSingle(); value[i][j] = Single.NaN; var target = new JaggedLuDecompositionF(value); var solution = target.Solve(I); var inverse = target.Inverse(); Assert.IsTrue(Matrix.IsEqual(solution, inverse)); } } }
public void SolveTest1() { float[][] value = { new float[] { 2, 3, 0 }, new float[] { -1, 2, 1 }, new float[] { 0, -1, 3 } }; float[] rhs = { 5, 0, 1 }; float[] expected = { 1.6522f, 0.5652f, 0.5217f, }; JaggedLuDecompositionF target = new JaggedLuDecompositionF(value); float[] actual = target.Solve(rhs); Assert.IsTrue(Matrix.IsEqual(expected, actual, 0.001)); }