![]() |
TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Solve the equation \(f(x)=0\) using bisection method More...
#include <cmath>#include <iostream>#include <limits>Go to the source code of this file.
Macros | |
| #define | EPSILON 1e-6 |
| #define | MAX_ITERATIONS 50000 |
| Maximum number of iterations to check. | |
Functions | |
| static double | eq (double i) |
| template<typename T> | |
| int | sgn (T val) |
| int | main () |
Solve the equation \(f(x)=0\) using bisection method
Given two points \(a\) and \(b\) such that \(f(a)<0\) and \(f(b)>0\), then the \((i+1)^\text{th}\) approximation is given by:
\[x_{i+1} = \frac{a_i+b_i}{2} \]
For the next iteration, the interval is selected as: \([a,x]\) if \(x>0\) or \([x,b]\) if \(x<0\). The Process is continued till a close enough approximation is achieved.
Definition in file bisection_method.cpp.
| #define EPSILON 1e-6 |
Definition at line 20 of file bisection_method.cpp.
| #define MAX_ITERATIONS 50000 |
Maximum number of iterations to check.
Definition at line 22 of file bisection_method.cpp.
|
static |
define \(f(x)\) to find root for
Definition at line 26 of file bisection_method.cpp.
| int main | ( | void | ) |
main function
Definition at line 37 of file bisection_method.cpp.
| int sgn | ( | T | val | ) |
get the sign of any given number
Definition at line 32 of file bisection_method.cpp.