Advertisement
Rakibul_Ahasan

Fixed_PointI_teration_Method

Mar 15th, 2020
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. double func(double x)
  6. {
  7.   return cos(x);
  8. }
  9.  
  10. int main()
  11. {
  12.   double x=1,eps = 0.001,p;
  13.   int i=1,N=1000;
  14.  
  15.   while(true)
  16.   {
  17.     p = func(x);
  18.     if(fabs(p-x) < eps)
  19.     {
  20.       cout<<p<<endl;
  21.       break;
  22.     }
  23.     cout<<"Iteration "<<i<<": p = "<<p<<endl;
  24.     i++;
  25.     x = p;
  26.     cout<<"The solution is "<<p<<endl;
  27.     if(i>N)
  28.     {
  29.       cout<<"Solution not found"<<endl;
  30.       break;
  31.     }
  32.   }
  33.   cout<<"The solution is x = "<<p<<" in the iteration "<<i-1<<endl;
  34.  
  35.   return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement