Esempio n. 1
0
        static void Main()
        {
            FR SL = new FR(0.0001, 0.01, 2, 2);

            GR = new GoldenRatio();
            for (SL.k = 0; ; SL.k++)
            {
                Console.WriteLine();
                Console.WriteLine("--------------------------------------");
                Console.WriteLine("\nточка:" + SL.next.x + " " + SL.next.y);
                Console.WriteLine("итерация: " + SL.k);
                Console.WriteLine("градиент: " + SL.grad.x + " " + SL.grad.y);
                Console.WriteLine("норма градиента: " + SL.normV(SL.grad));
                Console.WriteLine("d: " + SL.d.x + " " + SL.d.y);

                if (SL.normV(SL.grad) < SL.e1)
                {
                    SL.answer = SL.next; break;
                }

                SL.d.x = -SL.grad.x + SL.b * SL.d.x;
                SL.d.y = -SL.grad.y + SL.b * SL.d.y;

                SL.first.x = SL.next.x;
                SL.first.y = SL.next.y;

                SL.step = GR.Calculate(SL.next, SL.grad, SL.d, SL.b, SL.preD);
                Console.WriteLine("Шаг: " + SL.step);

                SL.next.x = SL.first.x + SL.step * SL.d.x;
                SL.next.y = SL.first.y + SL.step * SL.d.y;

                if (SL.normV(new Point(SL.next.x - SL.first.x, SL.next.y - SL.first.y)) < SL.e2)
                {
                    if (Math.Abs(SL.F(SL.next.x, SL.next.y) - SL.F(SL.first.x, SL.first.y)) < SL.e2)
                    {
                        SL.answer = SL.next; break;
                    }
                }

                SL.grad = SL.gradF(SL.next);

                SL.preD.x = SL.d.x;
                SL.preD.y = SL.d.y;

                SL.b = Math.Pow(SL.normV(SL.grad), 2) / Math.Pow(SL.normV(SL.preGrad), 2);
                Console.WriteLine("b: " + SL.b);
                SL.preGrad.x = SL.grad.x;
                SL.preGrad.y = SL.grad.y;
            }

            SL.answer.x = SL.next.x;
            SL.answer.y = SL.next.y;
            Console.WriteLine();
            Console.WriteLine("\nОтвет:" + SL.answer.x + " " + SL.answer.y);
            Console.WriteLine(SL.normV(SL.grad));
            Console.Read();
        }
Esempio n. 2
0
        static void Main()
        {
            FR SL = new FR(0.0001, 0.01, 2, 2);
            GR = new GoldenRatio();
            for ( SL.k = 0; ; SL.k++)
            {

                Console.WriteLine();
                Console.WriteLine("--------------------------------------");
                Console.WriteLine("\nточка:" + SL.next.x + " " + SL.next.y);
                Console.WriteLine("итерация: " + SL.k);
                Console.WriteLine("градиент: " + SL.grad.x + " " + SL.grad.y);
                Console.WriteLine("норма градиента: " + SL.normV(SL.grad));
                Console.WriteLine("d: " + SL.d.x+" "+ SL.d.y);

                if (SL.normV(SL.grad) < SL.e1) { SL.answer = SL.next; break; }

                SL.d.x = -SL.grad.x + SL.b * SL.d.x;
                SL.d.y = -SL.grad.y + SL.b * SL.d.y;

                SL.first.x = SL.next.x;
                SL.first.y = SL.next.y;

                SL.step = GR.Calculate(SL.next, SL.grad, SL.d, SL.b, SL.preD);
                Console.WriteLine("Шаг: " + SL.step);

                SL.next.x = SL.first.x +  SL.step * SL.d.x;
                SL.next.y = SL.first.y +  SL.step * SL.d.y;

                if (SL.normV(new Point(SL.next.x - SL.first.x, SL.next.y - SL.first.y)) < SL.e2)
                {
                    if (Math.Abs(SL.F(SL.next.x, SL.next.y) - SL.F(SL.first.x, SL.first.y)) < SL.e2)
                    { SL.answer = SL.next; break; }
                }

                SL.grad = SL.gradF(SL.next);

                SL.preD.x = SL.d.x;
                    SL.preD.y =  SL.d.y;

                SL.b = Math.Pow(SL.normV(SL.grad), 2) / Math.Pow(SL.normV(SL.preGrad), 2);
                Console.WriteLine("b: "+SL.b);
                SL.preGrad.x = SL.grad.x;
                SL.preGrad.y = SL.grad.y;

            }

            SL.answer.x = SL.next.x;
            SL.answer.y = SL.next.y;
            Console.WriteLine();
            Console.WriteLine("\nОтвет:" + SL.answer.x + " " + SL.answer.y);
            Console.WriteLine(SL.normV(SL.grad));
            Console.Read();
        }