mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-28 07:21:07 +00:00
122cf4536d
Removing requirement of math library to make code faster
16 lines
336 B
Python
16 lines
336 B
Python
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 (x**3)-2*x-5
|
|
|
|
def f1(x):
|
|
return 3*(x**2)-2
|
|
|
|
print(newton(f,f1,3))
|