You have N experimental points (xi,yi) and you want to fit a straight line y=ax+b across them so that the mean value of the square of the deviations y(xi)-yi is minimum with respect to the parameters a and b
.
[tex]S=\sum_1^N{(ax_i+b-y_i)^2} = minimum[/tex]
For that, the partial derivatives of S have to be zero. This condition yields two equations for a and b.
[tex]\partial S /\partial a=\sum_1^N{2(ax_i+b-y_i)x_i}=0[/tex]
[tex]\partial S /\partial b=\sum_1^N{2(ax_i+b-y_i)}=0[/tex]
Rearranging the equations:
[tex]a\sum_1^N{x_i^2}+b\sum_1^N{x_i}=\sum_1^N{x_i y_i}[/tex]
[tex]a\sum_1^N{x_i}+N b=\sum_1^N{y_i}[/tex]
Solve for a and b.
ehild