Professional Documents
Culture Documents
1
Bisection Method
1.1 Objective: To find the root of the non-linear equation by Bisection Method using C/C++
1.2 Theory: The simplest root-finding algorithm is the bisection method. The algorithm
applies to any continuous function f(x) on an interval [a,b] where the value of the function f(x)
changes sign from a to b. The idea is simple: divide the interval in two, a solution must exist
within one subinterval, select the subinterval where the sign of f(x) changes and repeat.
1.3 Procedure/Code:
#include<iostream>
using namespace std;
#define EP 0.01
double func(double x)
{
return x*x*x - 2*x - 5;
}
double c = a;
while ((b-a) >= EP)
{
// Find middle point
c = (a+b)/2;
cout << "The value of root after "<< i++ <<" is : " << c << endl;
}
}
int main()
{
double a = 0;
double b = 0;
bisection(a, b);
cout << endl;
cout << "\nAditya Sarawat \nECE-A \n31\n";
return 0;
}
1.4 Result: