Skip to content

Commit a14bceb

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 8489f90 commit a14bceb

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

maths/brent_method.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
from typing import Callable
22

3+
34
def 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+
112115
if __name__ == "__main__":
113116
import doctest
114-
doctest.testmod(verbose=True)
115117

118+
doctest.testmod(verbose=True)

0 commit comments

Comments
 (0)