def differential(f, x, deltax=1e-12):
    """
    Returns the slope of the given function at the point x
    using the midpoint method. A deltax of 1e-12 or 1e-11
    works best.

    """
    # the following formula is the average between the slopes using
    # the right limit [(f(x + deltax) - f(x)) / deltax] and
    # the left limit [(f(x) - f(x - deltax)) / deltax]
    return (f(x + deltax) - f(x - deltax)) / (2 * deltax)