Skip to content

Instantly share code, notes, and snippets.

@hamzaavvan
Created October 6, 2019 09:46
Show Gist options
  • Save hamzaavvan/b0f02856718d84fd7bb5bc07dec1d218 to your computer and use it in GitHub Desktop.
Save hamzaavvan/b0f02856718d84fd7bb5bc07dec1d218 to your computer and use it in GitHub Desktop.
Python - Newton Method Code
import sympy as sp
from scipy.misc import derivative
x = sp.Symbol('x')
# y = sp.diff(3*x**2+1, x)
# print (y)
x = float(input("Enter x: "))
def f(x):
return x**4-x-10
def new(x, tol=1e-5):
while True:
xnew = x-(f(x)/(derivative(f,x)) )
print(xnew)
if abs(xnew-x) < tol:
break
x=xnew
new(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment