public static double diff_4(function f, Coord x, int number)
        {
            double dx     = 1e-7;
            int    length = x.coord.Length;
            Coord  x_dx   = dx * Coord.Ort(length, number);

            return((-f(x + 2 * x_dx) + 8 * f(x + x_dx) - 8 * f(x - x_dx) + f(x - 2 * x_dx)) / (12 * dx));
        }
        public static double diff_3(function f, Coord x, int number)
        {
            double dx     = 1e-7;
            int    length = x.coord.Length;
            Coord  x_dx   = dx * Coord.Ort(length, number);

            return((f(x - x_dx) - 4 * f(x) + 3 * f(x + x_dx)) / (2 * dx));
        }
        public static double second_diff_2(function f, Coord x, int number_1, int number_2)
        {
            double dx     = 1e-5;
            int    length = x.coord.Length;
            Coord  x_dx_1 = dx * Coord.Ort(length, number_1);
            Coord  x_dx_2 = dx * Coord.Ort(length, number_2);

            return((f(x + x_dx_1 + x_dx_2) - f(x + x_dx_1 - x_dx_2) - f(x - x_dx_1 + x_dx_2) + f(x - x_dx_1 - x_dx_2)) / (4 * dx * dx));
        }
예제 #4
0
        public void SuitablePoints(Coord x, int length, List <Coord> p)
        {
            Coord Ort = Coord.Ort(x.coord.Length, length - 1);

            p.Add(x + h * Ort);

            p.Add(x - h * Ort);

            if (length - 1 > 0)
            {
                SuitablePoints(new Coord(x + h * Ort), length - 1, p);
                SuitablePoints(new Coord(x - h * Ort), length - 1, p);
                SuitablePoints(new Coord(x), length - 1, p);
            }
        }
예제 #5
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);
        }