def compute_fixed_point(g, x0, tol=1e-8, print_n=False):
    """ Compute the fixed point of g(x). """
    prev_x = x0
    x = g(x0)
    n = 1
    while(abs(prev_x - x) > 0.5 * tol):
        prev_x = x
        x = g(x)
        n += 1
    if(print_n):
        print("\tn = %d" % n)
    return x