>>> secant_method(1, 3, 2) 0.2139409276214589
(lower_bound: float, upper_bound: float, repeats: int)
| 15 | |
| 16 | |
| 17 | def 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 | |
| 29 | if __name__ == "__main__": |