Advertisement
noor017

Aitken Delta Squared Root Finding

Jul 7th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include<cstdio>
  2. #include<cmath>
  3. #include<iostream>
  4.  
  5. #define ESP 0.000001
  6. #define F(x) (1-4*x*x)/6
  7.  
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12.     double x1, x2, x3, x4, y;
  13.     cin >> x1;
  14.  
  15.     for (int i=1; ; i=i+3)
  16.     {
  17.         x2 = F(x1);
  18.         x3 = F(x2);
  19.  
  20.         if(fabs(x3-x2) < ESP)
  21.         {
  22.             cout << x3;
  23.             break;
  24.         }
  25.  
  26.         else
  27.         {
  28.             y = x3-2*x2+x1;
  29.             x1 = x3-(((x3-x2)*(x3-x2))/y);
  30.         }
  31.     }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement