Advertisement
luizaspan

Bisection method

Aug 28th, 2015
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.38 KB | None | 0 0
  1. // para cosx=0, com a=0 e b=3 e epsilon
  2.  
  3. #include <stdio.h>
  4. #include <math.h>
  5.  
  6. #define pi M_PI
  7.  
  8. #define eps 1e-5
  9.  
  10. int main(void)
  11. {
  12.     double a=0, b=3, c, y;
  13.  
  14.     while ((b-a)>eps)
  15.     {
  16.         c=(a+b)/2;
  17.         y=cos(c);
  18.  
  19.         if (y>0)
  20.             a=c;
  21.  
  22.         else if (y<0)
  23.             b=c;
  24.  
  25.         else if (y==0)
  26.             break;
  27.     }
  28.  
  29.     printf("Raiz calculada: %e \nRaiz teórica: %e \n",c,pi/2);
  30.  
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement