Exemple #1
0
 newton(double e1, double e2, double x, double y)
 {
     this.e1 = e1;
     this.e2 = e2;
     first   = new Point(x, y);
     next    = new Point(first.x, first.y);
     grad    = gradF(next);
     answer  = new Point();
     d       = new Point(-grad.x, -grad.y);
     preGrad = new Point(grad.x, grad.y);
     preD    = new Point(d.x, d.y);
     GR      = new GoldenRatio();
     m       = new Matrix(16, -1, -1, 2);
 }
Exemple #2
0
 newton(double e1, double e2, double x, double y)
 {
     this.e1 = e1;
     this.e2 = e2;
     first = new Point(x, y);
     next = new Point(first.x, first.y);
     grad = gradF(next);
     answer = new Point();
     d = new Point(-grad.x, -grad.y);
     preGrad = new Point(grad.x, grad.y);
     preD = new Point(d.x, d.y);
     GR = new GoldenRatio();
     m = new Matrix(16,-1,-1,2);
 }
Exemple #3
0
        static void Main()
        {
            newton SL = new newton(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));

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

                Console.WriteLine("деф обр матр: " + SL.m.Invert().Det());
                if ((SL.m.Invert().Det()) > 0)            // H^-1>0 это же det?
                {
                    SL.d    = -((SL.m.Invert()) * SL.grad);
                    SL.step = 1;
                }
                else
                {
                    SL.d.x  = -SL.grad.x;
                    SL.d.y  = -SL.grad.y;
                    SL.step = GR.Calculate(SL.next, SL.d);
                }
                Console.WriteLine("d: " + SL.d.x + " " + SL.d.y);
                //if(k>1000) { break;}

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

                // Console.WriteLine(k);



                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.first.x = SL.next.x;
                SL.first.y = SL.next.y;

                SL.grad = SL.gradF(SL.next);
                //SL.h = SL.H(SL.first);


                Console.WriteLine("--------------------------------------");
                Console.WriteLine("--------------------------------------");
                Console.WriteLine("итерация: " + SL.k);
            }

            SL.answer.x = SL.next.x;
            SL.answer.y = SL.next.y;
            Console.WriteLine();
            Console.WriteLine("--------------------------------------");
            Console.WriteLine("--------------------------------------");
            Console.WriteLine("\nОтвет:" + SL.answer.x + " " + SL.answer.y);
            Console.WriteLine("итерация: " + SL.k);
            Console.WriteLine("норма градиента: " + SL.normV(SL.grad));
            Console.Read();
        }
Exemple #4
0
        static void Main()
        {
            newton SL = new newton(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));

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

                Console.WriteLine("деф обр матр: " + SL.m.Invert().Det());
                if ((SL.m.Invert().Det() ) > 0)           // H^-1>0 это же det?
                {
                    SL.d =-((SL.m.Invert()) * SL.grad);
                    SL.step = 1;
                }
                else
                {
                    SL.d.x = -SL.grad.x;
                    SL.d.y = -SL.grad.y;
                    SL.step = GR.Calculate(SL.next, SL.d);
                }
                Console.WriteLine("d: " + SL.d.x+" "+ SL.d.y);
                //if(k>1000) { break;}

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

               // Console.WriteLine(k);

               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.first.x = SL.next.x;
                 SL.first.y = SL.next.y;

                SL.grad = SL.gradF(SL.next);
                //SL.h = SL.H(SL.first);

                Console.WriteLine("--------------------------------------");
                Console.WriteLine("--------------------------------------");
                Console.WriteLine("итерация: " + SL.k);

            }

            SL.answer.x = SL.next.x;
            SL.answer.y = SL.next.y;
            Console.WriteLine();
            Console.WriteLine("--------------------------------------");
            Console.WriteLine("--------------------------------------");
            Console.WriteLine("\nОтвет:" + SL.answer.x + " " + SL.answer.y);
            Console.WriteLine("итерация: " + SL.k);
            Console.WriteLine("норма градиента: " + SL.normV(SL.grad));
            Console.Read();
        }