Example #1
0
        public static void Vegstein_method(string equation_str, string parameters_string, double a)
        {
            Console.WriteLine("Решаем СНУ методом Вегстейна");

            double e = 0;

            Console.WriteLine("Введите погрешность e:");
            e = double.Parse(Console.ReadLine());

            int k       = 0;
            int limit_k = 0;

            Console.WriteLine("Введите предельное количество итераций:");
            limit_k = int.Parse(Console.ReadLine());
            For_equals example = new For_equals(equation_str, parameters_string);

            example.Decide_first_time();
            double[] parameters_x0 = new double[1];
            double[] parameters_x1 = new double[1];
            double   x0            = a;
            double   x1            = Return_F1(x0);
            double   y0            = x0;
            double   y1            = x1;
            double   y2;
            double   x2;

            //Console.WriteLine("x = {0}", x);

            do
            {
                k++;
                if (k > limit_k)
                {
                    Console.WriteLine("Достигнута предельная итерация. Решение с заданной точностью не найдено");
                    return;
                }
                parameters_x0[0] = x1;
                y2 = example.Decide(parameters_x0);
                x2 = y2 - ((y2 - y1) * (y2 - x1)) / ((y2 - y1) - (x1 - x0));
                if (Math.Abs(y2 - y1) < e)
                {
                    break;
                }
                x0 = x1;
                y0 = y1;
                x1 = x2;
                y1 = y2;
            } while (true);
            Console.WriteLine("В точке {0} функция F({0}) принимает значение {1}", x2, Return_F11(y2));
            Console.WriteLine("Количество итераций равно {0}", k);
        }
Example #2
0
        // Решения СНУ через распознавание уравнения
        public static void Method_of_chord(string equation_str, string parameters_string, double a, double b)
        {
            Console.WriteLine("Решаем СНУ методом хорд");

            double e = 0;

            Console.WriteLine("Введите погрешность e:");
            e = double.Parse(Console.ReadLine());

            int k = 0;

            double[]   parameters = new double[1];
            double     c          = 0;
            double     helper_c   = 0;
            double     F_a        = 0;
            double     F_b        = 0;
            double     F_c        = 0;
            For_equals example    = new For_equals(equation_str, parameters_string);

            example.Decide_first_time();

            do
            {
                k++;
                parameters[0] = a;
                F_a           = example.Decide(parameters);
                parameters[0] = b;
                F_b           = example.Decide(parameters);
                helper_c      = c;
                c             = a - (F_a / (F_b - F_a)) * (b - a);
                parameters[0] = c;
                F_c           = example.Decide(parameters);
                Console.WriteLine("F({0}) = {1}", a, F_a);
                Console.WriteLine("F({0}) = {1}", b, F_b);
                Console.WriteLine("F({0}) = {1}", c, F_c);
                Console.WriteLine();
                if (F_a * F_c < 0)
                {
                    b = c;
                }
                if (F_c * F_b < 0)
                {
                    a = c;
                }
            } while (Math.Abs(helper_c - c) > e);
            Console.WriteLine("В точке {0} функция F({0}) принимает значение {1}", c, F_c);
            Console.WriteLine("Количество итераций равно {0}", k);
        }
Example #3
0
        static void Main(string[] args)
        {
            string equation_str      = "(x+3)^3+(6*x^2+x)^2-8*pi+e+sin(x)+cos(x)+tg(x)+ctg(x)+arcsin(x)+arccos(x)+arctg(x)+arcctg(x)+lg(x)+ln(x)";
            string parameters_string = "x";

            double[] parameters = new double[1];
            parameters[0] = 0.5;
            string[] parameters_str = new string[1];
            parameters_str[0] = "0,5";
            For_equals example = new For_equals(equation_str, parameters_string);

            example.Decide_first_time();
            example.Decide(parameters);

            //Open_file("string.txt");
        }
Example #4
0
        public static void Simple_iteration_method(string equation_str, string parameters_string, double a)
        {
            Console.WriteLine("Решаем СНУ методом простых итераций");

            double e = 0;

            Console.WriteLine("Введите погрешность e:");
            e = double.Parse(Console.ReadLine());

            int k       = 0;
            int limit_k = 0;

            Console.WriteLine("Введите предельное количество итераций:");
            limit_k = int.Parse(Console.ReadLine());
            double[]   parameters = new double[1];
            double     helper_a   = 0;
            For_equals example    = new For_equals(equation_str, parameters_string);

            example.Decide_first_time();

            do
            {
                k++;
                if (k > limit_k)
                {
                    Console.WriteLine("Достигнута предельная итерация. Решение с заданной точностью не найдено");
                    return;
                }
                helper_a      = a;
                parameters[0] = a;
                a             = example.Decide(parameters);
                Console.WriteLine("F({0}) = {1}", helper_a, a);
                if (a > Math.Pow(10, 50))
                {
                    Console.WriteLine("Метод расходится");
                    return;
                }
            } while (Math.Abs(a - helper_a) > e);
            Console.WriteLine("В точке {0} функция F({0}) принимает значение {1}", helper_a, a);
            Console.WriteLine("Количество итераций равно {0}", k);
        }