示例#1
0
        public override void Execute()
        {
            OneDimMethod step1 = new GoldenRatio2(F, Eps, 5);
            OneDimMethod step2 = new Paul(F, Df, Eps);
            IterationCount = 0;

            //ШАГ 2
            step1.A = A;
            step1.B = B;
            step1.Execute();

            A = step1.A;
            B = step1.B;

            //ШАГ 3
            step2.A = A;
            step2.B = B;
            step2.Execute();

            A = step2.A;
            B = step2.B;
            Answer = step2.Answer;

            IterationCount += step1.IterationCount;
            IterationCount += step2.IterationCount;
        }
        public override void Execute()
        {
            //Сбрасываем счетчик
            IterationCount = 0;

            //Разгонный метод
            OneDimMethod step1 = new GoldenRatio2(F, Eps);
            step1.SetSvenInterval();
            step1.Execute();
            A = step1.A;
            B = step1.B;

            //Вспомогательная переменная
            double x1 = 0;

            //Основной шаг
            do
            {
                IterationCount ++;
                if (IterationCount >= MaxIterations) break;

                var z = Df(A) + Df(B) + 3*(F(A) - F(B))/(B - A);
                var w = Math.Sqrt(Math.Pow(z, 2) - Df(A)*Df(B));
                var y = (z + w - Df(A))/(Df(B) - Df(A) + 2*w);

                if (y < 0)
                {
                    x1 = A;
                }
                else if (y > 1)
                {
                    x1 = B;
                }
                else
                {
                    x1 = A + y*(B - A);
                }

                var temp = Math.Abs(Df(x1));

                if (temp < Eps || x1 == A || x1 == B)
                    break;

                if (Df(x1) > 0)
                {
                    B = x1;
                }
                else
                {
                    A = x1;
                }
            } while (true);

            Answer = x1;
        }