namkongkirat

Newton Raphson Method

Dec 16th, 2016
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<math.h>
  4.  
  5. float f(float);
  6. float f1(float);
  7.  
  8. int main(){
  9. float x, x1,x2,y,t,m;
  10. printf("Enter the intial value:\n");
  11. scanf("%f",&x);
  12. x1=f(x);
  13. x2=f1(x);
  14. if(x2==0){
  15. printf("\nError!");
  16. main();
  17. }
  18. do{
  19. t=x;
  20. y=x-(f(x)/f1(x));
  21. m=t-y;
  22. x=y;
  23. }while(fabs(m)>0.0009);
  24. printf("\n\nThe root is: %.4f",y);
  25. getch();
  26. }
  27.  
  28. float f(float x){
  29. return((x*x)-(4*x)-10);
  30. }
  31.  
  32. float f1(float x){
  33. return((2*x)-4);
  34. }
Add Comment
Please, Sign In to add comment