Bisection Method is repeated application of Intermediate Value Property. In intermediate value property, an interval (a,b) is chosen such that one of f(a) and f(b) is positive and the other is negative. Since the line joining both these points on a graph of x vs f(x), must pass through a point, such that f(x)=0. We have to find this x.
In Bisection Method, we keep on decreasing the interval till we find the value of x where f(x)=o.
#include<stdio.h> #include<conio.h> #include<math.h> //bisection method to solve the equation x^4-x-10=0// float f(float x) { return(pow(x,4)-pow(x,1)-10); } void main() { float x,x1,a,b,err=0.00005; //err is the max error allowed int i=1,n; clrscr(); printf("enter the values of a,b and maximum iterations\n"); scanf("%f%f%d",&a,&b,&n); x=(a+b)/2; printf("iteration no. %d x=%10.5f\n",i,x); i++; while(i<n) { if(f(a)*f(x)<0) //checking for the signs b=x; //new interval (a,x)// else a=x; //new interval (x,b)// x=(a+b)/2; printf("iteration no. %d x=%10.5f\n",i,x); if(fabs(x1-x)<err) { printf("\nafter %d iterations, the value of root is %f\n",i,x); break; } x1=x; i++; } if(i>=n) { printf("\nsolution does not exist as iterations are not sufficient"); } getch(); }
rt bvfg
in the deep south of Georgia when I was a child, spanish rice was rice cooked in tomatoes instead of water. the rice was red not white.loved your story of Mu9#3y&phr;s Visit and he visits us on a regular basis and his motto is my motto. great post