def fprime(x, A, b):
    """ The gradient of the objective function with respect to the heights (x).
        This gradient is a vector the same size as x.
        A^T (Ax-b)
    """
    return A.transpose() * (A * x - b)