1 Phys261 Exp1 Excel - F2015
1 Phys261 Exp1 Excel - F2015
1 Phys261 Exp1 Excel - F2015
Introduction to EXCEL
I. Purpose
The purpose of this experiment is to teach you a few basic things about using EXCEL
2010 to plot and analyze data in the Physics lab. Make sure you complete the spreadsheet work
in Section VII and submit it to ELMS Canvas.
II. References
If you are not already comfortable with using EXCEL, you should start by reading
Appendix B and then come back and work through this write-up. If you are already familiar with
using EXCEL, read this write-up and consult the Help button in Microsoft Office Excel 2010.
III. Equipment
You will need a computer with Microsoft Office EXCEL 2010 installed. Note: the layout
of this version of EXCEL is similar to the 2007 version but differs substantially from all other
earlier versions, such as Excel 2003. You need the 2010 version to do this lab.
IV. Pre-lab Questions (Submit answers to Expert TA before your lab section meets)
Questions and multiple choice answers on Expert TA may vary from those given below. Be sure
to read questions and choices carefully before submitting your answers on Expert TA.
#1. A cell in an EXCEL spreadsheet contains $A$5. What does it mean? (pick one)
(a) Cell A5 is formatted as a currency. (b) Cell A5 is a fixed cell. (c) This tells Excel that cell
A5 is text rather than a numerical input. (d) This means the cell contains a formula. (e) This
is EXCELs way to indicate the cell contains an error.
#2. Given an x-coordinate and a y-coordinate for a point, which type of chart in EXCEL will
actually plot the point at its Cartesian coordinates? (pick the best answer) (a) line chart, (b)
pie chart, (c) scatter chart, (d) bar chart, (e) all of the above except the pie chart.
#3. In EXCEL, what is the Solver used for? (pick the best answer)
(a) Finding errors in a formula, (b) minimizing or maximizing a cell by varying other cells,
(c) doing error analysis, (d) solving algebraic equations, (e) solving differential equations.
#4. To run a macro in EXCEL, you may need to first click on.....? (pick the best answer)
(a) a cell and type in the macro formula, (b) the home tab and then click on the paste button,
(c) the insert tab and then enter your macro into a cell, (d) the view tab and then click on the
macro button.
#5. Before the lab template will let you exit from EXCEL, according to step 21, you must have
(a) entered your name in the designated area of the spreadsheet, (b) entered your section
number in the designated area of the spreadsheet, (c) saved the file using the gray save button
in the body of the spreadsheet, (d) all of the above.
Figure 1. Scatter plot of Sin(x) versus x. Note that the chart was clicked on and this caused
Excel to highlight the x and y columns being plotted and display the Chart Tools menu.
All of your plots should have labels on the x and y-axes. In this case, Layout #10 just has
default labels that say Axis Title. To change the axes labels, just click on them and type in X
(rad) for the x-axis label and y=Sin(x) for the y-axis label.
Your Spreadsheet should now look like Figure 1. If your plot is on top of the x and Sin(x)
columns, just click on the chart and you can move it to the side with the mouse. Notice that when
you click on the white background area in the chart window but outside the chart itself, EXCEL
will highlight columns that are being plotted (see Figure 2). This is very useful - a common
mistake is to plot the wrong set of numbers. To avoid this mistake, you should get into the habit
of clicking on your charts and letting EXCEL show you what cells it is plotting.
There is another serious mistake to avoid when making plots. Although there are many
different types of charts in EXCEL, only a Scatter chart will plot an x-value and a y-value as a
point at location (x,y) in the Cartesian plane. Some of the other types of plots can fool you into
thinking that they are plotting (x,y) points, but they are not. For example, a Line chart will
actually plot the y-values versus the order in which they are given and it does not use the xvalues at all. To be clear, you should only use Scatter plot for all of your plotting - never use a
Line plot or a Bar chart or any other type of chart in EXCEL.
10
11
Figure 2. Adding error bars to a plot. To get to this view, the user has clicked on a data point on
the chart and then selected the Layout tab, then clicked on the Error Bars button, and then
selected More error bar options. The user then selected Custom on the pop-up menu and hit the
specify value button and selected the numbers shown in column F under the error Y label.
Repeat this process for the negative error values (just select the same column of error bar values
that you did for the positive error values), then click OK you will be done.
4 - Modifying Charts, Adding Titles and Labels, and Copying charts
If you want to change something in a chart, just try clicking on it - you can change the
axis limits, the chart background, the type of chart, the curves being displayed, the grid, the tick
marks, the maximum and minimum range being plotted, and the error bars. To change the x-axis
label, the y-axis label or title on a chart, just click on it and type in the new label or title. Clicking
on one of your points in the chart lets you change the symbols used in the plot, as well as their
size and color, and the line-width and color of the line in the plot. If you forgot to add axes labels
or a chart title, just right click on the chart, then got to the Chart tools area on the menu bar,
click on the Layout tab and hit the chart title or axis titles buttons.
It can take a fair amount of time to get a chart with the axes properly labelled, error bars
in place and everything else looking right. If you have to make a second plot of some other data,
you could just go through the same steps outlined above to make a plot from scratch. However,
there is an easier way. After you have made one plot, you can click once on it (this selects it) and
then click on the Copy button on the Home tab. Next click on an empty cell and hit the paste
12
13
7 - Fitting to Data - Part 1 - Three Ways to do Least Square Fits to a Straight Line
There are several ways that you can use EXCEL to fit a theoretical formula to data some of the ways are covered in this section and the next two sections.
Suppose you have some data in the form of x and y-coordinates that you want to fit to a
straight line. For example, suppose you have x-coordinates 1, 2, ...., 20 in cells H2 to H21 and ycoordinates 3, 5, 7, ...., 41 in cells I2 to I21. EXCEL has built-in functions that can determine the
slope and intercept of the straight line that is the best least-square fit to the data. To determine
the slope of the best least-square fit line, go to an empty cell, and enter
=SLOPE(I2:I21,H2:H21). Note that first range of cells I2:I21 is for the y-values and the second
range H2:H21 is for the x-values. If you put the x-range first and the y-range second, you will get
the wrong slope. To determine the intercept of the best fit line, go to another empty cell enter
the formula =INTERCEPT(I2:I21,H2:H21). You can now use these slope and intercept values to
calculate the best fit y value for any given x value.
A second way to do a least-square fit of some data to a straight line is to click on the
Data menu tab on the top of the spreadsheet, then click on Data Analysis (its on the far right
side), select Regression and fill in the pop-up menu.
If you have a plot of your data, then there is a third way to do a least-square fit of a
straight line to your data by adding a trendline. To add a trendline, go to your plot and rightclick on one of your data points. Then select Add Trendline from the pop-up menu. The
Format Trendline window will open and you can now select linear to put a straight line
through your data. You will also want to select the Display Equation on Chart option, which
will then give you the equation of the best fit line.
Note that these three least-squares fits will give you exactly the same answer, but that
does not necessarily mean the fits are meaningful. You need to exercise caution when it comes to
fitting data and there are many subtleties. EXCEL can fit a straight line to any data, whether or
not it looks anything like a straight line. What EXCEL cannot do is tell you whether the fit is
good or whether it is reasonable to try to fit the data to a straight line. In fact, a least-square fit
may not even be the best straight line fit to your data and EXCEL will not tell you if there is a
better fit. To answer such questions, you need to use a more powerful fitting technique such as
2-fitting (chi-square fitting). See Section 9 below for how to do a 2-fit and Appendix A for a
discussion of the differences between least-square fitting and 2-fitting and how to decide if a fit
is good.
8 - Fitting to Data Part 2 - Adding a Power Law Fit to a Plot
If you have a plot of your data that is not a straight line, it is simple to get EXCEL to
perform fits to a power law, i.e. the y variable scales as the x-coordinate raised to a power. To
add a power law fit to a plot, go to your plot and right-click on one of your data points. Then
select Add Trendline from the pop-up menu. The Format Trendline window will open and you
can now select power-law to put a curve of the form y = axn through your data. You will also
want to select the Display Equation on Chart option, which will then give you the equation of
the best curve. If you change any of your data points, the fit and equation will automatically
adjust. If you forgot to select the display equation option, you can right click on the trendline and
select the option. EXCEL also has options for other types of non-linear fits, including
exponential, polynomial and logarithmic. Note however that the power law fit and some of the
other choices will not display a curve if your points include zero or negative numbers.
14
Figure 4. (a) Spreadsheet showing the layout for doing a 2 fit of data to a straight line. The
straight line theory starts with an initial slope m=1 and intercept b=2. (b) Spreadsheet after the
Solver has been used to minimize 2 by varying the slope m and intercept b. The best fit value for
the slope is m =0.146817 and the best fit value for the intercept is b = 0.101822.
15
10 - The Solver
The Solver is an Excel routine that allows you to minimize or maximize the contents of a
target cell by adjusting some other cells that the target cell depends on. For example, the
previous section described a 2 fit of some data to a straight line - to do this you would need to
minimize the cell containing 2 by varying the cells containing the slope m and the intercept b of
the straight line.
To run the Solver, click on the Data tab and go all the way to the right side of the menu
bar. You should see the word Solver. If you dont see it, then you probably did not install the
Solver on your computer (it is an Add-in), and you will need to install it. If need to install the
Solver, click on the File menu tab, then select Options from the list on the left, then select Addins from the new list on the left. Another window will open and you should now be able to find
and add the Solver. Once you have the Solver installed, go back and click on the Data tab, go all
the way to the right and you should now be able to see the Solver button. Click on the button
and the Solver Parameters window will open (see Figure 5). Enter the cell that you need to
minimize into the Set Objective, select Min to minimize this cell by checking the box under
the objective box, and then enter the cells that you need to vary into the box labelled By
varying cells: - you can put one cell or a range of cells into this box. Finally, it is very
important to uncheck the box that says make unconstrained variables non-negative generally you should expect a fit parameter could be negative (see Figure 5). When you are all
done, click on the Solve button at the bottom of the window and EXCEL will work out the
minimum and display it in a new window. Depending on how large your data set is and the
complexity of the fit, this may take a fraction of a second or a few minutes. The routine is quite
powerful and has many options which are useful but outside the scope of Physics 261.
Figure 5. Solver parameter window showing that cell $E$10 will be minimized by varfying cells
$D$1 to $D$2. Note that the Make Unconstrained varaibles non-negative box has been
deselected.
16
11 - Using Macros
An EXCEL Macro is a program that is written in VBA and can be run within Excel.
Recording or writing EXCEL macros is well outside the scope of Physics 261, but suffice it to
say that they can greatly extend the power of EXCEL by automating complex tasks, creating new
functions that dont exist in EXCELs standard library of functions, or handling a wide variety of
data collection and manipulation tasks. In Physics 261, we provide macros in some of the
spreadsheet templates for collecting some of the data and handling some particularly difficult,
sophisticated or time-consuming parts of the analysis.
While you wont need to create a macro, you will need to know how to run them. To run
a macro, you first need to get a spreadsheet template with the macro in it. For each experiment,
the macros that you will need are included in the spreadsheet for that experiment. After you open
the template, EXCEL may warn you that macros are present and it has disabled them - this is a
security precaution and you should never enable macros on a spreadsheet from an unknown
source since they can contain viruses. If you get this warning on a Physics 261 template, you will
to click enable macros or else the macro will not run.
Before running a macro, you will need to enter any data that the macro will need - this
depends on the macro and there will be explicit instructions in the lab write-up for each macro.
There are two ways that you can run a macro. In most of the spreadsheets we have added
buttons to the spreadsheet that start the macro - just click on the button and the macro will
automatically respond. The other way to run a macro is to click on the view tab, and then go to
the far right end of the menu bar and click on the macros icon. A window will open with a list of
all the macros that are available to that spreadsheet. Just select from the list the macro that you
want and then click on the run button. If you dont see the macro that you want on the list, it
means your spreadsheet does not have that macro and you have downloaded the wrong template.
17
Figure 6. Prototype Spreadsheet for Lab 1. The upper plot has blue points showing v
versus t with error bars and a red line for the best fit line. The lower chart shows a plot of the
kinetic energy E versus time t (blue points) and the black curve is a polynomial fit (quadratic fit)
to the blue points. Notice that the numbers in the table in columns E and F have been formatted
to display two digits after the decimal point.
Plotting
Step 5 - Make a scatter plot of the speed v versus the time t. (discussed in section 1 above)
Step 6 - Label the x and y axes of your plot. The x axis should be labelled t (s) and the yaxis should be labelled v (m/s). (discussed in section 1 above).
Step 7 - Add error bars to your plot using the uncertainties v given in cells D18 to D28.
(discussed in section 3 above)
Linear fit
Step 8 - In cells C32 and C34 calculate the slope and intercept of the v versus t data - make
sure you treat the times as x-coordinates and the speeds as y-coordinates. (discussed in
section 7 above)
Step 9 - Go to column E and use the slope and intercept values you just found to compute the
best fit speed at each time. The best fit for the speed (which you should think of as the
y-values) as a function of the time (which you should think of as the x-values) are
found by using the formula for a line Y= mX + b. Also remember that the slope m
18
(which is in cell D32) and intercept b (which you put in cell D34) should be fixed
with $ signs in your formula so they dont change when you copy the formula.
Modifying a Plot
Step 10 - Add a curve showing a plot of the best fit speed versus time to the same graph as
the v versus t data. To do this, try right-clicking on the chart and then click on select
data and then click on add. (discussed in section 2 above)
Step 11 - Figure out how to get the data to be plotted as blue points and the best fit to be
plotted as a solid red line without points. Try right-clicking on a point in your plot,
select Format Data Series and follow where it leads. (discussed in section 1)
Step 12 - Add a title (Speed) to your chart.
Working with Formulas and macros
Step 13 - In cell F18, enter the formula for the kinetic energy of the object with the speed
shown in cell D18. (Remember that kinetic energy is 1/2 mv2). Check that you have
used a fixed cell location for the mass. Your formula in cell F18 should be
=0.5*$C$13*C18^2
Step 14 - Copy the formula in F18 to the range F19F28
Step 15 - Make a plot of the energy E versus time t. Add a chart title and label the axes.
Step 16 - Add a polynomial fit to your plot of the E versus t data (just right click on a data
point on your plot, select add trendline and then choose polynomial). Make sure you
also select display equation on the plot. If you forgot to select display equation and
already closed the trendline window, just double-click on the fit curve to reopen the
window and you can now select display equation.
Step 17 - We have included a custom macro in this template that does a 2 fit to the E vs. t
data (see section 9). This particular macro actually does all the work for you - it
generates the uncertainty in E based on the uncertainty in v, fits to a quadratic
dependence of enegy on the time, minimizes 2 automatically and displays a table of
the results and best fit parameters. To run this macro, just try clicking on the run 2
button in the spreadsheet. Note that this is the best fit to the E versus t data, and that
the power-law fit curve generated by EXCEL is not the best fit (see section 11).
Finishing Up
Step 18 - Check your spreadsheet to make sure that you have not missed any steps and have
no brown or beige cells that need to be filled in. Also check that there are no red
feedback messages being displayed. If you see a red feedback message on your
spreadsheet it means that you have done something wrong and need to fix it. The
feedback system cannot detect all problems, so check your answers carefully.
Step 19 - Save your spreadsheet! Note: The templates have been set up so that the usual
EXCEL save button is disabled. Instead, to save the file, you must have entered your
name and section number into the spreadsheet in the designated area (see step 1) and
then click on the gray save button in the body of the spreadsheet. Also, the template
wont let you exit from EXCEL until after you have saved.
Step 20 - Log onto ELMS Canvas, go to the Physics 261 assignments, and figure out how to
download and submit a copy of your spreadsheet for Lab 1 before the Deadline.
Step 21 - Do not turn off the lab computers - just close any documents or files that you used.
19