Add files via upload

There are three methods that find approximately the roots of a non-linear function
This commit is contained in:
MindTraper
2017-12-17 22:02:36 +02:00
committed by GitHub
parent 7f87515836
commit 24bad2e273
3 changed files with 66 additions and 0 deletions

16
Intersection.py Normal file
View 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))