Created
January 24, 2019 06:30
-
-
Save vishal2612200/5cc8aa4ae80fed02b935347d67e46a22 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<math.h> | |
float f(float x){ | |
return x*log10(x)-1.2; | |
} | |
float df(float x){ | |
return log10(x) + 0.434293; | |
} | |
int main(){ | |
int a,b,maxitr,itr; | |
float aerr,x0,x1,h; | |
printf("please enter the valueof a,b :"); | |
scanf("%d%d",&a,&b); | |
printf("\n please enter the maxitr and aerr: "); | |
scanf("%d%f",&maxitr,&aerr); | |
if (f(a)*f(b)<0){ | |
x0 = (a+b)/2; | |
for(itr = 1;itr<=maxitr;itr++){ | |
h= f(x0)/df(x0); | |
x1= x0-h; | |
printf("\n itr no. %d , x = %f ", itr,x1); | |
if(fabs(h)<aerr){ | |
printf("\n After %d no. of itr by using N-R Method is %f",itr,x1); | |
return 0; | |
} | |
x0 = x1; | |
} | |
printf("\n Max itr is not sufficient "); | |
} | |
else{ | |
printf("\n there are no roots"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment