Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- setlocale(LC_ALL, "Russian");
- const int a = -5, b = 5;
- float y, next_y, c, d;
- int x;
- cout << "x y"<<endl;
- for (x = a; x <= b; x++) {
- y = 10 * x - exp(-x);
- next_y = 10 * (x + 1) - exp(-x - 1);
- if (y * next_y < 0) {
- c = x;
- d = x + 1;
- }
- cout << x << " " << y<<endl;
- }
- cout << "Корень уравнения находиться между x=" << c << ".." << d << endl;
- float e = 0.0001;
- cout << "Уточнение корней методом половинного деления:";
- float x0;
- while (abs(d - c) > e) {
- x0 = (c + d) / 2;
- y = 10 * x0 - exp(-x0);
- cout << "x=" << x0 << " " << "y=" << y << endl;
- if (y == 0)break;
- if (y > 0)d = x0; else c = x0;
- }
- c = 0;
- d = 1;
- cout << "Приближенное значение Х=" << x0 << endl;
- cout << "Уточнение корней методом Ньютона:"<<endl;
- if ((10 * d - exp(-d)) * (-exp(-d)) > 0)x0 = d;
- else x0 = c;
- cout <<"X="<< x0 << endl;
- float x1;
- x1 = x0 - (10 * x0 - exp(-x0)) / (exp(-x0) + 10);
- cout <<"X="<< x1 << endl;
- while (abs(x1 - x0) > e) {
- x0 = x1;
- x1 = x0 - (10 * x0 - exp(-x0)) / (exp(-x0) + 10);
- cout <<"X="<< x1<<endl;
- }
- cout<< "Приближенное значение Х=" << x1 << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment