Created
March 22, 2018 19:35
-
-
Save LVMBDV/ebea8838cedb9c1e59c7e9a2ffb39696 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 | |
from sympy import lambdify | |
from itertools import count | |
function = lambdify("x", input("Enter a method to iterate with: ")) | |
initial_value = float(input("Enter the initial value for the iteration: ")) | |
target_diff = float(input("Enter the target value for the difference between iterations: ")) | |
value = initial_value | |
for step in count(): | |
previous_value = value | |
value = function(value) | |
print(str(step).rjust(4), value) | |
if abs(value - previous_value) <= target_diff: | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment