Esempio n. 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()));
        }
Esempio n. 2
0
        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);
                    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 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()));
        }