Professional Documents
Culture Documents
Bisection
Bisection
Faculty of Engineering
Department of Computer Engineering
Numerical Analysis
Bisection Method
To find a root very accurately Bisection Method is used in Mathematics. Bisection
method algorithm is very easy to program and it always converges which means it
always finds root.
It is also called Interval halving, binary search method and dichotomy method.
Bisection Method calculates the root by first calculating the mid point of the given
interval end points.
Muataz Abdulsmad
Bisection Method Procedure:
The input for the method is a continuous function f, an interval [a, b], and the
function values f(a) and f(b). The function values are of opposite sign (there is at
least one zero crossing within the interval). Each iteration performs these steps:
4. Examine the sign of f(c) and replace either (a, f(a)) or (b, f(b)) with (c, f(c))
so that there is a zero crossing within the new interval.
#include<iostream>
using namespace std;
Muataz Abdulsmad
void bisection(double a,double b)
{
if(func(a) * func(b) >= 0)
{
cout<<"Incorrect a and b";
return;
}
c = a;
while ((b-a) >= e)
{
c = (a+b)/2;
if (func(c) == 0.0){
cout<<"Root = "<<c<<endl;
break;
}
else if (func(c)*func(a) < 0){
cout<<"Root
="<<c<<endl;
b = c;
}
else{
cout<<"Root ="<<c<<endl;
a = c;
}
}
}
Muataz Abdulsmad
int main()
{
double a,b;
a=-10;
b=20;
return 0;
}
Output :
a = -10.000000
b = 20.000000
Root = 5.000000
Root = -2.500000
Root = 1.250000
Root = -0.625000
Root = -1.562500
Root = -1.093750
Root = -0.859375
Root = -0.976563
Root = -1.035156
Root = -1.005859
Root = -0.991211
Root = -0.998535