Ejemplo n.º 1
0
        internal static void test(string name, double[][] A, double[] b)
        {
            Console.WriteLine("----------------------------------------------------");
            Console.WriteLine(name);
            Console.WriteLine("----------------------------------------------------");
            GaussJordanElimination gaussian = new GaussJordanElimination(A, b);

            if (gaussian.IsFeasible)
            {
                Console.WriteLine("Solution to Ax = b");
                double[] x = gaussian.Primal();
                for (int i = 0; i < x.Length; i++)
                {
                    Console.Write("{0,10:F6}\n", x[i]);
                }
            }
            else
            {
                Console.WriteLine("Certificate of infeasibility");
                double[] y = gaussian.Dual();
                for (int j = 0; j < y.Length; j++)
                {
                    Console.Write("{0,10:F6}\n", y[j]);
                }
            }
            Console.WriteLine();
            Console.WriteLine();
        }
Ejemplo n.º 2
0
        public static void MainTest(string[] args)
        {
            GaussJordanElimination.test1();
            GaussJordanElimination.test2();
            GaussJordanElimination.test3();
            GaussJordanElimination.test4();
            GaussJordanElimination.test5();
            GaussJordanElimination.test6();

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

            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);
            }
            GaussJordanElimination.test("random " + N + "-by-" + N + " (likely full rank)", A, b);

            // N-by-N random system (likely infeasible)
            A = new double[N][];
            for (int i = 0; i < N - 1; i++)
            {
                A[i] = new double[N];
                for (int j = 0; j < N; j++)
                {
                    A[i][j] = StdRandom.Uniform(1000);
                }
            }
            A[N - 1] = new double[N];
            for (int i = 0; i < N - 1; i++)
            {
                double alpha = StdRandom.Uniform(11) - 5.0;
                for (int j = 0; j < N; j++)
                {
                    A[N - 1][j] += alpha * A[i][j];
                }
            }
            b = new double[N];
            for (int i = 0; i < N; i++)
            {
                b[i] = StdRandom.Uniform(1000);
            }
            GaussJordanElimination.test("random " + N + "-by-" + N + " (likely infeasible)", A, b);
        }