#include
#include
#include
float f(float x)
{
float y;
y=x*x-25;
return y;
}
int main()
{
int i;
float x0,x1,x2,y0,y1,y2,e;
printf("Enter the value of x0,x1,error allowed\n");
scanf("%f\n %f\n %f",&x0, &x1,&e);
printf("x0=%f, x1=%f,e=%f\n",x0,x1,e);
y0=f(x0);
y1=f(x1);
i=0;
if((y0*y1)>0)
{
printf("Starting value unsuitable\n");
printf("x0=%f, x1=%f, y0=%f, y1=%f",x0,x1,y0,y1);
exit(1);
}
printf(" Iteration x0 x1 x2 f(x0) f(x1) f(x2)\n");
while((fabs((x1-x0)/x1))>e)
{
x2=(x0+x1)/2;
y2=f(x2);
i++;
if((y0*y2)>0)
{
x0=x2;
}
else
{
x1=x2;
}
printf(" %d %f %f %f %f %f %f\n",i,x0,x1,x2,y0,y1,y2);
}
printf("Solution is convergent to a root.\n");
printf("No. of iteration= %d & x=%f\n\n",i,x2);
return 0;
}
Nov 18, 2008
Bisection Method
Posted by
bikash pradhan
at
8:21 AM
Labels: Bisection Method c program code
Subscribe to:
Post Comments (Atom)
Search
Programs
- backward difference formula c program code (1)
- Bisection Method c program code (1)
- Cramers rule (1)
- False position (1)
- Forward Difference Formula c program code (1)
- Gauss Seidal Method c program code (1)
- Guass Elimination Method c program code (1)
- Method of Successive Approximation c program code (1)
- Newton Raphson Method c program code (1)
- Newton's Backward Interpolation Formula c program code (1)
- Newton's Forward Interpolation Formula c program code (1)
- Regula Falsi on False Position Method c program code (1)
- Simpson's 1/3 Rule c program code (1)
- Simpson's Simpsons' 3/8 rule c program code (1)
- Trapezoidal Rule C program code (1)
0 comments:
Post a Comment