Geradot345

lb4

Apr 14th, 2021
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. setlocale(LC_ALL, "Russian");
  8. const int a = -5, b = 5;
  9. float y, next_y, c, d;
  10. int x;
  11. cout << "x y"<<endl;
  12. for (x = a; x <= b; x++) {
  13. y = 10 * x - exp(-x);
  14. next_y = 10 * (x + 1) - exp(-x - 1);
  15. if (y * next_y < 0) {
  16. c = x;
  17. d = x + 1;
  18. }
  19. cout << x << " " << y<<endl;
  20. }
  21. cout << "Корень уравнения находиться между x=" << c << ".." << d << endl;
  22. float e = 0.0001;
  23. cout << "Уточнение корней методом половинного деления:";
  24. float x0;
  25. while (abs(d - c) > e) {
  26. x0 = (c + d) / 2;
  27. y = 10 * x0 - exp(-x0);
  28. cout << "x=" << x0 << " " << "y=" << y << endl;
  29. if (y == 0)break;
  30. if (y > 0)d = x0; else c = x0;
  31. }
  32. c = 0;
  33. d = 1;
  34. cout << "Приближенное значение Х=" << x0 << endl;
  35. cout << "Уточнение корней методом Ньютона:"<<endl;
  36. if ((10 * d - exp(-d)) * (-exp(-d)) > 0)x0 = d;
  37. else x0 = c;
  38. cout <<"X="<< x0 << endl;
  39. float x1;
  40. x1 = x0 - (10 * x0 - exp(-x0)) / (exp(-x0) + 10);
  41. cout <<"X="<< x1 << endl;
  42. while (abs(x1 - x0) > e) {
  43. x0 = x1;
  44. x1 = x0 - (10 * x0 - exp(-x0)) / (exp(-x0) + 10);
  45. cout <<"X="<< x1<<endl;
  46. }
  47. cout<< "Приближенное значение Х=" << x1 << endl;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment