Least Squares Fit I - Northern Illinois University

NORTHERN ILLINOIS UNIVERSITY
PHYSICS DEPARTMENT
Physics 253 – Basic Mechanics
Fall 2016
Lab #7
Lab Writeup Due: Mon/Tue/Wed/Thu, Oct. 17/18/19/20, 2016
Read Giancoli: Chapter 5 (Lecture Notes #8)
Least-Squares Fit I
χ2 Test of a Distribution
The quantity  defined below is a statistic that characterizes the difference
between your data points and a theoretical fit through your data:
2
 
2
y  y xi 

(1)
2    i
i

i 1 


where yi are your data points, y(x i ) are your theory points, and  i is the uncertainty in
N
each yi data point. For example,
 2 for a straight line fit is:
1

 2    yi  mx i  b 
i 1   i

N


2
(2)
where the theoretical points are those for a straight line: y(x i )  mx i  b . The
numerator in Eq. (2) is a measure of the deviation between theory and data, and the
denominator is a measure of the expected deviation. For good agreement between theory
and data, these deviations should be equal, thus   N  the number of data points.
The exact relation for excellent agreement can be obtained from probability theory:
2
 2  N   for excellent agreement
(3)
where  is the number of constrained parameters (for a straight line, the constrained
parameters are m and b [slope and intercept], thus   2 ).
For a fit to a straight line, in the ideal case we would like each data point, yi , to
equal each theory point, y(x i )  mx i  b , Then
 2 in Eq. (2) would be zero. In
practice this is never true. Thus, we need to find the best values of m and b that makes
 2 as small as possible—we wish to minimize  2 . To find the best value of b that
2
2
minimizes  , we must set the partial derivative of  with respect to b equal to zero:
 2
 N 1
 0
  y  mxi  b
b
b i 1  i2 i

2

N 

1
 2  2 yi  mx i  b 
i 1 
 i

N 

x
 2
  0  2  i2 yi  mx i  b 
m
i 1 
 i


Similarly,





(4)
(5)
These two equations can be rearranged into a pair of linear simultaneous equations to
solve for the unknown parameters m and b :
yi

2
i
x i yi

2
i
 b
1
 i2
 b
 m
xi
 i2
xi
(6)
 i2
 m
x i2
(7)
 i2
where it is assumed we are summing from i  1 to N . Solving this set of simultaneous
equations yields,
2
1  xi
b   2
   i
x iyi 
2
2 
2 



i
i
i 
xy
x
y 
1
1
m    2  i 2i   i2  i2 
   i
i
i
 i 
yi

xi

x 
   2  2    i2 
i
 i   i 
1
If all the uncertainties are equal,
written as:
x i2
(9)
2
(10)
 i   , then they cancel out and the solutions can be

1
x i2  yi   x i  x iyi


1
m
N  x i yi   x i  yi

b
(8)

  N  x i2 

x 
i

(11)
(12)
2
(13)
The uncertainties in the values of m and b can be found through the use of
propagation errors as discussed in the previous lab. For instance,
2
 b  2
 
 i

y
 i
2
b
(14)
with a similar relation for  m . The results are:
2
x i2
1
   2
 i
(15)
1
1

  i2
(16)
2
b
 m2 
where  is given by Eq. (10). For the special case where all the uncertainties are equal,
 i   , these equations reduce to:
 
2
b
2
x

 N
2
m
where,
2 
2
i
(17)
2
(18)


1
 yi  mxi  b
N 2

2
(19)
and  is given by Eq. (13). You can find more discussion about this topic in: Philip R.
Bevington, D. Keith Robinson, “Data Reduction and Error Analysis for the Physical
Sciences”
Analysis
This is to be done all in lab. At the end of lab upload your Excel spreadsheet to
Blackboard. There is no writeup for this lab.
In your Atwood Machine lab last week, you plotted a set of data relating acceleration (yaxis) to the mass difference (x-axis).
(1) Open up your Excel spreadsheet from last week.
(2) Create another worksheet and call it Least Squares (right click on the Sheet2 tab at
the lower left hand corner of Excel, and select Rename. If you have not given your
Sheet1 tab a name, call it Data).
(3) Construct the columns shown above of 𝑥𝑖 , 𝑦𝑖 , 𝑥𝑖 𝑦𝑖 , 𝑥𝑖2 , 𝑦𝑖2 , etc. Enter the exact
data above shown in this tutorial. Make certain that when you do any following
calculations, you use the cell reference only (ex: A9, C10, etc.) and not the actual
number in the cell. When you are done with the tutorial, you will replace the
numbers above with your actual measurements, and the calculations will
automatically update for your data.
(4) Select the cell containing the total mass M (447.35 g). Give this cell the symbolic
name MT by typing the letters MT to the left of the formula bar (and press enter):
Now the cell reference F2 is now associated with the symbolic name MT. Give the
cell A16 (the number of trials) the symbolic name N. To delete a symbolic name, go
to Formulas, and then select Name Manager and delete the desired symbolic name.
(5) Calculate the product 𝑥𝑖 𝑦𝑖 for the 1st row of data by typing the product of their cell
references:
(remember: type = sign for formulas)
Then grab the lower right hand corner of cell C9 containing the product, and drag it
to the last row of data: cell C13. This will replicate the product 𝑥𝑖 𝑦𝑖 for all the other
rows. Do the same for the columns 𝑥𝑖2 and 𝑦𝑖2 . See the final figure below to check
your results.
(6) In cell B16 we want the sum of all 𝑥𝑖 data points. Click on that cell and type
=Sum(A9:A13)
to sum all the 𝑥𝑖 data points.
Do the same procedure for the cells C16, D16, E16, and F16. For cells A19 and
B19, the square of the sums are desired. For instance for cell A19 we must type
do the same procedure for cell B19.
(7) Using Eqs 11-13, calculate  using the symbolic name for N:
Give this cell, F9, the symbolic name D.
(8) Now you are ready to find the slope, m , and intercept b of a straight ling fit through
your data. Calculate b using Eqs 11-13:
Give this cell, G9, the symbolic name b. Use Eqs. 11-13 to find the slope in cell H9,
and give it the symbolic name m.
(9) Now we are ready to find the uncertainties in the slope and intercept. Perform the

calculation yi  mx i  b

2
for column D2-D6:
We can now find  2 in Eq. 19. Put this in cell F11 and give it the symbolic name S:
(10) We can now find the uncertainties of the slope and intercept using Eqs. 17-18. Put
the uncertainty of the slope in cell J9 and give it the symbolic name Sm:
Put the uncertainty of the intercept in cell I9 and give it the symbolic
name Sb.
(11) Determine the acceleration due to gravity, g , using the slope and total mass
(remember to divide by 100 to get units of m/sec2). Put this result into cell K9 and
put into the cell K11 its uncertainty (calculated using
propagation errors):
(12) Your results should agree with the Excel spreadsheet below:
(13) For columns B2-6, C2-6, A9-13, B9-13, and cell F2 insert your own data you
gathered from last week. The values for the slope, m , and intercept, b , should agree
to your polynomial fit of order 1 (straight line fit) that you did last week (do they?—
look at your Data worksheet). Insert your own values and uncertainties in the cells
below the blue boxes for b , m , and g (do not use the values above). Note the
number of significant figures is determined by the uncertainty (which is always
written to 1 significant figure). For example, in the figure above, b 2 , thus b
must be rounded to -8 (the value -8.3 would have a precision better than the
0.2 forces m
uncertainty which would be very misleading). The uncertainty m
to be rounded to 3.6 (it would be wrong to write 3.61 since it would have a precision
0.8 forces g to be rounded
better than the uncertainty 0f 0.2). The uncertainty g
to 16.2 for the same reason.
To finish the spreadsheet, Give the fractional uncertainty of g and the percentage
error (relative to the accepted value of 9.8 m/sec2 for g ), and state whether you have
excellent, good, fair, or poor results (see how this information is shown in the figure
above—I used Insert, Equation in the ribbon menu).
Upload your spreadsheet to Blackboard.