Created
May 1, 2016 08:31
-
-
Save AFAgarap/358e91e4f9e4c852d9787b35389763d3 to your computer and use it in GitHub Desktop.
Finding the root of a function using Newton's method
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 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