(function,x0,x1)
| 1 | import math |
| 2 | |
| 3 | def intersection(function,x0,x1): #function is the f we want to find its root and x0 and x1 are two random starting points |
| 4 | x_n = x0 |
| 5 | x_n1 = x1 |
| 6 | while True: |
| 7 | x_n2 = x_n1-(function(x_n1)/((function(x_n1)-function(x_n))/(x_n1-x_n))) |
| 8 | if abs(x_n2 - x_n1) < 10**-5: |
| 9 | return x_n2 |
| 10 | x_n=x_n1 |
| 11 | x_n1=x_n2 |
| 12 | |
| 13 | def f(x): |
| 14 | return math.pow(x , 3) - (2 * x) -5 |