Skip to content

Instantly share code, notes, and snippets.

@LVMBDV
Created March 22, 2018 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LVMBDV/ebea8838cedb9c1e59c7e9a2ffb39696 to your computer and use it in GitHub Desktop.
Save LVMBDV/ebea8838cedb9c1e59c7e9a2ffb39696 to your computer and use it in GitHub Desktop.
#!/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