Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cmath>
- const double error=1e-7;
- using namespace std ;
- // newton
- double x,a;
- double funct(double x){
- return x*x-3*x+2;
- }
- double functDiff(double x ){
- return 2*x-3 ;
- }
- int main(){
- cout<<"input a: " ;
- cin>> a ;
- int count = 1;
- double ans = funct(a);
- printf("%d\t%.10f %.10f \n",count,a,ans);
- do {
- a = a-( ans/functDiff(a) );
- ans = funct(a);
- count++;
- printf("%d\t%.10f %.10f \n",count,a,ans);
- }while(fabs(ans) > error);
- return 0 ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement