Exemple #1
0
        /**
         * Uses LU decomposition to determine inverse
         */
        public Matrix inverse_lu()
        {
            LUDecomposition lu       = new LUDecomposition(this);
            Matrix          identity = new Matrix(this.cols, this.rows);

            identity.setIdentity();
            Matrix inverse = lu.solve(identity);

            return(inverse);
        }
        public static void TestHarness()
        {
//			Matrix A = new Matrix(3, 3);
//			A.setIdentity();
//			A.data[0,1] = A.data[1,0] = 0.2;
//			A.data[0,2] = A.data[2,0] = 0.3;
//			A.data[1,2] = A.data[2,1] = 0.1;
//			System.Console.WriteLine("A is\n{0}", A.dump());
//
//			LUDecomposition A_lu = new LUDecomposition(A);
//			System.Console.WriteLine("LU is\n{0}", A_lu.dump());

            Matrix B = new Matrix(3, 3);

            B.setIdentity();
            B.data[0, 1] = B.data[1, 0] = 0.2;
            B.data[0, 2] = B.data[2, 0] = 0.3;
            B.data[1, 2] = 0.1;
            B.data[2, 0] = 0.4;
            Console.WriteLine("B is\n{0}", B.dump());

            LUDecomposition B_lu = new LUDecomposition(B);

            Console.WriteLine("LU is\n{0}", B_lu.dump());

            Matrix b = new Matrix(3, 1);

            b.data[0, 0] = 1.0;
            b.data[1, 0] = 2.0;
            b.data[2, 0] = 3.0;
            Console.WriteLine("b is\n{0}", b.dump());

            Matrix x = B_lu.solve(b);

            Console.WriteLine("x is\n{0}", x.dump());

            Matrix test_b = B.multiply(x);

            Console.WriteLine("test_B is\n{0}", test_b.dump());
        }