def rate(e0, e1, n0, n1, nr, p):
    """
    This equation is solved for p to determine the convergence rate when the
    reference solution is used to measure the error.

    y(p) = 0 determines the convergence rate.

    e0, n0 : Error and grid number for grid "0"
    e1, n1 : Error and grid number for grid "1"
    nr : Reference grid number 
    p : Convergence rate to solve for

    """
    h0 = 0.5 ** (n0 * p)
    h1 = 0.5 ** (n1 * p)
    hr = 0.5 ** (nr * p)
    y = e0 * (h1 - hr) - e1 * (h0 - hr)
    return y