lected);
}
// --------------------------------------------- ------------------------------
Метод сполучених градієнтів
// $ $ ---- Form CPP ----
// --------------------------------------------- ------------------------------
# include
# pragma hdrstop
# include
# include
# include "Unit1.h"
// --------------------------------------------- ------------------------------
# pragma package (smart_init)
# pragma resource "*. dfm" * Form1; shp = 1; shp1 = shp; shp2 = shp; shp3 = shp;
// --------------------------------------------- ------------------------------
__fastcall TForm1 :: TForm1 (TComponent * Owner)
: TForm (Owner)
{
}
vector Simple (double (* f) (vector ), vector x0, double h)
{fxk, fxk1; xk = x0; xk1 = x0; (int i = 0; i <2; i + +)
{
{= f (xk); [i] = xk [i] + h; = f (xk1); = xk1;
} (fxk> fxk1);
} (xk1);
} Conjugate (double (* f) (vector ), vector (* agrad) (vector ), vector x0, double h, double e)
{ xk = x0; xk1 = x0; agradXk, agradXk1, Sk, Sk1 (2); (int NumOfMetIt = 1;; NumOfMetIt + +)
{-> LabeledEdit3-> Text = IntToStr (NumOfMetIt); = agrad (xk); = agradXk; = Simple (f, xk, h); = agrad (xk1); Bk = (pow (agradXk1 [ 0], 2) + pow (agradXk1 [1], 2))/(pow (agradXk [0], 2) + pow (agradXk [1], 2)); [0] = agradXk1 [0] + Bk * Sk [0]; [1] = agradXk1 [1] + Bk * Sk [1]; -> Series1-> AddXY (xk [0], xk [1], "", Form1-> ColorBox1 -> Selected); -> Series1-> AddXY (xk1 [0], xk1 [1], "", Form1-> ColorBox1-> Selected); (fabs (f (xk1) - f (xk))
}
}
x)
{(x [0] + x [1] -2.0);
} g2 (vector x)
{(-x [0] + x [1] -1.0);
} g3 (vector x)
{(-x [1] -3.0);
}
x)
{(2.0 * (x [0] -3.0) * (x [0] -3.0) + (x [1] -2.0) * (x [1] -2.0));
}
// --------------------------------------------- ------------------------------ agradf (vector x0)
{ x = x0; [0] = - (4.0 * (x0 [0] -3. 0)); [1] = - (2.0 * (x0 [1] -2.0)); (x);
}
// --------------------------------------------- ------------------------------ agradrf (vector x0)
{ x = x0; [0] = - (4.0 * (x0 [0] -3.0) + 2.0 * shp1 * (x [0] + x [1] -2.0) - 2.0 * shp2 * (-x [0] + x [1] -1.0)); [1] = - (2.0 * (x0 [1] -2.0) + 2.0 * shp1 * (x [0] + x [1] -2.0 ) + 2.0 * shp2 * (-x [0] + x [1] -1.0) - shp3 * (-x [1] -3.0)); (x);
}
x)
{(2.0 * (x [0] -3.0) * (x [0] -3.0) + (x [1] -2.0) * (x [1] -2.0) + * (x [0] + x [1] -2.0) * (x [0] + x [1] -2.0) + * (-x [0] + x [1] -1.0) * (-x [0] + x [1] - 1.0) + * (-x [1] -3.0) * (-x [1] -3.0));