示例#1
0
        public void LU分解テストランダム版()
        {
            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 lu      = mat.LuSolve();
            var restore = lu.L * lu.U;

            Console.WriteLine(mat);
            Console.WriteLine(restore);

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    Assert.IsTrue(Math.Abs(mat[i, j] - restore[i, j]) < 0.001);
                }
            }
        }
示例#2
0
        public void LU分解コンソール確認用()
        {
            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 result = mat.LuSolve();

            Console.WriteLine("L");
            Console.WriteLine(result.L);
            Console.WriteLine("===================");
            Console.WriteLine("U");
            Console.WriteLine(result.U);
        }
示例#3
0
        public void u分解テスト()
        {
            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 lu = mat.LuSolve();
            var u  = lu.U;

            var uCorrect = denseMat.LU().U;

            Console.WriteLine(u);
            Console.WriteLine(uCorrect);
//
//            for (int i = 0; i < 4; i++)
//            {
//                for (int j = 0; j < 4; j++)
//                {
//                    Assert.IsTrue(Math.Abs(u[i,j] - uCorrect[i,j]) < 0.001);
//                }
//            }
        }
示例#4
0
        public void   角行列の逆行列が計算できているか確認()
        {
            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 lu = mat.LuSolve();
            var l  = lu.L;

            var lInv = l.InverseLowerTriangularMatrix();

            Console.WriteLine("l Inv");
            Console.WriteLine(lInv);
            var identity = l * lInv;

            Console.WriteLine(identity);

            identity = lInv * l;
            Console.WriteLine(identity);
        }
示例#5
0
        public void LU分解テスト()
        {
            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 lu      = mat.LuSolve();
            var restore = lu.L * lu.U;

            Console.WriteLine(mat);
            Console.WriteLine(restore);

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                }
            }
        }