Brent Method Implementation in Octave, Julia, and Mathematica
John Bryan
- Equations.
Inverse Quadrature Interpolation
\begin{equation}
s = \frac{af(b)f(c)}{(f(a)-f(b))(f(a)-f(c))}+
\frac{bf(a)f(c)}{(f(b)-f(a))(f(b)-f(c))}+
\frac{cf(a)f(b)}{(f(c)-f(a))(f(c)-f(b))}
\tag{eq. 1}
\end{equation}
Secant (linear interpolation)
\begin{equation}
s = b - \frac{f(b)(b-a)}{f(b)-f(a)}
\tag{eq. 2}
\end{equation}
Midpoint (bisection)
\begin{equation}
s = \frac{b+a}{2}
\tag{eq. 3}
\end{equation}
-
Octave implementation.
-
Julia implementation.
-
Mathematica implementation.
-
Results.
$$
\begin{array}{c|lcr}
(x+4)(x+1),\quad [-5,-3] & -4 \\ \qquad
\sin(x),\quad [3\pi/4,5\pi/4] & \pi
\end{array}
$$