File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11from typing import Callable
22
3+
34def brent_method (
45 f : Callable [[float ], float ],
56 a : float ,
67 b : float ,
78 tol : float = 1e-8 ,
8- max_iter : int = 100
9+ max_iter : int = 100 ,
910) -> float :
1011 """
1112 Find the root of function f in the interval [a, b] using Brent's Method.
12-
13+
1314 Brent's Method combines bisection, secant, and inverse quadratic interpolation.
14-
15+
1516 Parameters
1617 ----------
1718 f : Callable[[float], float]
@@ -24,17 +25,17 @@ def brent_method(
2425 Tolerance for convergence (default 1e-8).
2526 max_iter : int
2627 Maximum number of iterations (default 100).
27-
28+
2829 Returns
2930 -------
3031 float
3132 Approximate root of f in [a, b].
32-
33+
3334 Raises
3435 ------
3536 ValueError
3637 If f(a) and f(b) do not have opposite signs.
37-
38+
3839 Examples
3940 --------
4041 >>> def func(x): return x**3 - x - 2
@@ -109,7 +110,9 @@ def brent_method(
109110
110111 # If we reach max iterations
111112 return b
113+
114+
112115if __name__ == "__main__" :
113116 import doctest
114- doctest .testmod (verbose = True )
115117
118+ doctest .testmod (verbose = True )
You can’t perform that action at this time.
0 commit comments