Advertisement
Rakibul_Ahasan

Fixed PointI teration Method

Mar 15th, 2020
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int It=6;
  4. double v;
  5. // Fixed POINT METHOD
  6.  
  7. double x,y,z;
  8.  
  9. double First_Equation (){
  10.    // return 2-(x*x);
  11.    return 5/x;
  12. }
  13.  
  14. double Second_Equation (){
  15.     return (y*y)+y-5;
  16. }
  17.  
  18. double Third_Equation (){
  19.    
  20.     return (z+(5/z))/2;
  21. }
  22.  
  23. void solve(){
  24.     int ok=0,i=0;
  25.     v=0;
  26.     while(true){
  27.         long double F=First_Equation();
  28.          cout<<"Iteration "<<++i<<": "<<F<<"\n";
  29.          x=F;
  30.           if(It==ok) break;
  31.          if(v-F==0){ break;goto S;}
  32.          v=F;
  33.          ok++;
  34.     }
  35.     cout<<"\n\n";
  36.     ok=0,v=0,i=0;
  37.     while(true){
  38.         long double F=Second_Equation();
  39.          cout<<"Iteration "<<++i<<": "<<F<<"\n";
  40.          y=F;
  41.           if(It==ok) break;
  42.          if(v-F==0){ break;goto S;}
  43.          v=F;
  44.          ok++;
  45.     }
  46.    
  47.     cout<<"\n\n";
  48.     ok=0,v=0,i=0;
  49.     while(true){
  50.         long double F=Third_Equation();
  51.          cout<<"Iteration "<<++i<<": "<<F<<"\n";
  52.          z=F;
  53.          if(It==ok) break;
  54.          if(v-F==0){ break;goto S;}
  55.          v=F;
  56.          ok++;
  57.     }
  58.     S:
  59.     cout<<"\n"<<"Solution: "<<v<<"\n";
  60. }
  61.  
  62.  
  63. int main()
  64. {
  65.     cin>>x;
  66.     cin>>y;
  67.     cin>>z;
  68.     solve();
  69.    
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement