Bisection method
C++ Algorithms
numeric method, while
Flowchart (ISO 5807)
Source code
double f(double x) {
return x * x - 2;
}
double bisection(double a, double b, double eps) {
double m;
while (b - a > eps) {
m = (a + b) / 2;
if (f(a) * f(m) < 0) {
b = m;
} else {
a = m;
}
}
return (a + b) / 2;
}