コード例 #1
0
        static void TestMatrixInvertSpeed(EigenWrapper.Matrix A)
        {
            EigenWrapper.Matrix C;
            Stopwatch           watch = Stopwatch.StartNew();

            for (int i = 0; i < testIterations; i++)
            {
                C = A.Inverse();
            }
            watch.Stop();
            Console.WriteLine("P/Invoked Eigen matrix class inverse test took: " + watch.ElapsedMilliseconds + " ms.");
        }
コード例 #2
0
        static void TestInverseCorrectness()
        {
            double[,] A = { { 1, -2, -3, -4 }, { 2, -5, -6, -7 }, { 3, 7, -8, -9 }, { 4, 8, 12, 16 } };
            EigenWrapper.Matrix AMat = new EigenWrapper.Matrix(4, 4);
            AMat[0, 0] = 1;
            AMat[0, 1] = 2;
            AMat[0, 2] = 3;
            AMat[0, 3] = 4;
            AMat[1, 0] = -2;
            AMat[1, 1] = -5;
            AMat[1, 2] = 7;
            AMat[1, 3] = 8;
            AMat[2, 0] = -3;
            AMat[2, 1] = -6;
            AMat[2, 2] = -8;
            AMat[2, 3] = 12;
            AMat[3, 0] = -4;
            AMat[3, 1] = -7;
            AMat[3, 2] = -9;
            AMat[3, 3] = 16;

            //Test the C# inverse correctness
            Console.WriteLine("C# matrix inverse...");
            Console.WriteLine("The input matrix is:");
            PrintMatrix(A);
            Console.WriteLine("The inverse matrix is:");
            double[,] Atrans = MatrixMathCS.Transpose(A);
            double[,] C      = MatrixMathCS.InverseMatrix(Atrans);
            double[,] Ctrans = MatrixMathCS.Transpose(C);
            PrintMatrix(Ctrans);
            Console.WriteLine();

            //Test the Eigen matrix inverse correctness
            Console.WriteLine("P/Invoke Eigen 2D double array matrix inverse...");
            Console.WriteLine("The input matrix is:");
            PrintMatrix(A);
            Console.WriteLine("The inverse matrix is:");
            double[,] D = EigenWrapper.MatrixMath.InvertMatrix(A);
            PrintMatrix(D);
            Console.WriteLine();

            //Test the matrix class inverse correctness
            Console.WriteLine("P/Invoke Eigen matrix class inverse...");
            Console.WriteLine("The input matrix is:");
            PrintMatrix(AMat);
            Console.WriteLine("The inverse matrix is:");
            EigenWrapper.Matrix CMat = AMat.Inverse();
            PrintMatrix(CMat);
        }