Answer by
njanetos (69)
There are many ways to find a formula which describes a line that fits some collection of points. But the easiest one to remember is in the two-dimensional case. The line will be of the form y=mx+b, where m=(n*sum(xy)-sum(x)*sum(y))/(n*sum(x^2)-sum(x)^2) and b=(sum(y)-m*sum(x))/n. Here "sum(x)" means the sum over the x component of all points.