Skip to content

Commit 0aeb7f7

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 56d6f97 commit 0aeb7f7

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

maths/numerical_analysis/brents_method.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from collections.abc import Callable
22

3+
34
def brent_method(
45
f: Callable[[float], float],
56
a: float,
67
b: float,
78
tol: float = 1e-14,
8-
max_iter: int = 100
9+
max_iter: int = 100,
910
) -> float:
1011
"""
1112
Root finding using Brent's method.
@@ -42,9 +43,9 @@ def brent_method(
4243
if fa != fc and fb != fc:
4344
# Inverse quadratic interpolation
4445
s = (
45-
a * fb * fc / ((fa - fb) * (fa - fc)) +
46-
b * fa * fc / ((fb - fa) * (fb - fc)) +
47-
c * fa * fb / ((fc - fa) * (fc - fb))
46+
a * fb * fc / ((fa - fb) * (fa - fc))
47+
+ b * fa * fc / ((fb - fa) * (fb - fc))
48+
+ c * fa * fb / ((fc - fa) * (fc - fb))
4849
)
4950
else:
5051
# Secant method
@@ -83,6 +84,8 @@ def brent_method(
8384

8485
return b
8586

87+
8688
if __name__ == "__main__":
8789
from doctest import testmod
90+
8891
testmod()

0 commit comments

Comments
 (0)