Advertisement
DacCum

Прості ітерації

Sep 29th, 2021
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. #define EPS 0.0001
  5.  
  6. using namespace std;
  7.  
  8. double initial(double x) {
  9.     return x - 0.05 * (pow(5., x) - 6 * x - 3);
  10. }
  11.  
  12. int main() {
  13.  
  14.     double x_1,  
  15.            x_0,  
  16.            dif_x;
  17.     cout << "Enter x0 in between[1.4; 1.7]: ";
  18.     cin >> x_0;
  19.  
  20.     int i = 0;
  21.  
  22.     do {
  23.         i++;
  24.         x_1 = initial(x_0);
  25.         dif_x = fabs(x_1 - x_0);
  26.         x_0 = x_1;
  27.         cout << "Itetarion " << i
  28.              << " xi = " << x_1
  29.              << "\tdifference = " << dif_x << endl;
  30.     } while (dif_x >= EPS);
  31.  
  32.     cout << "\nThe root of the equation = " << x_1 << endl;    
  33.  
  34.     return 0;
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement