mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 01:09:40 +08:00
increment 1
This commit is contained in:
16
arithmetic_analysis/intersection.py
Normal file
16
arithmetic_analysis/intersection.py
Normal file
@ -0,0 +1,16 @@
|
||||
import math
|
||||
|
||||
def intersection(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
|
||||
while True:
|
||||
x_n2 = x_n1-(function(x_n1)/((function(x_n1)-function(x_n))/(x_n1-x_n)))
|
||||
if abs(x_n2 - x_n1)<0.00001 :
|
||||
return x_n2
|
||||
x_n=x_n1
|
||||
x_n1=x_n2
|
||||
|
||||
def f(x):
|
||||
return math.pow(x,3)-2*x-5
|
||||
|
||||
print(intersection(f,3,3.5))
|
Reference in New Issue
Block a user