Created
August 27, 2016 19:36
-
-
Save anonymous/969b5af7e7475f3dbda7df5949fff998 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Визначити характер екстремуму функції f(x1, x2, x3) в стаціонарній точці Х* | |
#include <iostream> | |
#include <locale> | |
#include <conio.h> | |
using namespace std; | |
double dfx(double x, double y, double z) { return -2*x + y - 2*z + 11; } //1-я производная по x | |
double dfy(double x, double y, double z) { return -10*y + x + 2*z + 2; } //1-я производная по y | |
double dfz(double x, double y, double z) { return -6*z - 2*x + 2*y + 18; } //1-я производная по z | |
int multi(int a, int b, int c, int d) { return a*c - b*d; } | |
int main() { | |
double x1, x2, x3; // координаты X* | |
double d1, d2, d3; // дельта | |
// 2-е производные | |
const int dfxx = -2; | |
const int dfxy = 1; | |
const int dfyy = -10; | |
const int dfxz = -2; | |
const int dfyz = 2; | |
const int dfzz = -6; | |
setlocale(LC_ALL, "Russian"); | |
cout << "x1=", cin >> x1; | |
cout << "x2=", cin >> x2; | |
cout << "x3=", cin >> x3; | |
if ((dfx(x1, x2, x3) != 0) || (dfy(x1, x2, x3) != 0) || (dfz(x1, x2, x3) != 0)) { | |
cout << "Данная точка не является точкой экстремума!"; | |
_getch(); | |
return 0; | |
} | |
d1 = dfxx; | |
d2 = multi(dfxx, dfxy, dfxy, dfyy); | |
d3 = dfxx*multi(dfyy, dfyz, dfyz, dfzz) - dfxy*multi(dfxy, dfyz, dfxz, dfzz) + dfxz*multi(dfxy, dfyy, dfxz, dfyz); | |
if (d1 > 0 && d2 > 0 && d3 > 0) { | |
cout << "Исходная функция достигает минимума в точке X*"; | |
_getch(); | |
return 0; | |
} | |
if (d1 < 0 && d2 > 0 && d3 < 0) { | |
cout << "Исходная функция достигает максимума в точке X*"; | |
_getch(); | |
return 0; | |
} | |
if (d3 != 0) { | |
cout << "X* - это седловая точка"; | |
_getch(); | |
return 0; | |
} | |
if (d3 = 0) { | |
cout << "Нет ответа о характере точки X*"; | |
_getch(); | |
return 0; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Для функції f(x) задані точки x1, x2, x3 відповідні їм значення функції f(x1), f(x2), f(x3). Знайти екстремум функціїf(x) методом оцінки з використанням квадратичної апроксимації | |
#include <iostream> | |
#include <locale> | |
#include <conio.h> | |
using namespace std; | |
int main() { | |
double x1, x2, x3; | |
double f1, f2, f3; // значения ф-й в x1, x2, x3 | |
double a1, a2; // постоянные величины ф-и q(x)=a0+a1(x-x1)+a2(x-x1)(x-x2) | |
double x; // приемлимая оценка координаты точки истинного оптимума x* | |
setlocale(LC_ALL, "Russian"); | |
cout << "x1=", cin >> x1; | |
cout << "x2=", cin >> x2; | |
cout << "x3=", cin >> x3; | |
cout << endl; | |
if (x2 == x1 || x3 == x1 || x3 == x2) { | |
cout << "Ноль в знаменателе!"; | |
_getch(); | |
return 0; | |
} | |
cout << "f1=", cin >> f1; | |
cout << "f2=", cin >> f2; | |
cout << "f3=", cin >> f3; | |
cout << endl; | |
a1 = (f2 - f1) / (x2 - x1); | |
a2 = 1 / (x3 - x2) * ((f3-f1)/(x3-x1) - (f2-f1)/(x2-x1)); | |
x = (x2 + x1) / 2 - (a1 / (2 * a2)); | |
cout << "Экстремум функции f(x) = " << x; | |
_getch(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment