Advertisement
ssr17

Monotone

Jul 22nd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. float f(float x, float a,float b,float c)
  6. {
  7.     return ((a*x*x)+(b*x)+c);
  8. }
  9.  
  10. float g(float x, float a,float b,float c)
  11. {
  12.     return ((((-a)*x*x)-c)/b);
  13. }
  14.  
  15. int main()
  16. {
  17.     float a, b, c, root;
  18.     int it, count=0;
  19.     cout<<"Enter The Value of a : ";
  20.     cin>>a;
  21.     cout<<"Enter The Value of b : ";
  22.     cin>>b;
  23.     cout<<"Enter The Value of c: ";
  24.     cin>>c;
  25.  
  26.     cout<<"Enter The Number of iterations : ";
  27.     cin>>it;
  28.  
  29.     int X[it];
  30.     cout<<"Enter The Initial Guess : ";
  31.     cin>>X[0];
  32.  
  33.     for(int i=0; i<=it; i++){
  34.         X[i+1] = g(X[i],a,b,c);
  35.         if(X[i+1] > X[i])
  36.             count++;
  37.         else
  38.             count = 0;
  39.         if(count > 3)
  40.             break;
  41.     }
  42.  
  43.     cout<<"System has Monotone divergence"<<endl;
  44.  
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement