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 collections .abc import Callable
22
3+
34def 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+
8688if __name__ == "__main__" :
8789 from doctest import testmod
90+
8891 testmod ()
You can’t perform that action at this time.
0 commit comments