Beispiel #1
0
 public GradientMethod(IntroducedFunction _y, Coord _x0, double _Eps, int _maxIter) : base(_y, _Eps, _maxIter)
 {
     amountPoints = amountVar + 2;
     x            = new Coord[amountPoints];
     x[0]         = _x0;
     x[1]         = x[0];
 }
Beispiel #2
0
 //Конструктор
 public UnconditionalOptimization(IntroducedFunction _y, Coord _x0, double _Eps, int _maxIter) : base(_y, _Eps, _maxIter)
 {
     x    = new Coord[5];
     x[0] = _x0;
     x[1] = x[0];
     h    = 0.01 * x[0].Norma;
     beta = 2;
 }
 //Градиент
 public static Coord Gradient(IntroducedFunction y, Coord x, int amount)
 {
     double[] g = new double[amount];
     for (int i = 0; i < amount; i++)
     {
         g[i] = Func.diff_4(y, x, i);
     }
     return(new Coord(g));
 }
        public static double second_diff_2(IntroducedFunction 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.Answer(x + x_dx_1 + x_dx_2) - f.Answer(x + x_dx_1 - x_dx_2) - f.Answer(x - x_dx_1 + x_dx_2) + f.Answer(x - x_dx_1 - x_dx_2)) / (4 * dx * dx));
        }
        public static double diff_4(IntroducedFunction f, Coord x, int number)
        {
            double dx     = 1e-5;
            int    length = x.coord.Length;
            Coord  x_dx   = dx * Coord.Ort(length, number);

            return((-f.Answer(x + 2 * x_dx) + 8 * f.Answer(x + x_dx) - 8 * f.Answer(x - x_dx) + f.Answer(x - 2 * x_dx)) / (12 * dx));
            //return (-f(x + 2 * x_dx, parts) + 8 * f(x + x_dx, parts) - 8 * f(x - x_dx, parts) + f(x - 2 * x_dx, parts)) / (12 * dx);
        }
 //Гессиан
 public static Matrix H(IntroducedFunction f, int length, Coord x)
 {
     double[,] el = new double[length, length];
     for (int i = 0; i < length; i++)
     {
         for (int j = 0; j < length; j++)
         {
             el[i, j] = Func.second_diff_2(f, x, i, j);
         }
     }
     return(new Matrix(el));
 }
        //Событие при нажатии на кнопку ввести функцию
        private void button1_Click(object sender, EventArgs e)
        {
            foreach (TextBox te in t)
            {
                te.Hide();
                te.Text = "";
            }
            foreach (Label la in l)
            {
                la.Hide();
            }

            minTextBox.Text        = "";
            IterationsTextBox.Text = "";

            EpsLabel.Visible   = true;
            EpsTextBox.Visible = true;

            ChangeMethodLabel.Visible    = true;
            ChangeMethodComboBox.Visible = true;
            ChangeMethodComboBox.Text    = "";
            mLabel.Visible           = true;
            mTextBox.Visible         = true;
            CoordinatesLabel.Visible = true;
            func = new IntroducedFunction(FunctionComboBox.Text);
            if (func.IsRightFunction())
            {
                func.CountVariables();
                func.Postfix();
                for (int i = 0; i < func.Variables; i++)
                {
                    t[i].Visible = true;
                    l[i].Visible = true;
                }
            }
            else
            {
                MessageBox.Show("Неправильная функция");
            }
        }
 //Конструктор
 public LinearSearch(Coord _x0, Coord _p, IntroducedFunction _y)
 {
     x0 = _x0;
     p  = _p;
     y  = _y;
 }
Beispiel #9
0
 //Конструктор
 public ConjugatedGrad(IntroducedFunction _y, Coord _x0, double _Eps, int _maxIter) : base(_y, _Eps, _maxIter)
 {
     x    = new Coord[maxIter + 2];
     x[0] = _x0;
     x[1] = x[0];
 }
 public Coord Gradient(IntroducedFunction y)
 {
     return(Gradient(y, this, this.coord.Length));
 }
Beispiel #11
0
 public HookeJeeves(IntroducedFunction _y, Coord _x0, double _Eps, int _maxIter) : base(_y, _Eps, _maxIter)
 {
     h = 0.01 * x[0].Norma;
 }