Ok, I am writing a program to find the root of f(x)= x - cos(x) using Newton-Raphson method. I implemented a loop and have calculated the root with no problems. However I want to break the loop when the difference between iterations = 10^-8. how exactly can I do this. I was thinking of using an if statement i.e. when x - x(previous) <= 10**8, break, print x but don't know how to refer to the seperate iterations!!! PLEASE HELP.
from math import *
for i in range (20):
x = x - ((x-cos(x))/(1 + sin(x)))