def checkDerivative(fctn, x0, num=7, plotIt=True, dx=None, expectedOrder=2, tolerance=0.85, eps=1e-10, ax=None):

    print "%s checkDerivative %s" % ('='*20, '='*20)
    print "iter    h         |ft-f0|   |ft-f0-h*J0*dx|  Order\n%s" % ('-'*57)

    f0, J0 = fctn(x0)

    x0 = mkvc(x0)

    if dx is None:
        dx = np.random.randn(len(x0))

    h  = np.logspace(-1, -num, num)
    E0 = np.ones(h.shape)
    E1 = np.ones(h.shape)

    def l2norm(x):
        # because np.norm breaks if they are scalars?
        return np.sqrt(np.real(np.vdot(x, x)))

    for i in range(num):
        # Evaluate at test point
        ft, Jt = fctn( x0 + h[i]*dx )
        # 0th order Taylor
        E0[i] = l2norm( ft - f0 )
        # 1st order Taylor
        if inspect.isfunction(J0):
            E1[i] = l2norm( ft - f0 - h[i]*J0(dx) )
        else:
            # We assume it is a numpy.ndarray
            E1[i] = l2norm( ft - f0 - h[i]*J0.dot(dx) )

        order0 = np.log10(E0[:-1]/E0[1:])
        order1 = np.log10(E1[:-1]/E1[1:])
        print " %d   %1.2e    %1.3e     %1.3e      %1.3f" % (i, h[i], E0[i], E1[i], np.nan if i == 0 else order1[i-1])

    # Ensure we are about precision
    order0 = order0[E0[1:] > eps]
    order1 = order1[E1[1:] > eps]
    belowTol = (order1.size == 0 and order0.size >= 0)
    # Make sure we get the correct order
    correctOrder = order1.size > 0 and np.mean(order1) > tolerance * expectedOrder

    passTest = belowTol or correctOrder

    if passTest:
        print "%s PASS! %s" % ('='*25, '='*25)
        print happiness[np.random.randint(len(happiness))]+'\n'
    else:
        print "%s\n%s FAIL! %s\n%s" % ('*'*57, '<'*25, '>'*25, '*'*57)
        print sadness[np.random.randint(len(sadness))]+'\n'


    if plotIt:
        import matplotlib.pyplot as plt
        ax = ax or plt.subplot(111)
        ax.loglog(h, E0, 'b')
        ax.loglog(h, E1, 'g--')
        ax.set_title('Check Derivative - %s' % ('PASSED :)' if passTest else 'FAILED :('))
        ax.set_xlabel('h')
        ax.set_ylabel('Error')
        leg = ax.legend(['$\mathcal{O}(h)$', '$\mathcal{O}(h^2)$'], loc='best',
            title="$f(x + h\Delta x) - f(x) - h g(x) \Delta x - \mathcal{O}(h^2) = 0$",
            frameon=False)
        plt.setp(leg.get_title(),fontsize=15)
        plt.show()

    return passTest
Return a newly created :class:`Dial` verb, nested inside this
dataset/ETHPy150Open simpeg/simpeg/SimPEG/Tests.py/checkDerivative--crossover with--dataset/ETHPy150Open twilio/howtos/intercom/twilio/twiml.py/Response.dial