Exemple #1
0
        private int Method(opt OptBeta)
        {
            opt Beta = OptBeta;

            double[] arr_p = new double[amountVar];
            Coord    p     = new Coord(arr_p);

            p = p / p.Norma;
            k = 1;
            //Высчитываем новую точку, пока квадрат нормы градиента меньше эпсилон
            while (true)
            {
                x[k + 1] = newPoint(x[k - 1], x[k], OptBeta);
                Grad     = Coord.Gradient(y, x[k + 1], amountVar);
                // Console.WriteLine("gradNorm^2 = {0}", Grad.Norma * Grad.Norma);

                if (Grad.Norma * Grad.Norma <= Eps || k >= 300)
                {
                    min = x[k + 1];
                    break;
                }
                k++;
            }
            return(k);
        }
Exemple #2
0
        Coord Gamma(Coord x1, Coord x2)
        {
            Coord grad1 = Coord.Gradient(y, x1, amountVar);
            Coord grad2 = Coord.Gradient(y, x2, amountVar);
            Coord gamma = grad2 - grad1;

            return(gamma);
        }
Exemple #3
0
        double FletcherReeves(Coord x1, Coord x2)
        {
            double Beta;
            Coord  grad1 = Coord.Gradient(y, x1, amountVar);
            Coord  grad2 = Coord.Gradient(y, x2, amountVar);

            Beta = (grad2.Norma * grad2.Norma) / (grad1.Norma * grad1.Norma);
            return(Beta);
        }
Exemple #4
0
        double PolakRibier(Coord x1, Coord x2)
        {
            double Beta;
            Coord  gamma;
            Coord  grad1 = Coord.Gradient(y, x1, amountVar);
            Coord  grad2 = Coord.Gradient(y, x2, amountVar);

            gamma = grad2 - grad1;
            Beta  = (grad2.Transp * gamma) / Math.Pow(grad1.Norma, 2);
            return(Beta);
        }
Exemple #5
0
        Coord newPoint(Coord x1, Coord x2, opt opt_A)
        {
            Matrix E    = Matrix.E(amountVar);
            Coord  grad = Coord.Gradient(y, x2, amountVar);

            if (k % amountVar == 1)
            {
                //if (k == 1)
                A = E;
            }
            else
            {
                A = opt_A(x1, x2);
            }
            p = -A * grad;
            LinearSearch f1 = new LinearSearch(x2, p, y);

            return(f1.M[6](50));
        }
Exemple #6
0
        Coord newPoint(Coord x1, Coord x2, opt OptBeta)
        {
            opt Beta = OptBeta;

            Grad = Coord.Gradient(y, x2, amountVar);
            //Если k = 1, n+1, 2n+1...
            if (k % amountVar == 1)
            {
                //if (k <= 3)
                p = -Grad;
            }
            else
            {
                double beta = Beta(x2, x1);
                p = -Grad + (beta * p);
            }

            p = p / p.Norma;
            //Запускаем линейный поиск
            LinearSearch f1 = new LinearSearch(x2, p, y);

            f1.Svenn(20);
            //f1.Svenn2();
            f1.Bolcano(20);
            //f1.Dichotomy(20);
            //f1.Bolcano2();
            f1.Davidon();
            //f1.Davidon2();
            //f1.DSK(30);
            //f1.Davidon2();
            alfa = f1.alfa_min;
            p    = p / p.Norma;
            Coord x3 = x2 + alfa * p;

            return(x3);
        }
Exemple #7
0
        public int Gelfond(int max)
        {
            k = 0;
            double delta = 0.01;
            Coord  _x1;
            Coord  _x2;
            Coord  d, dif;
            Coord  p, _p, p2;

            while (true)
            {
                _x1 = x[1] + delta * Coord.Ort(amountVar, 0);
                p   = -Coord.Gradient(y, x[1], amountVar);
                LinearSearch f1 = new LinearSearch(x[1], p, y);
                x[2] = f1.M[2](20);
                _p   = -Coord.Gradient(y, _x1, amountVar);
                LinearSearch f2 = new LinearSearch(_x1, _p, y);
                _x2 = f2.M[2](20);
                d   = x[2] - _x2;
                p2  = -Coord.Gradient(y, x[2], amountVar);
                LinearSearch f3 = new LinearSearch(x[2], p2, y);
                x[3] = f3.M[2](20);
                dif  = x[3] - x[2];
                k++;
                if (dif.norma() <= Eps)
                {
                    min = x[3];
                    break;
                }
                else
                {
                    x[1] = x[3];
                }
            }
            return(k);
        }
Exemple #8
0
        public int Koshi(int max)
        {
            k = 0;
            Coord p = -Coord.Gradient(y, x[1], amountVar);

            while (true)
            {
                LinearSearch f1 = new LinearSearch(x[1], p, y);
                x[2] = f1.M[2](20);
                Grad = Coord.Gradient(y, x[2], amountVar);
                k++;
                if (Grad.norma() <= Eps || k >= max)
                {
                    min = x[2];
                    break;
                }
                else
                {
                    x[1] = x[2];
                    p    = Grad;
                }
            }
            return(k);
        }
Exemple #9
0
        public int Method()
        {
            k = 1;
            Coord Grad;

            while (true)
            {
                x[k + 1] = newPoint(x[k - 1], x[k], BroidenFletcherShenno);
                //x[k + 1].output();


                //Console.WriteLine("k = {0}", k);
                Grad = Coord.Gradient(y, x[k + 1], amountVar);
                //Grad.output();
                //Console.WriteLine("Norma = {0}", Grad.Norma);
                if (Grad.Norma <= Eps || k >= 300)
                {
                    min = x[k + 1];
                    break;
                }
                k++;
            }
            return(k);
        }