forked from TheAlgorithms/Python
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintersection.py
More file actions
Latest commit
17 lines (14 loc) · 469 Bytes
/
Copy pathintersection.py
File metadata and controls
17 lines (14 loc) · 469 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
importmath
defintersection(function,x0,x1): #function is the f we want to find its root and x0 and x1 are two random starting points
x_n=x0
x_n1=x1
whileTrue:
x_n2=x_n1-(function(x_n1)/((function(x_n1)-function(x_n))/(x_n1-x_n)))
ifabs(x_n2-x_n1) <10**-5:
returnx_n2
x_n=x_n1
x_n1=x_n2
deff(x):
returnmath.pow(x , 3) - (2*x) -5
if__name__=="__main__":
print(intersection(f,3,3.5))