Bisection Method

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();
}

kaliadevansh has written 15 articles

One thought on “Bisection Method

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>