Advertisement
daktarism

Newton - Raphson Method

Mar 11th, 2014
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.50 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. double f(double a){return 0.7-a+sin(a);}
  4. double fturev(double a){return -1+cos(a);}
  5.  
  6. int main()
  7. {
  8.     double epsilon,x1,fark,x2;
  9.     printf("X1 : "); scanf("%lf",&x1);
  10.     printf("epsilon : "); scanf("%lf",&epsilon);
  11.  
  12.     do{
  13.         x2 =  x1 - (f(x1)  / fturev(x1)) ;
  14.         fark = fabs(x1-x2);
  15.         printf("x1 = %.15lf , x2 = %.15lf , fark = %.15lf \n",x1,x2,fark );
  16.         if( fark > epsilon ) { x1 = x2;}
  17.     } while( fark > epsilon );
  18.  
  19.     return 0;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement