Exemple #1
0
        //Для метода Ньютона
        private void Solve_Equation_Newton(object sender, RoutedEventArgs e)
        {
            int    methodIndex        = 1;
            int    equationIndex      = EquationList2.SelectedIndex;
            double startApproximation = Double.Parse(StartApproximation.Text.Replace(".", ","));
            double accuracy           = Math.Abs(Double.Parse(Accuracy.Text.Replace(".", ",")));

            var solution = new NonlinearEquationMethods(methodIndex, equationIndex, 0, 0, accuracy, startApproximation);

            if (solution.SolutionExistence)
            {
                if (solution.FastConvergence)
                {
                    OutputConsole2.Text += "При данном начальном приближении обеспечена быстрая сходимость.\n";
                }

                OutputConsole2.Text += "Значение корня: " + solution.EquationResult + "\n" +
                                       "Достигнутая погрешность: " + solution.ResultAccuracy + "\n" +
                                       "Количество итераций: " + solution.CountOfIterations + "\n" +
                                       "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
            }
            else
            {
                OutputConsole2.Text += "При данном приближении нет гарнатии существования корня, задайте другой.\n" +
                                       "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
            }

            Update_Graphics_Newton();

            Show_Graphic_Newton(-8, 8);

            //добавляем корень на график
            double x;
            double y = 0;

            if (solution.SolutionExistence)
            {
                x = solution.EquationResult;
                switch (equationIndex)
                {
                case 0:
                    y = Math.Pow(x, 5) + 4;
                    break;

                case 1:
                    y = 3 * Math.Cos(3 * x);
                    break;

                case 2:
                    y = 1.5 * Math.Sin(1.5 * x) - 3 * Math.Cos(3 * x);
                    break;
                }
                Ellipse result = new Ellipse {
                    Width = 6, Height = 6
                };
                result.Fill   = Brushes.Lime;
                result.Margin = new Thickness(x * 80, -y * 80, 0, 0);
                GraphicPlaceNewton.Children.Add(result);
            }
        }
Exemple #2
0
        //Для метода бисекции
        private void Solve_Equation_Bisection(object sender, RoutedEventArgs e)
        {
            int    methodIndex   = 0;
            int    equationIndex = EquationList.SelectedIndex;
            double upperLimit    = Double.Parse(UpperLimit.Text.Replace(".", ","));
            double lowerLimit    = Double.Parse(LowerLimit.Text.Replace(".", ","));
            double accuracy      = Math.Abs(Double.Parse(Accuracy.Text.Replace(".", ",")));

            if (upperLimit < lowerLimit)
            {
                upperLimit = lowerLimit;
                lowerLimit = Double.Parse(UpperLimit.Text.Replace(".", ","));
            }

            if (upperLimit > 8)
            {
                upperLimit      = 8;
                UpperLimit.Text = upperLimit.ToString();
            }
            if (upperLimit < -8)
            {
                upperLimit      = -8;
                UpperLimit.Text = upperLimit.ToString();
            }
            if (lowerLimit > 8)
            {
                lowerLimit      = 8;
                LowerLimit.Text = lowerLimit.ToString();
            }
            if (lowerLimit < -8)
            {
                lowerLimit      = -8;
                LowerLimit.Text = lowerLimit.ToString();
            }

            var solution = new NonlinearEquationMethods(methodIndex, equationIndex, upperLimit, lowerLimit, accuracy, 0);

            if (solution.SolutionExistence)
            {
                OutputConsole.Text += "Корень уравнения на данном отрезке существует.\n" +
                                      "Значение корня: " + solution.EquationResult + "\n" +
                                      "Достигнутая погрешность: " + solution.ResultAccuracy + "\n" +
                                      "Количество итераций: " + solution.CountOfIterations + "\n" +
                                      "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
            }
            else
            {
                OutputConsole.Text += "На данном отрезке нет гарнатии существования корня, задайте другой.\n" +
                                      "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
            }


            Update_Graphics_Bisection();

            Show_Graphic_Bisection(lowerLimit, upperLimit);

            //добавляем корень на график
            double x;
            double y = 0;

            if (solution.SolutionExistence)
            {
                x = solution.EquationResult;
                switch (equationIndex)
                {
                case 0:
                    y = Math.Pow(x, 5) + 4;
                    break;

                case 1:
                    y = 3 * Math.Cos(3 * x);
                    break;

                case 2:
                    y = 1.5 * Math.Sin(1.5 * x) - 3 * Math.Cos(3 * x);
                    break;
                }
                Ellipse result = new Ellipse {
                    Width = 6, Height = 6
                };
                result.Fill   = Brushes.Lime;
                result.Margin = new Thickness(x * 80, -y * 80, 0, 0);
                GraphicPlaceBisection.Children.Add(result);
            }
        }