Guest User

Untitled

a guest
Oct 14th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. float f(float x)
  2. {
  3.   return exp(1-x)*cos(x)-x;
  4. }
  5.  
  6. float fd(float x)
  7. {
  8.   return -exp(1-x)*sin(x)-exp(1-x)*cos(x)-1;
  9. }
  10.  
  11. float fdd(float x)
  12. {
  13.   return 2*exp(1-x)*sin(x);
  14. }
  15.  
  16. bool tangente(float x)
  17. {
  18.   float x1 = 0.0;
  19.   float fx1 = f(x1);
  20.   float e_max=0.000005;
  21.   int n_iter = 0;
  22.  
  23.   while((abs(x1-x) > e_max) && (fx1 > e_max))
  24.     {
  25.       x = x1;  
  26.       x1 = x - f(x) / fd(x);
  27.       fx1 = f(x1);
  28.      
  29.  
  30.       if((fd(x) == 0) && (fdd(x1) * fdd(x) < 0 ))
  31.     return false;
  32.    
  33.       n_iter++;
  34.  
  35.       cout << "numero de iterações: " << n_iter << endl;
  36.       cout << "Zero = " << x1 << endl;
  37.       cout << "Erro maximo: " << e_max << endl;
  38.     }
  39.  
  40.   cout << endl << endl;
  41.   return true;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment