Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include<iostream>
- #include<string>
- #include<alg.h>
- using namespace std;
- const double EPS = 1e-4;
- const int INF = 1e8 + 13;
- double func(double x)
- {
- return 2. * x*x - 6 * x - 3;
- }
- pair<double, double> solve()
- {
- double left = -1;
- double right = 3;
- double step = 0.00001;
- double answer = INF;
- double answerPoint = -INF;
- for (double x = left; left <= right; x += step)
- {
- double cur = func(x);
- if (answer == INF)
- {
- answer = cur;
- continue;
- }
- if (cur <= answer)
- {
- answer = cur;
- answerPoint = x;
- }
- else
- break;
- }
- return { answer, answerPoint };
- }
- int main()
- {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- pair<double, double> ans = solve();
- cout << "min = " << ans.first << "\nwith x = " << ans.second << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement