/*newton
raphson method*/
#include<stdio.h>
#include<math.h>
void
main()
{
int count=0;
float x0,xn,fx,dfx;
printf("enter the guess
value:");
scanf("%f",&x0);
/*iteration process*/
label:
fx=(((1-x0*x0)*tan(x0))-x0);
dfx=(((1-x0*x0)*(pow(cos(x0),-2)))-(1+(2*x0*tan(x0))));
xn=x0-(fx/dfx);
if((fabs(xn-x0))<0.001)
printf("\n the final root is %.4f
\n",xn);
else
{x0=xn;
count=count+1;
if (count>100)
{
printf("the solution does not
converge");
printf("enter a different guess
value:");
}
else
goto label;
}
}
RESULT:
enter the
guess value:2 3
the final root is 2.7437
Press any
key to continue
No comments:
Post a Comment
Thanks for comment.