Created
April 4, 2023 20:35
-
-
Save therealFoxster/a0090ba90046e26633a2341d15bbb15c to your computer and use it in GitHub Desktop.
Newton's Iterative Formula in SageMath
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
# Function variable x | |
x = var('x'); | |
# Function f(x) | |
f(x) = (x-3)*ln(x)-1; | |
# Derivative f'(x) | |
df = diff(f,x); | |
# Newton's Iterative Formula | |
nif(x) = x-(f/df)(x); | |
x1 = 5; # Initial guess | |
i = 10; # Number of iterations | |
for _ in range(i): | |
x=N(nif(x1)); | |
print(x, "<-- iteration", _+1) | |
x1=x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment