|
Algorithms_in_C++
1.0.0
Set of algorithms implemented in C++.
|
Solve the equation \(f(x)=0\) using false position method, also known as the Secant method. More...
#include <cmath>#include <cstdlib>#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 false position method, also known as the Secant 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\cdot f(b_i) - b_i\cdot f(a_i)}{f(b_i) - f(a_i)} \]
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.
|
static |
define \(f(x)\) to find root for
| int main | ( | ) |
main function