Fitting Data

One of the fundamental tasks in experimental physics is to compare theory with data. This comparison is often done by fitting a theory-motivated curve to data. In other words, some mathematical function produced by the physical theory has unknown parameters that can be varied so the function more closely resembles the data. In this laboratory you will be given a data set and develop such a procedure to find a best fit curve to the data.

1. Basic Fit Commands

This section demonstrates the commands needed to fit a simple function to a data. First get the necessary packages. Enter this command once and only before using any other fitting commands.

Needs["LinearRegression`"]

Below is a sample data set.

data={{0.055,90},{0.091,97},{0.138,107},{0.167,124},{0.182,142},{0.211,150},{0.232,172},{0.248,189},{0.284,209},{0.351,253}};

Fit the data to a second-order polynomial with the following command.

fit1=Regress[data,{1,x, x^2},x,
RegressionReport->{ParameterTable,EstimatedVariance}]

The first column of the table above contains the terms of the polynomial,the second column has the best-fit parameters for each term,and the third column shows the uncertainties in those fit parameters.The remaining columns hold the results of statistical tests that are not important to us now. The estimated variance (σ^2) is defined in the following way

                                                                        (σ^2) = (1/(n-m))∑((((Subscript[y, i])-(Subscript[y, fit])))^2)

where n is the number of data points, m is the number of adjustable parameters in the fit, (Subscript[y, i]) is a data point at a particular (Subscript[x, i])value, and (Subscript[y, fit])is the value of the fit at that point. This quantity represents the quality of the fit and it is also used to convert the parameter uncertainties from those of a Student's t-distribution to a Gaussian distribution.

2. Other Useful Commands

The command below shows how to read in a set of horizontal position versus time data from the file `rolling.dat' into the array data1.

(* on a unix machine. *)
data1 = ReadList["/home/gilfoyle/tmp/rolling.dat",{Number,Number}]

(* on a windows machine desktop. *)
data1 = ReadList["C:\\Documents and Settings\\ggilfoyl\\Desktop\\rolling.dat",{Number,Number}]

To display the data1 array and a curve on a single plot use the commands shown below. You'll need this later.

plot1 = ListPlot[data1,PlotStyle->RGBColor[0,0,1]]
plot2 = Plot[0.2 + 0.3*x,{x,0,1.75},PlotStyle->{Thickness[0.01],RGBColor[1,0,0]}]
Show[plot1,plot2]

2. Testing a Model

In this example consider a ball rolling on a flat surface. 

1. What is the horizontal acceleration? 

2. What expression would describe the horizontal position as a function of time? 

3. Use the data1 array from Section 2 to test your hypothesis. How would tell that your hypothesis is the best one?