def lingres(xa, ya, w):
    """
	Return a, b for the relation y = a + b*x
	given data in xa, ya and weights in w
	"""
    sum = w.sum()
    sumX = (w * xa).sum()
    sumY = (w * ya).sum()
    sumX2 = (w * xa * xa).sum()
    sumY2 = (w * ya * ya).sum()
    sumXY = (w * xa * ya).sum()
    delta = sum * sumX2 - sumX * sumX
    a = (sumX2 * sumY - sumX * sumXY) / delta
    b = (sumXY * sum - sumX * sumY) / delta
    return a, b
