Добавил:
degenetard
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:lab_6 / prog
.cpp#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
double f(double x, double y) {
return 3 * pow(x, 2) + 2 * pow(y, 2) - 5 * y + 1;
}
double lambda(double x, double y) {
return (36 * pow(x, 2) + 16 * pow(y, 2) - 40 * y + 25) /
(216 * pow(x, 2) + 64 * pow(y, 2) - 160 * y + 100);
}
double p(double x) {
return 6 * x;
}
double s(double y) {
return 4 * y - 5;
}
void NSA(double x, double y, double E) {
double L, F = f(x, y);
int k = 0;
cout << "k\t x \t y\t p\t s f(x,y)" << endl;
cout << "--------------------------------------------------" << endl;
cout << setprecision(7) << k << setw(9) <<
x << setw(10) << y << setw(10) <<
p(x) << setw(10) << s(y) << setw(10) << F << endl;
k = 1;
while (abs(p(x)) >= E && abs(s(y)) >= E) {
L = lambda(x, y); x -= L * p(x);
y -= L * s(y); F = f(x, y);
cout << setprecision(4) << fixed << k << setw(9) <<
x << setw(10) << y << setw(10) <<
p(x) << setw(10) << s(y) << setw(10) << F << endl;
k++;
}
cout << "\nXmin= " << x << "\tYmin= " << y << "\tf(x, y)= " << F << endl;
}
int main() {
NSA(1, 1, 1E-4);
return 0;
}