from math import sqrt # Fixed-point iteration for computing the square root of a # Does not work for all values of a # n_it is number of fixed-point iterations # x is initial guess def fix_root(a,x,n_it): true_solution=sqrt(a) print '\n \t approximation', '\t error' for k in range(n_it): x=-x*x+a+x error=abs(true_solution-x) print '\t %f \t %f' % (x,error)