Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
|
Solve the equation \(f(x)=0\) using bisection method More...
#include <cmath>
#include <iostream>
#include <limits>
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.
#define EPSILON 1e-6 |
|
static |
int main | ( | void | ) |
main function
int sgn | ( | T | val | ) |
get the sign of any given number