Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- int main() {
- double E,x1,x2,t,a,b,F,Ra,Rb,i;
- a = 0;
- b = 2;
- E = 0.01;
- i = 0;
- cout << "Введите начальные точки: " << "\n";
- cin >> x1 >> x2;
- while ((abs(2*(x1-1))>=E) || (abs(40*(x2-1))>=E)) {
- while (((b - a)/2 > E)) {
- Ra = a + 0.618*(b - a);
- Rb = b - 0.618*(b - a);
- if (pow(x1 - Ra * (2*(x1-1)) - 1, 2) + 20 * pow(x2 - Ra * (40*(x2-1)) - 1, 2) + 11 < pow(x1 - Rb * (2*(x1-1)) - 1, 2) + 20 * pow(x2 - Rb * (40*(x2-1)) - 1, 2) + 11) {
- a = Rb;
- t = Ra;
- }else {
- b = Ra;
- t = Rb;
- }
- }
- a=0;
- b=2;
- x1 = x1 - t * (2*(x1-1));
- x2 = x2 - t * (40*(x2-1));
- i++;
- cout << "Итерация " << i << ": (" << x1 << " ; " << x2 << ")" << "\n";
- }
- F = round(pow(x1 - 1, 2) + 20 * pow(x2 - 1, 2) + 11);
- cout << "Количество итераций: " << i << "\n";
- cout << "Значение функции: " << F << "\n";
- cout << "Точка x1: " << x1 << "\n" << "Точка x2: " << x2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement