Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def f1(x):
- return x**3-(2.*x)-5.
- def derivative_f1(x):
- return (3*x**2)-2.
- def Newton(f, df, x, tol):
- while True:
- x1 = x - (f(x)/df(x)) # it was f(x) - (f(x)/df(x))
- t = abs(x1-x)
- if t < tol:
- break
- x = x1
- return x
- initial = 2
- print(Newton(f1,derivative_f1,initial,0.000001))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement