Fixed Point Method

import numpy as np

def fp(g, x, tol=1E-5, maxit=10000):

    for k in range(1, maxit+1):

        xnew = g(x)

        if np.linalg.norm(xnew-x)/np.linalg.norm(x) <= tol:
            return xnew, k
        x = xnew

    print(f"No convergence it {maxit} iterations")
    return x, k

#---------------------------

def g(x):
    return np.sqrt(x+2.0)

#---------------------------

xguess = 4.0
x, nit = fp(g, xguess)
print(f"\nx = {x:.4f}\niterations = {nit}\nf(x)={x-g(x):.4e}")
x = 2.0000
iterations = 9
f(x)=4.9621e-06