Google Search

Tuesday, December 13, 2011

Newton Raphson Method using c program



Newton Raphson Method

#include< stdio.h > 
#include< conio.h >
#include<math.h>
float f(float x)
{
return x*log10(x)-1.2;
}
float df(float x)
{
return log10(x)+0.43429;
}
main()
{
int itr,maxitr;
float h,x0,x1,aerr;
clrscr();


 6



printf("enter the value of  x0”, “allowed errorm maximum iteration \n");
scanf("%f%f%d",&x0,&aerr,&maxitr);
for(itr=1;itr<=maxitr;itr++)
{
h=f(x0)/df(x0);
x1=x0-h;
printf("iteration %3d,x=%9.6f\n",itr,x1);
if(fabs(h)<aerr)
{
printf("after %3d iteration,root=%8.6f\n",itr,x1);
return 0;
}
x0=x1;
}
printf("solution does not converge,” “iteration not sufficient ");
return 1;
}

Result: -
Enter the x0, allowed error, maximum iterations.
……….
Iteration No.1 x=
Iteration No.2 x=
……….
………
After iterations, root= 

0 comments:

Post a Comment