Created
October 6, 2019 09:46
-
-
Save hamzaavvan/b0f02856718d84fd7bb5bc07dec1d218 to your computer and use it in GitHub Desktop.
Python - Newton Method Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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