We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3ada8bb commit f8a30b4Copy full SHA for f8a30b4
arithmetic_analysis/secant_method.py
@@ -0,0 +1,28 @@
1
+# Implementing Secant method in Python
2
+# Author: dimgrichr
3
+
4
5
+from math import exp
6
7
8
+def f(x):
9
+ """
10
+ >>> f(5)
11
+ 39.98652410600183
12
13
+ return 8 * x - 2 * exp(-x)
14
15
16
+def SecantMethod(lower_bound, upper_bound, repeats):
17
18
+ >>> SecantMethod(1, 3, 2)
19
+ 0.2139409276214589
20
21
+ x0 = lower_bound
22
+ x1 = upper_bound
23
+ for i in range(0, repeats):
24
+ x0, x1 = x1, x1 - (f(x1) * (x1 - x0)) / (f(x1) - f(x0))
25
+ return x1
26
27
28
+print(f"The solution is: {SecantMethod(1, 3, 2)}")
0 commit comments