MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / secant_method

Function secant_method

maths/numerical_analysis/secant_method.py:17–26  ·  view source on GitHub ↗

>>> secant_method(1, 3, 2) 0.2139409276214589

(lower_bound: float, upper_bound: float, repeats: int)

Source from the content-addressed store, hash-verified

15
16
17def secant_method(lower_bound: float, upper_bound: float, repeats: int) -> float:
18 """
19 >>> secant_method(1, 3, 2)
20 0.2139409276214589
21 """
22 x0 = lower_bound
23 x1 = upper_bound
24 for _ in range(repeats):
25 x0, x1 = x1, x1 - (f(x1) * (x1 - x0)) / (f(x1) - f(x0))
26 return x1
27
28
29if __name__ == "__main__":

Callers 1

secant_method.pyFile · 0.85

Calls 1

fFunction · 0.70

Tested by

no test coverage detected