I have forgotten

COST (GBP)
2.98
0.00
0

# Falseposition

Calculates the zeros of a function using the Regula-Falsi method.
Controller: CodeCogs

C++

## Falseposition

 doublefalseposition( double (*f)(double)[function pointer] double x0 = -1E+7 double x1 = 1E+7 double eps = 1E-10 double maxit = 1000 )
The false position method, on contrast with Newton's method, in which the calculation of the derivative $\inline&space;f'(x_n)$ was required, replaces it with its approximation

$f'(x_n)&space;=&space;\frac&space;{f(x_n)&space;-&space;f(x_{n&space;-&space;1})}&space;{x_n&space;-&space;x_{n&space;-&space;1}}$

Given $\inline&space;x_0$ and $\inline&space;x_1$, the main algorithm is based on the following recurrence relation
$x_{n&space;+&space;1}&space;=&space;\frac&space;{x_n&space;f(x_{n&space;-&space;1})&space;-&space;x_{n&space;-&space;1}&space;f(x_n)}&space;{f(x_{n&space;-&space;1})&space;-&space;f(x_n)}&space;\qquad&space;n&space;\geq&space;1$

This method has rate of convergence $\inline&space;\frac&space;{1&space;+&space;\sqrt{5}}&space;{2}&space;\approx&space;1.618$, therefore inferior to the method of Newton. However it is more accurate than Newton because only one function evaluation is required, $\inline&space;f(x_n)$, $\inline&space;f(x_{n&space;-&space;1})$ being calculated in the previous iteration, while Newton requires two, $\inline&space;f(x_n)$ and $\inline&space;f'(x_n)$.

To give you a better idea on the way this method works, the following graph shows different iterations in the approximation process. Here is the associated list of pairs chosen at consecutive steps

$(a_0,&space;b_0)&space;\quad&space;(a_1,&space;b_0)&space;\quad&space;(a_2,&space;b_0)$

This algorithm finds the roots of the user-defined function f starting with an initial interval [x0, x1] and iterating the sequence above until either the accuracy eps is achieved or the maximum number of iterations maxit is exceeded.

## Example:

#include <codecogs/maths/rootfinding/falseposition.h>

#include <iostream>
#include <iomanip>
#include <cmath>

// user-defined function
double f(double x) {
return cos(x);
}

int main()
{
double x = Maths::RootFinding::falseposition(f, 1, 3);

std::cout << "The calculated zero is X = " << std::setprecision(12) << x << std::endl;
std::cout << "The associated ordinate value is Y = " << f(x) << std::endl;
return 0;
}
Output:
The calculated zero is X = 1.70614146372
The associated ordinate value is Y = -0.134932299622

## References:

• F.R. Ruckdeschel, "BASIC Scientific Subroutines", Vol. II, BYTE/McGRAWW-HILL, 1981

### Parameters

 f the user-defined function x0 Default value = -1E+7 x1 Default value = 1E+7 eps Default value = 1E-10 maxit Default value = 1000

### Authors

Lucian Bentea (August 2005)
##### Source Code

Source code is available when you buy a Commercial licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.