public void InverseTest() { double[][] value = { new double[] { 2, -1, 0 }, new double[] { -1, 2, -1 }, new double[] { 0, -1, 2 } }; double[][] expected = { new double[] { 0.7500, 0.5000, 0.2500 }, new double[] { 0.5000, 1.0000, 0.5000 }, new double[] { 0.2500, 0.5000, 0.7500 }, }; var target = new JaggedQrDecomposition(value); double[][] actual = target.Inverse(); Assert.IsTrue(Matrix.IsEqual(expected, actual, 1e-10)); Assert.IsTrue(Matrix.IsEqual(value, target.Reverse(), 1e-4)); target = new JaggedQrDecomposition(value.Transpose(), true); actual = target.Inverse(); Assert.IsTrue(Matrix.IsEqual(expected, actual, 1e-10)); Assert.IsTrue(Matrix.IsEqual(value.Transpose(), target.Reverse(), 1e-4)); }
public void InverseTest1() { double[][] value = { new double[] { 41.9, 29.1, 1 }, new double[] { 43.4, 29.3, 1 }, new double[] { 43.9, 29.5, 0 }, new double[] { 44.5, 29.7, 0 }, new double[] { 47.3, 29.9, 0 }, new double[] { 47.5, 30.3, 0 }, new double[] { 47.9, 30.5, 0 }, new double[] { 50.2, 30.7, 0 }, new double[] { 52.8, 30.8, 0 }, new double[] { 53.2, 30.9, 0 }, new double[] { 56.7, 31.5, 0 }, new double[] { 57.0, 31.7, 0 }, new double[] { 63.5, 31.9, 0 }, new double[] { 65.3, 32.0, 0 }, new double[] { 71.1, 32.1, 0 }, new double[] { 77.0, 32.5, 0 }, new double[] { 77.8, 32.9, 0 } }; double[][] expected = new JaggedSingularValueDecomposition(value, computeLeftSingularVectors: true, computeRightSingularVectors: true, autoTranspose: true).Inverse(); var target = new JaggedQrDecomposition(value); double[][] actual = target.Inverse(); Assert.IsTrue(Matrix.IsEqual(expected, actual, atol: 1e-4)); var targetMat = new QrDecomposition(value.ToMatrix()); double[][] actualMat = target.Inverse(); Assert.IsTrue(Matrix.IsEqual(expected, actualMat, atol: 1e-4)); }
public void InverseTestNaN() { int n = 5; var I = Jagged.Identity(n); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { double[][] value = Jagged.Magic(n); value[i][j] = double.NaN; var target = new JaggedQrDecomposition(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.JaggedIdentity(n); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { double[][] value = Matrix.JaggedMagic(n); value[i][j] = double.NaN; var target = new JaggedQrDecomposition(value); var solution = target.Solve(I); var inverse = target.Inverse(); Assert.IsTrue(Matrix.IsEqual(solution, inverse)); } } }
public void InverseTest() { double[][] value = { new double[] { 2, -1, 0 }, new double[] { -1, 2, -1 }, new double[] { 0, -1, 2 } }; double[][] expected = { new double[] { 0.7500, 0.5000, 0.2500}, new double[] { 0.5000, 1.0000, 0.5000}, new double[] { 0.2500, 0.5000, 0.7500}, }; var target = new JaggedQrDecomposition(value); double[][] actual = target.Inverse(); Assert.IsTrue(Matrix.IsEqual(expected, actual, 0.0000000000001)); target = new JaggedQrDecomposition(value.Transpose(), true); actual = target.Inverse(); Assert.IsTrue(Matrix.IsEqual(expected, actual, 0.0000000000001)); }