Fitting Data

WHICH FITTER TO USE  ::  ENTERING YOUR DATA

ACCESSING THE FARADAY FITTER  ::  USING THE FARADAY FITTER

WHICH FITTER TO USE

For many cases when you need to fit data to a function (linear, quadratic, etc.) the fitter in DataStudio is fine. However this fitter does not correctly include the effect of errors. To handle errors correctly you may want to use the fitter on Faraday which is accessible through the Web.

Details of the use of the Faraday Fitter and useful Tips are contained in the relevant pages of the Laboratory Manual. You will find the fitter MUCH easier to use if you have these pages in front of you. By default the Fitter fits to a polynomial in the independent variable where the independent variable may be any legitimate Mathematica expression involving the variables in addition to the simple variables you have entered. To use the Fitter to fit to other linear models such as Fourier Series or Bessel Functions etc. see "Advanced Options" in the Fitter.

ENTERING YOUR DATA

1. Using DataStudio.

Either - A. You have taken the data using DataStudio. In this case, drag the icon for the appropriate run in the Data window onto the Table icon in the Displays window. If you want to edit the data at this stage - though since you do have to edit it in Notepad before it goes to Faraday, you might as well wait till that step - you can do so in DataStudio by clicking on the the pencil icon on the Table toolbar (see B. below for details).

Or - B. You want to fit data that was not taken directly in DataStudio. In this case, drag the Table icon onto a free area on the screen. Use the large red X on the Table toolbar to remove any data that appears there. Click on the pencil icon on the toolbar. The title of the Table will change to Editable Data; the first row will be highlighted and you can type in your data.  The right button has useful items to delete unwanted rows, etc.

THEN you need to save the file for use in Faraday's fitter  Use the Export Data option in the pull-down File menu. You will then be asked to choose the data you want to export - whatever table you have highlighted will be exported in text ( .txt ) form. You then have to choose where to save the exported data. You can leave the files on your local computer or drag them into your Faraday directory (named x****).

In both of these cases you have to delete the first two lines of the file - the title of the table and the names of the variables given by DataStudio - since Faraday expects only numerical data in this file. This is easiest done by going to the desktop, finding the file, double clicking on it to open it in Notepad and deleting the first two lines.

2. Using Excel.

As in 1B, suppose you want to fit data that was not taken directly in DataStudio. In this option you enter your data in Excel. The file must contain only numbers (no heading) with each variable in its own column - e.g. x, dx, y, dy . Save it as a .txt file (tab or space delimited) in the local computer you are using or in your directory in Faraday. If you want to name the variables (optional, but desirable), create another .txt file with the variables in the same order as the data file, their names in the first row. (Without a variables file, Faraday will simply call the variables var1,var2, etc.) Save this file, again in .txt format.

3. Directly in Faraday.

This is the easiest option for data that has not been taken directly in DataStudio. Log on to Faraday using a terminal in MP257, MP125 or MP126. Follow the menu to find the item create ; enter your data following the instructions (data goes in columns). Then you can go directly to the fitter (use the fit menu item!).

ACCESSING THE FARADAY FITTER

Log on to the Web. Follow the links from the Department of Physics home page to UPSCALE, then to Data. In the Data Analysis Tools window click on Linear Fit. You will be asked for your login name and password. If your files are in directories on UPSCALE, click on the appropriate links to find the files with your variable names (optional) and your data. The Fit Setup menu will automatically appear. If your files are in the file system on your computer (i.e. the local file system), use the Browse button to find them. Then click on Submit Upload. That should bring up the Fit Setup window. When entering the data to the fitter, remember that whatever you want to go on the y-axis is called the Dependent Variable.

USING THE FARADAY FITTER

This section has been reprinted for your convenience from the Laboratory Manual.

Plotting Graphs

Although the computer has a data-plotting utility called graph, if you wish to plot your data points and nothing more, our advice to you is don't do it on the computer. You will learn much more about what your data looks like and how your experiment is behaving if you plot by hand. However, if you want to fit your data to a theoretical expression and extract physical values from the plot, as is almost always the case, use the utility called fit described below.

Fitting a Curve (Line) To Your Data

The lab computer provides an "objective" procedure for giving a best fit of a straight line or a specified polynomial to your data, along with correctly calculated error estimates on that fit. It uses the programme called Mathematica. Basically the computer calculates the square of the distance between your data points and the curve it is trying to find; it then adjusts the constants of the polynomial representing the curve until the sum of these squares is a minimum. It gives you the values of the constants so found, along with their errors (one standard error). In addition it draws a graph which shows your data points and the fitted curve. If the errors in your data points are large enough to be visible on the graph, the computer also draws two lines which correspond to the "maximum" and "minimum" lines which would appear in a hand-drawn graph (see HAND-DRAWING OF GRAPHS above); however the computer's lines are correctly calculated to be ± one standard deviation from the fitted line. The graph itself is an important visual aid to determine the reasonableness of your fit.

The programme is menu-driven, and mostly self-explanatory.

READ THE FOLLOWING TIPS BEFORE YOU USE THE COMPUTER FOR THE FIRST TIME-

they will save you huge amounts of time!!

Your variable names should be short mnemonics, in lower case; e.g. s,t,vc etc., rather than distance, time, voltage (the less typing, the less chance of error; Mathematica functions start with an upper case letter).

Always enter your raw data, just as you have taken it (the computer will do any calculations on it that you need - see below).

As long as the errors on your data are either constants (e.g. 0.005, 0.3, etc.) or functions of the variables (e.g. 0.005/t2, 2s/t, etc.) you do NOT need to enter them (you can enter them at the time of setting up the graph). Otherwise, however, you need to define a variable name for your errors and enter the numerical value for each point.

The fit window has a table which contains the variable names you have defined; alternatively it will provide the names var1 and var2. As far as the computer is concerned, the dependent variable will appear on the y-axis and the independent variable on the x-axis (these don’t necessarily have anything to do with which variable was dependent or independent in your actual experiment); make your own choice depending on how you want your final graph to look. You also need to define the errors in these quantities. If you want to plot the variables and errors just as they were defined, choose the appropriate "buttons"; if you want to manipulate the data somewhat (or, e.g. insert a constant value for an error) choose the button which reads An expression - you can then enter a constant value or a formula to calculate the variable you want to use.

Notes on calculations using Mathematica.

Some of the grammar you may need when you calculate mathematical expressions involving your variables is listed in the table below.

Algebraic Expression Mathematica Expression
xy x*y OR x  y (be safe -  use x*y)
1/x 1/x
xn x^n
Square root of x Sqrt[x]
ln(x) Log[x]
ex Exp[x]
log10(x) Log[10,x]
cos(x)  Cos[x]
sin-1(x) ArcSin[x]
|x| Abs[x]

 

N.B. Use "(" and ")" as parenthesis in your expressions; "[" and "]" are reserved for the arguments of Mathematica functions. Angles are measured in radians.

To all data, the computer fits a general polynomial which has the form:

y = A(0) + A(1)x + A(2)x2 + A(3)x3 + ...

You need to specify which of the terms in the polynomial are relevant to the fit of your data; this is done by selecting the appropriate "buttons" in the window from the set:

0

1

2

3

4

5

6

7

8

9

to choose one or more of the coefficients

A(0)

A(1)

A(2)

A(3)

A(4)

A(5)

A(6)

A(7)

A(8)

A(9)

(Often you will be specifying 0 and 1, which is a fit to the straight line y = A(0) + A(1)x with A(1) = slope and A(0) = intercept on the y axis). Follow the on-screen menu to try another fit, or re-plot the graph with a variety of options, or print the graph on the lab printer (near the wicket).

Other Useful Features of the Faraday Analysis Programmes.

1. When you use a menu item, you need usually type in only enough letters to uniquely identify the word; most of the time only the first letter is sufficient.

2. Once you have used create to enter your data, you can always look at it by choosing the menu item show which is available on the data and the analyse menus (the latter also gives you the option to print the data file).

3. There are several ways in which you can change your data after you have created it. You should almost never have to type in the full set of data again, since these programmes will make almost all the corrections you want.

A) edit. This is the simplest of these programmes, and should be used only for simple fixes. You can move around your data file, deleting, changing and adding data. To exit edit click on File (top left corner of the screen) to pull down the menu there. Choose the End option; you will then be prompted to Save before exiting. CAUTION! Occasionally you will get a message which reads Wrong columns or non-numbers found ; this often means that you have left the cursor sitting on a new line instead of exactly at the end of your data. Move the cursor to the end of the file and use the Backspace button to delete any extra spaces or line returns till the cursor is sitting immediately after the last digit of your last data point. Then try exiting again.

B) massage. You will find this programme in the analyse menu. Clicking on massage will lead you to another menu with several options. The two which you will find most useful are now discussed.

recalc. This option presents you with the opportunity to add variables to your data set which are either constants or functions of the ones you have already defined. For example, in the Boyle’s Law experiment you may mistakenly have added mm of mercury (from the barometer reading) to cm of mercury (manometer reading), and all your pressure data has to be changed. Or you may have a very complicated expression to calculate from the raw data which you have entered in the file (the Flywheel experiment is a good example). You are asked how many new variables you want to define, their names, and how the computer is to calculate them from the data already in your file. NOTE! You are first asked if you want to keep the original data - it is usually a good idea to answer yes to this question.

addvar. You may decide that you want to add the values of a variable which you had forgotten to enter the first time. This option will ask you how many variables you want to add, and their names. It will present you, a line at a time, with the data that is already in your file. You just have to type in the new values. The programme will exit automatically when you reach the last line.