The inverse quadratic interpolation of Brent’s Method is the second of a two-part process which when combined, is Brent’s Method of finding roots.

This method converges faster than the linear one when the approximations are “near” the actual root, but is slow to converge when they are “far away” from the root.

**Explanation**

Typically, higher degree polynomials tend to provide better estimates, when looking at the error associated with the secant method. However, polynomials of 3rd degree or higher are too expensive to reasonably compute. Thus, quadratics are used as they provide a suitable balance between complexity and efficiency in finding roots.

Nevetheless, standard quadratics in the form are not used because they have minimum or maximum turning points and thus may not have a real root. This prevents them from converging towards the root of the function we are finding.

Instead, an inverse quadratic in the form is preferred, constructed using Lagrange Polynomials. As inverse quadratics are guaranteed to intersect the x-axis, there will always be a solution for y=0.

**Worked Example**

In the image below, the graph of in red is also used in the previous topics on linear interpolation and the bisection method. The graph in green is the inverse quadratic derived from the points and while its formula is

Note that only after 1 iteration, the approximated root (, as highlighted by the green graph) is extremely close to the actual root (). This is due to the ability of quadratics to more closely approximate the shape of non-linear functions due to their curvature.

**Efficiency**

Iteration | x | y |

– | 4.5 | -0.8108634509984304 |

– | 2.5 | 0.8984721441039565 |

– | 3.5 | -0.13649751340390556 |

1 | 3.3310456395302936 | 0.03683282875913396 |

2 | 3.366898729297604 | -0.0006477897671345878 |

3 | 3.36627587617705 | 5.806422448406678e-07 |

As evident from the above, quadratics are extremely efficient in converging to the root. Even after just 2 iterations, the approximation was accurate to 3 significant figures.

**The math**

Lagrange polynomials come in the form:

where is the number of points used to define the function.

Just like how defining a straight line requires 2 distinct points, defining a quadratic requires 3 distinct points.

**Lagrange Basis Functions**

Each lagrange polynomial of degree is made up of basis functions in the form:

We therefore need a second degree Lagrange polynomial using three basis functions – – one for each of the points.

Combining all of the basis functions into the main lagrange function as outlined above, we get:

**Complete Derivation**

Since we are calculating the inverted quadratic function, , we need to swap the variables x and y.

Furthermore, since we’re only interested in the value of x at a specific point , we can substitute y=0 into the function.

Since is an approximation for the value of x at the root, we can use that value to modify L to get an even closer estimate. More generally, the lagrange polynomial can be rewritten as:

Brent’s Method combines all three algorithms – bisection, linear secant interpolation and inverse quadratic interpolation – using a process that chooses which method to use at which stage.

Just like the aforementioned methods, we need to start with a bracketing interval that contains root such that . We assume that , otherwise, the labeling is switched.

Each iteration has four points, one derived value and one pre-defined constant:

- : alignment points that satisfy and
- : root estimate of the current iteration
- : root estimate of the previous iteration; initialised as
- : root estimate of the second-last iteration
- : an intermediate derived value in this iteration. it is given by linear interpolation if , otherwise it is given by the midpoint between and .
- 𝜀: a pre-specified precision tolerance for convergence

Next, four inequalities are used to decide which method is used:

If any one of the below 5 conditions hold true, the bisection method is used. Otherwise, interpolation is used.

- last iteration uses the bisection method and inequality 1 is false
- last iteration uses the interpolation method and inequality 2 is false
- last iteration uses the bisection method and inequality 3 is false
- last iteration uses the interpolation method and inequality 4 is false
- the temporary value, , calculated by interpolation is not in

The method of interpolation depends on the number of distinct points. If all three points are distinct, quadratic interpolation is used, otherwise linear interpolation.

**Explanation**

The pre-specified tolerance value was implemented by Brent in 1973 as there were certain cases where linear interpolation was performed for every iteration, resulting in a very slow convergence to the root. Adding this extra step of comparing results ensured that the optimal algorithm for each iteration was used.

**Implementation**

In NM Dev, the class BrentRoot implements the Brent’s method. It is a two-step procedure: solver construction and then call the solve function. The signatures of the functions are:

` ````
```**
* Construct an instance of Brent's root finding algorithm.
*
* @param tol the convergence tolerance
* @param maxIterations the maximum number of iterations
*/
public BrentRoot(double tol, int maxIterations)
/**
* Search for a root, *x*, in the interval *[lower, upper]* such
* that *f(x) = 0*.
*
* @param f a univariate function
* @param lower the lower bound of the bracketing interval
* @param upper the upper bound of the bracketing interval
* @param guess an initial guess of the root within *[lower, upper]*.
* Note that {@code guess} is a {@code double[]}.
* This signature allows multiple initial guesses for certain
types of
* uniroot algorithms, e.g., Brent's algorithm.
* @return an approximate root
* @throws NoRootFoundException when the search fails to find a root
*/
public double solve(
UnivariateRealFunction f,
double lower,
double upper,
double... guess
) throws NoRootFoundException;

Here is an example of calling BrentRoot to solve the function in the previous topics, :

` ````
```UnivariateRealFunction f = new AbstractUnivariateRealFunction(){
@Override
public double evaluate(double x) {
return Math.sin(x) + 3/(4*x); // x^2 - 3 = 0
}
};
BrentRoot solver = new BrentRoot(1e-8, 10);
double root = solver.solve(f, 2.5, 4.5);
double fx = f.evaluate(root);
System.out.println(String.format("f(%f) = %f", root, fx));