Newtons method to solve equation
from math import * def numder(f,x,step=0.00001): return (f(x+step)-f(x-step))/(2*step) #def f(x): return cos(x)-x def newt(f,x0, tol=1e-10): x = x0 print("0 : ", x0) n=0 while (abs(f(x)/numder(f,x)) > tol) and (n<20): n=n+1 xn = x - f(x)/numder(f,x) print(n,": ",xn) x=xn print("done")