Пример #1
0
        public void 逆行列テストランダム版()
        {
            var mat  = new MatrixLib.Matrix(4, 4);
            var rand = new Random();

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    mat[i, j] = rand.Next(0, 20);
                }
            }

            var denseMat = new DenseMatrix(4, 4);

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    denseMat[i, j] = mat[i, j];
                }
            }

            var inv        = mat.Inverse();
            var invCorrect = denseMat.Inverse();

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    Assert.IsTrue(Math.Abs(invCorrect[i, j] - inv[i, j]) < 0.001);
                }
            }
        }
Пример #2
0
        public void 逆行列テスト()
        {
            var denseMat = DenseMatrix.OfArray(new double[, ]
            {
                { 8, 16, 24, 32 },
                { 2, 7, 12, 17 },
                { 6, 17, 32, 59 },
                { 7, 22, 46, 105 }
            });
            var mat = new MatrixLib.Matrix(4, 4);

            mat[0, 0] = 8;
            mat[0, 1] = 16;
            mat[0, 2] = 24;
            mat[0, 3] = 32;


            mat[1, 0] = 2;
            mat[1, 1] = 7;
            mat[1, 2] = 12;
            mat[1, 3] = 17;

            mat[2, 0] = 6;
            mat[2, 1] = 17;
            mat[2, 2] = 32;
            mat[2, 3] = 59;

            mat[3, 0] = 7;
            mat[3, 1] = 22;
            mat[3, 2] = 46;
            mat[3, 3] = 105;

            var inv        = mat.Inverse();
            var invCorrect = denseMat.Inverse();

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    Assert.IsTrue(Math.Abs(invCorrect[i, j] - inv[i, j]) < 0.001);
                }
            }
        }