def residuals(p, y, x):
    """ The residual function required by leastsq."""

    ## The gradient of the line.
    m = p[0]

    ## The intercept with the y axis.
    c = p[1]

    ## The model we're testing - a straight line in this case.
    model = m*x + c

    ## The result to return.
    res = y - model

    # Return it!
    return res