Advertisement
luizaspan

Método de Newton-Raphson (errinho)

Sep 4th, 2015
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.48 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. #define eps 1e-6
  5. #define dx 1e-8
  6.  
  7. double f(double x)
  8. {
  9.     return (x*x*x - 2*x*x - 11*x + 12);
  10. }
  11.  
  12. double df(double x)
  13. {
  14.     return (3*x*x - 4*x - 11);
  15. }
  16.  
  17. int main(void)
  18. {  
  19.     double x,delta,y;
  20.     int i;
  21.  
  22.     for (double x0=2.3528 ; x0>1e-4 ; x0=x0-5e-2)
  23.     {
  24.         x=x0;
  25.         do
  26.         {
  27.             y=x;
  28.             x=x-f(x)/df(x);
  29.             delta=(x-y);
  30.         } while (delta>eps);
  31.  
  32.         printf("%lf \t %lf \t %lf \n",x0,x,f(x)); // bacia de atração
  33.  
  34.     }
  35.  
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement