simple newton iteration based convergence function

def converge(f, step, tol, max_h):
    """
    simple newton iteration based convergence function
    """
    g = f(0)
    dx = 10000
    h = step
    while (dx > tol):
        g2 = f(h)
        dx = abs(g - g2)
        g = g2
        h += step

        if h > max_h:
            raise Exception("Did not converge before {}".format(h))
    return g