Beispiel #1
0
        static void runLab2()
        {
            LU_Decomposition lU = new LU_Decomposition();

            double[] gammas = new double[] { 1, 4, 1, 4, 2, 7 };
            double[] alphas = new double[] { 2, -2, -1, 7, -5, -3, -3 };
            double[] betas  = new double[] { 0.5, 6, 3, 2, 1, 2 };
            double[] b      = new double[] { 8, 6, 3, -2, 4, 7, -0.5 };

            var resLU = lU.calculate_LU(gammas, alphas, betas, b);

            for (int i = 0; i < resLU.Length; i++)
            {
                Console.WriteLine("X" + i + ":" + resLU[i]);
            }
            for (int i = 0; i < resLU.Length; i++)
            {
                if (i == 0)
                {
                    Console.WriteLine("Check of equation Num" + i + "\t:" + (double)(alphas[i] * resLU[i] + gammas[i] * resLU[i + 1]));
                }
                else if (i == resLU.Length - 1)
                {
                    Console.WriteLine("Check of equation Num" + i + "\t:" + (double)(alphas[i] * resLU[i] + betas[i - 1] * resLU[i - 1]));
                }
                else
                {
                    Console.WriteLine("Check of equation Num" + i + "\t:" + (double)(betas[i - 1] * resLU[i - 1] + alphas[i] * resLU[i] + gammas[i] * resLU[i + 1]));
                }
            }
        }
        static void Main(string[] args)
        {
            //Create method
            LU_Decomposition decomposition = new LU_Decomposition();
            //Create source
            string source = "Matrix.txt";

            int from = 0;

            double[] vector;

            byte key = 99;

            while (key != 0)
            {
                Console.Clear();
                Console.WriteLine("Choose point of menu");
                Console.WriteLine("1. Write data");
                if (from != 0)
                {
                    Console.WriteLine("2. Output determination");
                }
                Console.WriteLine("3. Output README");
                Console.WriteLine("4. Exit");
                Console.Write("Your number: ");
                key = Byte.Parse(Console.ReadLine());
                switch (key)
                {
                case 1:
                {
                    Console.WriteLine("What kind of source(file (1) or hand-create values (2))\n" +
                                      "Your number: ");
                    int fl = Convert.ToInt32(Console.ReadLine());
                    switch (fl)
                    {
                    case 1:
                    {
                        from = 1;
                    }
                    break;

                    case 2:
                    {
                        from = 2;
                    }
                    break;
                    }
                }
                break;

                case 2:
                {
                    if (from != 0)
                    {
                        Console.WriteLine("Your output is");
                        decomposition.ClcltLU_Dcmp(source, from, out vector);
                        foreach (double x in vector)
                        {
                            Console.Write(Math.Round(x, 5) + " ");
                        }
                        Console.ReadKey();
                    }
                }
                break;

                case 3:
                {
                    Console.Clear();
                    Console.Write("Program for design SLAE");
                }
                break;

                case 4:
                {
                    key = 0;
                }
                break;
                }
            }
        }