/* Solution of an algebraic equation x^5+3x^2-10=0 by Newton-Raphson method */
#include<stdio.h>
#include<math.h>
int main()
{
int count=0;
float x0, xn, fx, dfx;
printf("Initial guess value x0:");
scanf("%f", &x0);
/* Iteraion begins */
label:
fx=pow(x0,5)+3*x0*x0-10;
dfx=5*pow(x0,4)+6*x0;
xn=x0-fx/dfx;
if(fabs(xn-x0)<0.0001)
printf("The final root is:%f\n",xn);
else
{
x0=xn;
count=count+1;
if(count>100)
printf("Solution does not converge,choose another guess value.\n");
else
goto label;
}
return(0);
}
#include<stdio.h>
#include<math.h>
int main()
{
int count=0;
float x0, xn, fx, dfx;
printf("Initial guess value x0:");
scanf("%f", &x0);
/* Iteraion begins */
label:
fx=pow(x0,5)+3*x0*x0-10;
dfx=5*pow(x0,4)+6*x0;
xn=x0-fx/dfx;
if(fabs(xn-x0)<0.0001)
printf("The final root is:%f\n",xn);
else
{
x0=xn;
count=count+1;
if(count>100)
printf("Solution does not converge,choose another guess value.\n");
else
goto label;
}
return(0);
}
Comments
Post a Comment