Skip to content

Instantly share code, notes, and snippets.

@AFAgarap
Created May 1, 2016 08:31
Show Gist options
  • Save AFAgarap/358e91e4f9e4c852d9787b35389763d3 to your computer and use it in GitHub Desktop.
Save AFAgarap/358e91e4f9e4c852d9787b35389763d3 to your computer and use it in GitHub Desktop.
Finding the root of a function using Newton's method
import math
print("Newton's method\n")
A = int(input("Enter value of Xn: "))
X = 0; E = 1
while (True):
B = 3**(3 * A + 1) - 7 * 5**(2 * A)
C = math.log(3) * 3**(3 * A + 2) - 14 * math.log(5) * 5**(2 * A)
X = A - (B / C)
E = abs(X - A)
if (E < (10**(-16))):
break
else:
A = X
print("Root of f(x):", X)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment