TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Solve the equation \(f(x)=0\) using false position method, also known as the Secant method. More...
#include <cmath>
#include <iostream>
Go to the source code of this file.
Namespaces | |
namespace | numerical_methods |
for assert | |
namespace | false_position |
Functions for [False Position] (https://en.wikipedia.org/wiki/Regula_falsi) method. | |
Functions | |
static float | numerical_methods::false_position::eq (float x) |
This function gives the value of f(x) for given x. | |
static float | numerical_methods::false_position::regula_falsi (float x1, float x2, float y1, float y2) |
This function finds root of the equation in given interval i.e. (x1,x2). | |
void | numerical_methods::false_position::printRoot (float root, const int16_t &count) |
This function prints roots of the equation. | |
int | main () |
Main function. | |
Solve the equation \(f(x)=0\) using false position method, also known as the Secant method.
First, multiple intervals are selected with the interval gap provided. Separate recursive function called for every root. Roots are printed Separatelt.
For an interval [a,b] \(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.
Definition in file false_position.cpp.
|
static |
This function gives the value of f(x) for given x.
x | value for which we have to find value of f(x). |
Definition at line 44 of file false_position.cpp.
int main | ( | void | ) |
Main function.
Definition at line 102 of file false_position.cpp.
void numerical_methods::false_position::printRoot | ( | float | root, |
const int16_t & | count ) |
This function prints roots of the equation.
root | which we have to print. |
count | which is count of the root in an interval [-range,range]. |
Definition at line 84 of file false_position.cpp.
|
static |
This function finds root of the equation in given interval i.e. (x1,x2).
x1,x2 | values for an interval in which root is present. |
y1,y2 | values of function at x1, x2 espectively. |
Definition at line 55 of file false_position.cpp.