f (a)*f (b)<0
then there is at least one real riot in the interval between a and b.
Its strategy is to begin with two values of x say a and b that bisects the root of f (x)=0. This method treats the interval distance between the initial values as line segments and then successively divides the interval in half and replace the one end point with the midpoint so that the root is again bracketed.
ALGORITHM:
Start
Define function f (x) and stopping criteria E.
Decide initial values of x as a and b.
Compute f (a) and f (b).
If f (a)*f (b)>0 then a and b does not converge and root does not lies between a and b. Go to step 10. Otherwise continue.
If `f (x_1)<0` then set `a=x_1` and `b=x_2` otherwise set `a=x_2` and `b=x_1`
Calculate `c=(a+b)/2` and f (c).
if `f(c)> 0` set `b=c` else set `a=c`.
Repeat step 8 until the absolute value of `abs ((b-a)/a)
Stop.
C-PROGRAM:
//Bisection Method
#include
#include
#include
#define f(x) cos(x) - x * exp(x)
void main()
{
float x0, x1, x2, f0, f1, f2, e;
int step = 1;
clrscr();
up:
printf("\nEnter two initial guesses:\n");
scanf("%f%f", &x0, &x1);
printf("Enter tolerable error:\n");
scanf("%f", &e);
f0 = f(x0);
f1 = f(x1);
if( f0 * f1 > 0.0)
{
printf("Incorrect Initial Guesses.\n");
goto up;
}
printf("\nStep\t\tx0\t\tx1\t\tx2\t\tf(x2)\n");
do
{
x2 = (x0 + x1)/2;
f2 = f(x2);
printf("%d\t\t%f\t%f\t%f\t%f\n",step, x0, x1, x2, f2);
if( f0 * f2 < 0)
{
x1 = x2;
f1 = f2;
}
else
{
x0 = x2;
f0 = f2;
}
step = step + 1;
}while(fabs(f2)>e);
printf("\nRoot is: %f", x2);
getch();
}
CONCLUSION:
Thus the roots of the given non linear equation was found out using Bisection method.