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

17
NeutonMethod.py Normal file
View File

@@ -0,0 +1,17 @@
import math
def newton(function,function1,startingInt): #function is the f(x) and function1 is the f'(x)
x_n=startingInt
while True:
x_n1=x_n-function(x_n)/function1(x_n)
if abs(x_n-x_n1)<0.00001:
return x_n1
x_n=x_n1
def f(x):
return math.pow(x,3)-2*x-5
def f1(x):
return 3*math.pow(x,2)-2
print(newton(f,f1,3))