
9/12/00 2000 Donald Candela
Intermediate Physics Lab, Physics 440
Data Plotting and Fitting Exercise
For many research projects, you will have to plot data on various types of graph, and find and plot theoretical
models to compare with that data. Powerful computer packages such as Mathematica, Matlab, and Origin are
now available and commonly used in research labs for these purposes. The purpose of this exercise is to get you
to learn the rudiments of one of these packages, if you don't already know them.
The assignment is divided into stages of increasing difficulty and sophistication. We want you to use a full-
featured scientific data-handling package: Origin or Mathematica. You may already know how to do some
parts of the assignment using software like Excel, Deltagraph, Sigmaplot… We want you to use Origin or
Mathematica so you can start to learn about one of these packages. All stages use the "dummy data" that is
listed at the end of this document. You can type this data into Origin or Mathematica or you can import it
without typing in various ways.
What to hand in. We don’t need a lot of writing, but we do need at least the following:
Your name and the date
Actual plots, well-labeled to show what is what
Your answers to the questions below
Stage one: Simple plot and straight-line fit. Plot the z data set versus the x data set on linear axes, using
points or other symbols (not a curve through the data points). Be sure the axes are labeled.
Then, determine the best straight-line fit to the data and produce a plot showing both the data and the fit.
Stage two: Semi-log and log-log plots and what they tell us. Plot the u data set versus the x data set. Make
one, the other, or both axes logarithmic- do any of these turn the plot into a straight line? If so, what does that
tell us about the data (what kind of function? what power?). Repeat with the v data set plotted versus x.
Stage three: Plot data with error bars. Plot the y data set versus the x data set, using the e data set as
uncertainties on y. That is, each data point should show a symbol at (xi, yi) along with an error bar extending by
plus and minus ei in the y direction.
Stage four: Linear least-squares fit. Find the best fit of a quadratic function to the y versus x data. That is,
find the values of a, b, c such that y=ax2+bx+c best describes the data. This will normally involve minimizing the
sum of the squares of the differences between the fit and the data, hence the name "least squares". Plot the fit
and the data (with error bars) on the same graph, and print out the values of a, b, c. Usually it works best to plot
the data using points or other symbols, and the fit as a smooth curve.
Stage five: Nonlinear least-squares fits. Find and plot the best fit of the y versus x data to a gaussian function:
y = a exp(−(x-c)2 / 2σ2)
with a, c, and σ to be determined. Do the same thing for a cosine function:
y = a cos(ω(x-c)).
Note: This stage is "harder" (requires a more sophisticated fitting program) than stage four, because the gaussian
and cosine functions are not simply linear combinations of given functions.