Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. #include<iostream>
  2. #include<cmath>
  3. const double error=1e-7;
  4. using namespace std ;
  5. // newton
  6.  
  7. double x,a;
  8.  
  9. double funct(double x){
  10. return x*x-3*x+2;
  11. }
  12.  
  13. double functDiff(double x ){
  14. return 2*x-3 ;
  15. }
  16.  
  17. int main(){
  18.  
  19. cout<<"input a: " ;
  20. cin>> a ;
  21.  
  22. int count = 1;
  23. double ans = funct(a);
  24. printf("%d\t%.10f %.10f \n",count,a,ans);
  25. do {
  26. a = a-( ans/functDiff(a) );
  27. ans = funct(a);
  28. count++;
  29. printf("%d\t%.10f %.10f \n",count,a,ans);
  30. }while(fabs(ans) > error);
  31.  
  32. return 0 ;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement