Wednesday, November 28, 2007

Program in C for False position method...

Important notes:
1. while running the program replace [] (in #include )by less than and greater than symbol since i cant publish post with those symbol.
2. if there is written like less than then use symbol in actual program.

/*programm for false-position
method by HEMANT ABHARE.*/
#include[stdio.h]
#include[math.h]
#define epsilon 1e-6
/*this is a programm to find out root
of the equation x^10-15=0 by false-position
method*/

main()
{
double g1,g2,g,v,v1,v2,dx;
int found,converged,i;
found=0;
printf("enter the first guess\n");
scanf("%lf",&g1);
v1=g1*g1*g1*g1*g1*g1*g1*g1*g1*g1-15;
printf(" value 1 is %lf\n",v1);
while (found==0)
{
printf(" enter the second guess\n");
scanf("%lf",&g2);
v2=g2*g2*g2*g2*g2*g2*g2*g2*g2*g2-15;
printf(" value 2 is %lf\n",v2);
if (v1*v2>0)
{found=0;}
else
found=1;
}
printf("right guess\n");
i=1;
while (converged==0)
{
printf("\n iteration=%d\n",i);
g=g1-((v1*(g1-g2))/(v1-v2));
printf(" new gues is %lf\n",g);
v=g*g*g*g*g*g*g*g*g*g-15;
printf("new value is%lf\n",v);
if (v*v1>0)
{
g1=g;
printf(" the next guess is %lf\n",g);
dx=(g1-g2)/g1;
}
else
{
g2=g;
printf(" the next guess is %lf\n",g);
dx=(g1-g2)/g1;
}
if (fabs(dx)'less than'epsilon)
{converged=1;}
i=i+1;
}
}

No comments: