コード例 #1
0
        public static void MainTest(string[] args)
        {
            GaussianElimination.test1();
            GaussianElimination.test2();
            GaussianElimination.test3();
            GaussianElimination.test4();
            GaussianElimination.test5();
            GaussianElimination.test6();
            GaussianElimination.test7();
            GaussianElimination.test8();
            GaussianElimination.test9();

            // N-by-N random system
            int N = int.Parse(args[0]);

            // build augmented matrix
            double[][] A = new double[N][];

            for (int i = 0; i < N; i++)
            {
                A[i] = new double[N];
                for (int j = 0; j < N; j++)
                {
                    A[i][j] = StdRandom.Uniform(1000);
                }
            }

            double[] b = new double[N];
            for (int i = 0; i < N; i++)
            {
                b[i] = StdRandom.Uniform(1000);
            }

            GaussianElimination.test(N + "-by-" + N + " (probably nonsingular)", A, b);
        }
コード例 #2
0
        /// <summary>
        /// Demo test the <c>GaussianElimination</c> data type.</summary>
        ///
        internal static void test(string name, double[][] A, double[] b)
        {
            Console.WriteLine("----------------------------------------------------");
            Console.WriteLine(name);
            Console.WriteLine("----------------------------------------------------");
            GaussianElimination gaussian = new GaussianElimination(A, b);

            double[] x = gaussian.Primal();
            if (gaussian.IsFeasible)
            {
                for (int i = 0; i < x.Length; i++)
                {
                    Console.Write("{0:F6}\n", x[i]);
                }
            }
            else
            {
                Console.WriteLine("System is infeasible");
            }
            Console.WriteLine();
            Console.WriteLine();
        }