maths.numerical_analysis.brent_method ===================================== .. py:module:: maths.numerical_analysis.brent_method Functions --------- .. autoapisummary:: maths.numerical_analysis.brent_method.brent_method Module Contents --------------- .. py:function:: brent_method(func: collections.abc.Callable[[float], float], left: float, right: float, tol: float = 1e-08, max_iter: int = 100) -> float Find the root of function func in the interval [left, right] using Brent's Method. Brent's Method combines bisection, secant, and inverse quadratic interpolation. Parameters ---------- func : Callable[[float], float] Function for which to find the root. left : float Left endpoint of interval. right : float Right endpoint of interval. tol : float Tolerance for convergence (default 1e-8). max_iter : int Maximum number of iterations (default 100). Returns ------- float Approximate root of func in [left, right]. Raises ------ ValueError If func(left) and func(right) do not have opposite signs. Examples -------- >>> def f(x): return x**3 - x - 2 >>> round(brent_method(f, 1, 2), 5) 1.52138 >>> def f2(x): return x**2 + 1 >>> brent_method(f2, 0, 1) Traceback (most recent call last): ... ValueError: func(left) and func(right) must have opposite signs