Least squares fit to a straight line?

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
4 replies · 2K views
noname1
Messages
131
Reaction score
0
I was wondering if someone could explain how to compute the Least squares fit to a straight line
 
Physics news on Phys.org
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
 
i have solved it and got this

y = 46.3x+(-61.8)

my question is now, i plotted my points on a table on paper but how do i make the straight line?
 
how didnt i think of that duhhh lol, one more question now how do i calculate g from the slope?