# Brent-Dekker Method as a Root Finding Method of Any Equation

by admin in Math, Statistics, and Optimization , MATLAB Family , Roots of Equation on June 13, 2019Chandrupatla’s method is a variant which is simpler and converges faster for functions that are flat around their roots (which means they have multiple roots or closely-located roots).^{[3]}^{[4]}

### Contents

- Dekker’s method
- Brent’s method
- Algorithm
- Example
- Implementations
- References
- Further reading
- External links

### Dekker’s Method

The idea to combine the bisection method with the secant method goes back to Dekker (1969). Suppose that we want to solve the equation ** f(x) = 0**. As with the bisection method, we need to initialize Dekker’s method with two points, say

**and**

*a*_{0}**, such that**

*b*_{0}**and**

*f*(*a*_{0})**have opposite signs. If**

*f*(*b*_{0})**is continuous on**

*f***[**, the intermediate value theorem guarantees the existence of a solution between

*a*_{0},*b*_{0}]**and**

*a*_{0}**.**

*b*_{0}Three points are involved in every iteration:

is the current iterate, i.e., the current guess for the root of*b*_{k}*f*.is the “contrapoint,” i.e., a point such that*a*_{k}and*f*(*a*_{k})have opposite signs, so the interval*f*(*b*_{k})**[**contains the solution. Furthermore,*a*_{k},*b*_{k}]**|**should be less than or equal to*f*(*b*_{k})|**|**, so that*f*(*a*_{k})|is a better guess for the unknown solution than*b*_{k}.*a*_{k}is the previous iterate (for the first iteration, we set*b*_{k−1}).*b*_{k−1}=*a*_{0}

Two provisional values for the next iterate are computed. The first one is given by linear interpolation, also known as the secant method:

and the second one is given by the bisection method

If the result of the secant method, *s*, lies strictly between *b*_{k} and *m*, then it becomes the next iterate (** b_{k+1} = s**), otherwise the midpoint is used (

**).**

*b*_{k+1}=*m*Then, the value of the new contrapoint is chosen such that ** f(a_{k+1})** and

**have opposite signs. If**

*f*(*b*_{k+1})**and**

*f*(*a*_{k})**have opposite signs, then the contrapoint remains the same:**

*f*(*b*_{k+1})**. Otherwise,**

*a*_{k+1}=*a*_{k}**and**

*f*(*b*_{k+1})**have opposite signs, so the new contrapoint becomes**

*f*(*b*_{k})**.**

*a*_{k+1}=*b*_{k}Finally, if **| f(a_{k+1})| < |f(b_{k+1})|**, then

**is probably a better guess for the solution than**

*a*_{k+1}*b*

_{k+1}, and hence the values of

**and**

*a*_{k+1}**are exchanged.**

*b*_{k+1}This ends the description of a single iteration of Dekker’s method.

Dekker’s method performs well if the function ** f **is reasonably well-behaved. However, there are circumstances in which every iteration employs the secant method, but the iterates

**converge very slowly (in particular,**

*b*_{k}**|**may be arbitrarily small). Dekker’s method requires far more iterations than the bisection method in this case.

*b*_{k}−*b*_{k−1}|### Brent’s Method

Brent (1973) proposed a small modification to avoid this problem. He inserted an additional test which must be satisfied before the result of the secant method is accepted as the next iterate. Two inequalities must be simultaneously satisfied: Given a specific numerical tolerance **delta**, if the previous step used the bisection method, the inequality

must hold to perform interpolation, otherwise the bisection method is performed and its result used for the next iteration. If the previous step performed interpolation, then the inequality

is used instead to perform the next action (to choose) interpolation (when inequality is true) or bisection method (when inequality is not true). Also, if the previous step used the bisection method, the inequality

must hold, otherwise the bisection method is performed and its result used for the next iteration. If the previous step performed interpolation, then the inequality

is used instead.

This modification ensures that at the **kth** iteration, a bisection step will be performed in at most **2.log2(|b(k-1) – b(k-2)| / delta)** additional iterations, because the above conditions force consecutive interpolation step sizes to halve every two iterations, and after at most **2.log2(|b(k-1) – b(k-2)| / delta)** iterations, the step size will be smaller than **delta**, which invokes a bisection step. Brent proved that his method requires at most ** N^{2} **iterations, where

**denotes the number of iterations for the bisection method. If the function**

*N**f*is well-behaved, then Brent’s method will usually proceed by either inverse quadratic or linear interpolation, in which case it will converge superlinearly.

Furthermore, Brent’s method uses inverse quadratic interpolation instead of linear interpolation (as used by the secant method). If ** f(b_{k}), f(a_{k})** and

**are distinct, it slightly increases the efficiency. As a consequence, the condition for accepting**

*f*(*b*_{k−1})*s*(the value proposed by either linear interpolation or inverse quadratic interpolation) has to be changed:

*s*has to lie between

**(3**and

*a*_{k}+*b*_{k}) / 4**.**

*b*_{k}### Algorithm

inputa,b, and (a pointer to) a function forfcalculatef(a) calculatef(b)iff(a)f(b) ≥ 0thenexit function because the root is not bracketed.end ifif|f(a)| < |f(b)|thenswap (a,b)end ifc:=asetmflagrepeat untilf(bors) = 0or|b−a|issmall enough(convergence)iff(a) ≠f(c)andf(b) ≠f(c)then(inverse quadratic interpolation)else(secant method)end ifif(condition 1)sis notbetween (3a+b)/4 andbor(condition 2)(mflagissetand|s−b| ≥ |b−c|/2)or(condition 3)(mflagisclearedand|s−b| ≥ |c−d|/2)or(condition 4)(mflagissetand|b−c| < |δ|)or(condition 5)(mflagisclearedand|c−d| < |δ|)then(bisection method)setmflagelseclearmflagend ifcalculatef(s)d:=c(d is assigned for the first time here; it won't be used above on the first iteration because mflag is set)c:=biff(a)f(s) < 0thenb:=selsea:=send ifif|f(a)| < |f(b)|thenswap (a,b)end ifend repeatoutputbor s (return the root)

### Example

Suppose that we are seeking a zero of the function defined by ** f(x) = (x + 3)(x − 1)^{2}**.

We take **[ a_{0}, b_{0}] = [−4, 4/3]** as our initial interval.

We have ** f(a_{0}) = −25 and f(b_{0}) = 0.48148** (all numbers in this section are rounded), so the conditions

*f*(*a*_{0})*f*(*b*_{0})**< 0**and

**|**are satisfied.

*f*(*b*_{0})| ≤ |*f*(*a*_{0})|- In the first iteration, we use linear interpolation between
**(**and*b*_{−1},*f*(*b*_{−1})) = (*a*_{0},*f*(*a*_{0})) = (−4, −25)**(**, which yields*b*_{0},*f*(*b*_{0})) = (1.33333, 0.48148). This lies between*s*= 1.23256**(3**and*a*_{0}+*b*_{0}) / 4, so this value is accepted. Furthermore,*b*_{0}*f*(1.23256) = 0.22891and*a*_{1}=*a*_{0}.*b*_{1}=*s*= 1.23256 - In the second iteration, we use inverse quadratic interpolation between
**(**and*a*_{1},*f*(*a*_{1})) = (−4, −25)**(**and*b*_{0},*f*(*b*_{0})) = (1.33333, 0.48148)**(**. This yields*b*_{1},*f*(*b*_{1})) = (1.23256, 0.22891)**1.14205**, which lies between**(3**and*a*_{1}+*b*_{1}) / 4. Furthermore, the inequality*b*_{1}**|1.14205 −**is satisfied, so this value is accepted. Furthermore,*b*_{1}| ≤ |*b*_{0}−*b*_{−1}| / 2, so we set*f*(1.14205) = 0.083582and*a*_{2}=*a*_{1}.*b*_{2}= 1.14205 - In the third iteration, we use inverse quadratic interpolation between
**(**and*a*_{2},*f*(*a*_{2})) = (−4, −25)**(**and*b*_{1},*f*(*b*_{1})) = (1.23256, 0.22891)**(**. This yields*b*_{2},*f*(*b*_{2})) = (1.14205, 0.083582)**1.09032**, which lies between**(3**and*a*_{2}+*b*_{2}) / 4. But here Brent’s additional condition kicks in: the inequality*b*_{2}**|1.09032 −**is not satisfied, so this value is rejected. Instead, the midpoint*b*_{2}| ≤ |*b*_{1}−*b*_{0}| / 2of the interval*m*= −1.42897**[**is computed. We have*a*_{2},*b*_{2}]*f*(*m*) = 9.26891and*a*_{3}=*a*_{2}.*b*_{3}= −1.42897 - In the fourth iteration, we use inverse quadratic interpolation between
**(**and*a*_{3},*f*(*a*_{3})) = (−4, −25)**(**and*b*_{2},*f*(*b*_{2})) = (1.14205, 0.083582)**(**. This yields*b*_{3},*f*(*b*_{3})) = (−1.42897, 9.26891)**1.15448**, which is not in the interval between**(3**. Hence, it is replaced by the midpoint*a*_{3}+*b*_{3}) / 4 and*b*_{3}). We have*m*= −2.71449, so we set*f*(*m*) = 3.93934and*a*_{4}=*a*_{3}*b*_{4}= −2.71449. - In the fifth iteration, inverse quadratic interpolation yields
**−3.45500**, which lies in the required interval. However, the previous iteration was a bisection step, so the inequality**|−3.45500 −**need to be satisfied. This inequality is false, so we use the midpoint*b*_{4}| ≤ |*b*_{4}−*b*_{3}| / 2. We have*m*= −3.35724, so*f*(*m*) = −6.78239becomes the new contrapoint (*m*) and the iterate remains the same (*a*_{5}= −3.35724).*b*_{5}=*b*_{4} - In the sixth iteration, we cannot use inverse quadratic interpolation because
*b*_{5}=*b*_{4}. Hence, we use linear interpolation between**(**and*a*_{5},*f*(*a*_{5})) = (−3.35724, −6.78239)**(**. The result is*b*_{5},*f*(*b*_{5})) = (−2.71449, 3.93934), which satisfies all the conditions. But since the iterate did not change in the previous step, we reject this result and fall back to bisection. We update*s*= −2.95064, and*s*= -3.03587.*f*(*s*) = -0.58418 - In the seventh iteration, we can again use inverse quadratic interpolation. The result is
, which satisfies all the conditions. Now,*s*= −3.00219, so we set*f*(*s*) = −0.03515and*a*_{7}=*b*_{6}(*b*_{7}= −3.00219and*a*_{7}are exchanged so that the condition*b*_{7}**|**is satisfied). (*f*(*b*_{7})| ≤ |*f*(*a*_{7})|*Correct*: linear interpolation**s = -2.99436,f(s) = 0.089961)** - In the eighth iteration, we cannot use inverse quadratic interpolation because
. Linear interpolation yields*a*_{7}=*b*_{6}, which is accepted. (*s*= −2.99994*Correct*:**s = -2.9999, f(s) = 0.0016**) - In the following iterations, the root
is approached rapidly:*x*= −3and*b*_{9}= −3 + 6·10^{−8}. (*b*_{10}= −3 − 3·10^{−15}*Correct*:**Iter 9 :**,*f*(*s*) = -1.4E-07**Iter 10 :**)*f*(*s*) = 6.96E-12

### Implementations

- Brent (1973) published an Algol 60 implementation.
- Netlib contains a Fortran translation of this implementation with slight modifications.
- The PARI/GP method
`solve`implements the method. - Other implementations of the algorithm (in C++, C, and Fortran) can be found in the Numerical Recipes books.
- The Apache Commons Math library implements the algorithm in Java.
- The SciPy optimize module implements the algorithm in Python (programming language)
- The Modelica Standard Library implements the algorithm in Modelica.
- The
`uniroot`function implements the algorithm in R (software). - The Boost (C++ libraries) implements two algorithms based on Brent’s method in C++ in the Math toolkit:

- Function minimization at minima.hpp with an example locating function minima.
- Root finding implements the newer TOMS748, a more modern and efficient algorithm than Brent’s original, at TOMS748, and Boost.Math rooting finding that uses TOMS748 internally with examples.

- The Optim.jl package implements the algorithm in Julia (programming language)

### References

- Brent, R. P. (1973), “Chapter 4: An Algorithm with Guaranteed Convergence for Finding a Zero of a Function”,
*Algorithms for Minimization without Derivatives*, Englewood Cliffs, NJ: Prentice-Hall, ISBN 0-13-022335-2 - Dekker, T. J. (1969), “Finding a zero by means of successive linear interpolation”, in Dejon, B.; Henrici, P. (eds.),
*Constructive Aspects of the Fundamental Theorem of Algebra*, London: Wiley-Interscience, ISBN 978-0-471-20300-1

### Related Reading

- Atkinson, Kendall E. (1989). “Section 2.8.”.
*An Introduction to Numerical Analysis*(2nd ed.). John Wiley and Sons. ISBN 0-471-50023-2. - Press, W. H.; Teukolsky, S. A.; Vetterling, W. T.; Flannery, B. P. (2007). “Section 9.3. Van Wijngaarden–Dekker–Brent Method”.
*Numerical Recipes: The Art of Scientific Computing*(3rd ed.). New York: Cambridge University Press. ISBN 978-0-521-88068-8. - Alefeld, G. E.; Potra, F. A.; Shi, Yixun (September 1995). “Algorithm 748: Enclosing Zeros of Continuous Functions”.
*Transactions on Mathematical Software*.**21**(3): 327–344. doi:10.1145/210089.210111.

### External Links

- zeroin.f at Netlib.
- module brent in C++ (also C, Fortran, Matlab) by John Burkardt
- GSL implementation.
- Boost C++ implementation.
- Python (Scipy) implementation

Share Now!