コード例 #1
0
        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 },
            };

            var target = new LuDecomposition(value);

            double[,] actualInverse = target.Inverse();
            Assert.IsTrue(Matrix.IsEqual(expectedInverse, actualInverse, 0.001));
            Assert.IsTrue(Matrix.IsEqual(value, target.Reverse()));

            var target2 = new JaggedLuDecomposition(value.ToJagged());

            actualInverse = target2.Inverse().ToMatrix();
            Assert.IsTrue(Matrix.IsEqual(expectedInverse, actualInverse, 0.001));
            Assert.IsTrue(Matrix.IsEqual(value, target2.Reverse()));
        }
コード例 #2
0
        public void SolveTest1()
        {
            double[,] value =
            {
                {  2,  3, 0 },
                { -1,  2, 1 },
                {  0, -1, 3 }
            };

            double[] rhs = { 5, 0, 1 };

            double[] expected =
            {
                1.6522,
                0.5652,
                0.5217,
            };

            var target = new LuDecomposition(value);

            double[] actual = target.Solve(rhs);
            Assert.IsTrue(Matrix.IsEqual(expected, actual, 1e-3));
            Assert.IsTrue(Matrix.IsEqual(value, target.Reverse()));

            var target2 = new JaggedLuDecomposition(value.ToJagged());

            actual = target2.Solve(rhs);
            Assert.IsTrue(Matrix.IsEqual(expected, actual, 1e-3));
            Assert.IsTrue(Matrix.IsEqual(value, target2.Reverse()));
        }
コード例 #3
0
        public void SolveTest1()
        {
            double[,] value =
            {
               {  2,  3,  0 },
               { -1,  2,  1 },
               {  0, -1,  3 }
            };

            double[] rhs = { 5, 0, 1 };

            double[] expected =
            {
                1.6522,
                0.5652,
                0.5217,
            };

            var target = new LuDecomposition(value);
            double[] actual = target.Solve(rhs);
            Assert.IsTrue(Matrix.IsEqual(expected, actual, 1e-3));
            Assert.IsTrue(Matrix.IsEqual(value, target.Reverse()));

            var target2 = new JaggedLuDecomposition(value.ToJagged());
            actual = target2.Solve(rhs);
            Assert.IsTrue(Matrix.IsEqual(expected, actual, 1e-3));
            Assert.IsTrue(Matrix.IsEqual(value, target2.Reverse()));
        }
コード例 #4
0
        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 },
            };

            var target = new LuDecomposition(value);
            double[,] actualInverse = target.Inverse();
            Assert.IsTrue(Matrix.IsEqual(expectedInverse, actualInverse, 0.001));
            Assert.IsTrue(Matrix.IsEqual(value, target.Reverse()));

            var target2 = new JaggedLuDecomposition(value.ToJagged());
            actualInverse = target2.Inverse().ToMatrix();
            Assert.IsTrue(Matrix.IsEqual(expectedInverse, actualInverse, 0.001));
            Assert.IsTrue(Matrix.IsEqual(value, target2.Reverse()));
        }