In numerical analysis, a root-finding algorithm is an algorithm for finding zeros, also called "roots", of continuous functions. A zero of a function
Most numerical root-finding methods use iteration, producing a sequence of numbers that hopefully converges towards the root as its limit. They require one or more initial guesses of the root as starting values, then each iteration of the algorithm produces a successively more accurate approximation to the root. Since the iteration must be stopped at some point, these methods produce an approximation to the root, not an exact solution.
This library includes the following root-finding algorithms,
- Bisection method
- False position method (Regula-falsi method)
- Secant method
- Generalized secant method
- Muller method
- Newton-Raphson method
- Ridder method
- Sidi method
- Steffensen method
- Calculate
$c$ , the midpoint of the given interval,$c = \dfrac{a+b}{2}$ . - Calculate the funciton value at midpoint,
$f(c)$ . - If
$f(c) = 0$ or$\dfrac{b-a}{2} < \epsilon$ , return$c$ as root. - If
$f(c) < 0$ ,$a = c$ else$b = c$ , repeat.
The root of a given function
The iterative procedure is as follows,
- Initialize the intervals
$[a, b]$ such that$f(a)\cdot f(b) < 0$ - Repeat
- Estimate
$c$ via the formula above, - If
$f(c) = 0$ or$\dfrac{b-a}{2} < \epsilon$ , then$c$ is the root. - Otherwise, if
$f(a)\cdot f(c) < 0$ , set$b = c$ , else set$a = c$ .
- Estimate
The iterative procedure is as follows,
Repeat
- Estimate
$x_{n+1}$ via the formula above, - Set,
$x_{n-1} = x_n$ and$x_n = x_{n+1}$ . - If
$f(x_{n+1}) = 0$ or$f(x_{n+1}) < \epsilon$ ,$x_{n+1}$ is the root.
Note
The secant method can also be written in terms of divided differnece
The Sidi's method is the generalization of the secand method, and can be iteratively performed as follows,
Repeat,
- Calculate
$x_{n+1}$ using the secand method, - Calculate
$f(x_{n+1})$ , and divided differences at$x_{n-1}$ ,$x_n$ ,$x_{n+1}$ , - Calculate
$$x_{n+2} = x_{n+1} - \frac{f(x_{n+1})}{f[x_{n+1}, x_{n-1}] + (x_{n+1} - x_n)f[x_{n+1}, x_n, x_{n-1}]}$$ - Set
$x_{n-1} = x_n$ ,$x_n = x_{n+1}$ , and$x_{n+1} = x_{n+2}$ - if
$f[x_{n+1}, x_{n-1}] + f[x_{n+1}, x_n, x_{n-1}] < \epsilon$ , return$x_{n+2}$ as root.
Repeat,
- Calculate
$x_\text{mid} = \dfrac{x_n + x_{n+1}}{2}$ - Calculate, $$ X = \dfrac{(x_\text{mid} - x_n) f(x_\text{mid})}{\sqrt{f(x_\text{mid})^2 - f(x_n)f(x_{n+1})}} $$
- Evaluate
$$x_\text{new} = x_\text{mid} + \text{sign}\left[f(x_n), f(x_{n+1})\right]X$$ - If,
$f(x_\text{new}) = 0$ or$\sqrt{f(x_\text{mid})^2 - f(x_n)f(x_{n+1})} = 0$ return$x_\text{new}$ as the root. - Otherwise,
- If
$f(x_\text{mid})f(x_\text{new}) < 0$ , set$x_{n} = x_\text{mid}$ and$x_{n+1} = x_\text{new}$ - Else set
$x_n = x_\text{new}$
- If
Note
The Steffensen method is implemented in this library via two methods,
- Root between two points
- Root from initial guess
- Take two points
$[a, b]$ such that,$a < b$ and$f(a)\cdot f(b) < 0$ - Repeat,
- Calculate
$x_0 = \dfrac{a+b}{2}$ , - Calculate
$f(x_0)$ and$f(x_0 + f(x_0))$ , and calculate$x_1$ using the above formula - If
$f(x_1) = 0$ than$x_1$ is an exact root, else$x_0 = x_1$ .
- Calculate