al__nasim

Newton_raphson

Dec 4th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define eps .001
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. double a,b,c,x0,x;
  8. double r=1;
  9. cout <<"Enter the value of a,b,c : ";
  10. cin >> a >>b >>c;
  11.  
  12. if(a>0)
  13. {
  14. cout <<"Enter the value of x0(initial guess) :";
  15. cin >> x0;
  16. x=x0;
  17. while(1)
  18. {
  19. double fx = a*x*x +b*x +c;
  20. double fpx = 2*a*x +b;
  21. x = x-(fx/fpx);
  22. cout <<"iteration "<<r++<<" root is : "<<x<<endl;
  23. //break;
  24. }
  25.  
  26. cout<<"The Root is : " <<x<<endl;
  27. }
  28. return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment