You are on page 1of 10

Computational Spreadsheets: An Introduction

Spreadsheets are not only a great tool for graphing data, but also for transformations and calculations. They have the power to develop mathematical models and examine the goodness of fit of the model to the data as well. Basic Computations Open Excel 2007and set up a worksheet as shown below where we have supplied some Oreo cookie stack height data for stacks from 2 to 15 cookies. Type things in the same cells (starting in B3) as shown in the screenshot, that way our formulas will all be the same as we develop them.

To start a calculation in a cell, go to the cell and click and highlight it, and type = (all computations must start with an equal sign). Use the arithmetic operators as shown below. Lets calculate the stack height in millimeters in column D of the worksheet. So on the worksheet, find cell D5 and type the following in the cell: =10*C5 Here we want to multiply the value in cell C5 by 10. This converts the measurements in centimeters (cm) to millimeters (mm). You could click on cell C5 while you are doing the formula instead of typing it. If you hit enter, the formula will calculate and return the value 24 in cell D5.

Computational Spreadsheets: An Introduction/Sinex & Ragan (revised 2010)

With the cursor on the lower right corner, you can either drag down to fill in the remaining calculations or double click and it will fill down.

In column E, calculate the stack height of the cookies in meters (1 m = 100 cm). In column F, divide the results from column D by column E. What did you calculate?

Now in column G lets calculate the rate of change between each pair of points. This is the slope, y/ x, between each pair of points. In cell G5 enter the following formula: =(C6-C5)/(B6-B5) For a linear relationship, the rate of change for the data should be a constant (or nearly constant with experimental error). What do you think our cookie stack height as a function of the number of cookies in the stack should look like?

Excel has a vast variety of functions to use in calculations. Go to the summation sign on the left of the Home tab. Lets explore the sum and average functions on the worksheet. Go to cell B12, select the cell, then select Sum and get the total cookies in all the stacks. Repeat this calculation in cell C12 and get the total height of all the cookies. In cell E13, calculate the average cookie thickness. Now go to cell G13 and use Average to calculate the average thickness based on the slope calculations. You can label these by typing in the nearest cell. If you click on the More Functions, you will get the pop-up Insert Function window that gives a vast list of functions and their syntax.

Computational Spreadsheets: An Introduction/Sinex & Ragan (revised 2010)

Here is where you will find common functions such as: LN( ) for the natural logarithm LOG10( ) for the common logarithm EXP( ) for ex SQRT( ) for the square root STDEV( ) for the sample standard deviation

To see all the formulas in a worksheet, press Ctrl ` on the keyboard (press again to go back to results). This is a nice trick to use if you are trying to figure out how someone has set up a calculation in a worksheet.

Excel will deal with scientific notation such as the speed of light, 3.0 x 108 m/s or the diameter of a red blood cell, 7 x 10-6 m. Excel uses E for the 10 (not case sensitive on typing).

Computational Spreadsheets: An Introduction/Sinex & Ragan (revised 2010)

Graphing To produce a graph you must first highlight (select) the data that you want to plot. You can click on the first column heading and then move the cursor to the right to select other columns. Alternatively, you could click on the first cell of the data and highlight (click in the center of the first cell and drag to highlight) the data directly. Here we want to highlight cells B5 to C11. Note: To graph data that are in two non-adjacent columns, highlight the first column and then hold the Ctrl key down and highlight the second column. Now go the ribbons and select the Insert tab and place your cursor on the Scatter plot and click it to get the dropdown menu as seen below. The scatter plot in Excel is the ONLY graph that has the x-axis as a variable (the other graphs have the x-axis as a category, nonnumeric). We want the data points plotted without any line (can be smoothed or just connect the dots). Select the one shown to the left and your graph should appear. In Excel, the left-most column of data is always plotted as the xvariable, all others as the y-variable(s). The scatter plot will appear on your worksheet as seen in the screenshot below. Notice that the data that was plotted is highlighted (x in purple box, y in blue box) as well. You can move the blue box to select other data too.

Computational Spreadsheets: An Introduction/Sinex & Ragan (revised 2010)

You will also notice that on the ribbons when a graph is active (clicked on) that the chart tools will appear. The Design ribbon will allow color changes, but the Layout ribbon (click on it) is the major one for important graphical items labeling axes (Axis Titles), removing gridlines, etc.

For the Axis Titles, you will need to do both the x (horizontal) and y (vertical) axes. Remember the Chart Tools will only appear on the ribbon bar if you click on a graph! Finding the Line of Best Fit: Regression and Mathematical Models Excel has the capability of doing a variety of regression (or trendline) fits of data. Goodness of fit can be judged by the coefficient of determination, r2. Go to the graph and click on it and select Trendline from the Layout ribbon. Select the More Trendline Options at the bottom of the menu that appears. We use this option so that we may display the equation for the model and get Excel to calculate and display the coefficient of determination, r2. An r2 value of one is a perfect fit of the regression to the data. If you multiply r2 by 100, it tells you the percentage of variation of the y-variable that is caused by the variation of the x-variable. As the scatter in the data increases, the value of r2 decreases. One needs to be careful of data with a slight curvature!!! When the Format Trendline menu pops up, move it so that you can click on it and see the graph at the same time.

Computational Spreadsheets: An Introduction/Sinex & Ragan (revised 2010)

The Format Trendline menu has linear as the default type. If you look near the bottom, you will see that you need to select (check) the display Equation on chart and Display R-squared value on chart (you need to do this every time you perform a regression). With the graph in sight, you can select the types and view the fit to explore the various regressions. The Forecast box allows you to extrapolate the curve/line to larger x values (forward) or smaller (backward) values outside the range of the actual data. This will extend the curve/line beyond the data. Excel also has the ability to do a linear regression that is forced through zero (Set Intercept = 0).

Here is a labeled graph with a linear regression fit for the cookie data. This is the line of bestfit through the data and is a really good fit due to the high r2 value (99.9% of the stack height variation is caused by the variation in the number of cookies). How does the slope of the regression line compare to the earlier calculations of average cookie thickness?

Computational Spreadsheets: An Introduction/Sinex & Ragan (revised 2010)

Assessment See if you can construct the following spreadsheet. We want to look at the cooling of a cup of coffee. The temperature, T, of the coffee as a function of time, t, is given by: T (t) = Tsurroundings + (Tinitial cup Tsurroundings)e-kt where t is time in minutes, k is the rate constant for the cooling process, and Tsurroundings = 25oC Tinitial cup = 90 oC k = 0.3 minute-1

First set up the two columns for time, t and T(t) in cells A3 and B3. We will calculate the temperature over the time range of 0 to 20 minutes. Plug the numbers into the formula above before you put this into the spreadsheet to generate T(t). Remember to use EXP(-kt) to represent e-kt. So your equation would look like: in cell A4 in cell B4 and copy the formula down column A. Generate and label a graph of the data generated. How would you describe the plot of the data? 0

= 25+(90-25)*EXP(0.3*A4)

Now suppose you wanted to see how the curve responds if you changed the rate constant. What would you do?

Computational Spreadsheets: An Introduction/Sinex & Ragan (revised 2010)

Interactive Spreadsheets Now lets take the coffee cooling example above and make it an interactive spreadsheet where we can adjust variables and see what happens. To start, set up the following in a new worksheet. To subscript and superscript, highlight the text, right click, select Format Cells, and you will see subscript and superscript on the menu that pops up. To turn the cell lines off, go to the Page Layout ribbon and deselect the Gridlines View checkbox.

Now we are going to name variables in Excel. This makes the formulas easier to follow and more like algebraic equations. We will use the names that have the blank yellow cells associated with them. To name variables click on the yellow cell E2 and then go to the Formulas ribbon and select Define Name.

The Define Name pop-up menu will appear and it will contain the name from the cell to the left.

Computational Spreadsheets: An Introduction/Sinex & Ragan (revised 2010)

Do this for the other to variables with yellow cells. The named variables are absolute cell references (they will not change cell reference on dragging) and will use the number that we place in the various yellow cells in calculations. Note that absolute cell references use a $ sign in front of the letter and number of the cell. Now in the column labeled T(t) (cell C5) add the formula by clicking on the various cells. = Tsurroundings + (Tinitial cup Tsurroundings)*EXP(-k*B5) where cell B5 contains the time. Set up the T(t) - Tsurroundings column as well. Then produce a graph showing how T(t) and T(t) - Tsurroundings vary with respect to time, t. Once you have done this, change the values in the various yellow cells. What happens? You may want to add an exponential regression to the T (t) - Tsurroundings data.

For even more interactivity see the Cooling Coffee Excelet at: http://academic.pgcc.edu/~ssinex/excelets/cooling_coffee.xls. This interactive Excel spreadsheet or Excelet (Java-less applet like) uses items from the Forms Toolbar to enhance the level of interactivity.

Computational Spreadsheets: An Introduction/Sinex & Ragan (revised 2010)

For further information, see the following: S. Sinex and S. Ragan (2008) Excelets: A Simple, Rapid Deployment Computational Tool with Visualization and Pedagogical Powers for Middle and High School Teachers, SC08 Educational Program's K-12 Wiki, http://sc08edprogk12.wikispaces.com/file/view/Excelets_Computation_Tool.pdf, 5 pp. S. Ragan, C. Trout, and S. Sinex (2008) Computational Resources, http://mvhs.shodor.org/CAST2008, 5 pp. A good Excel 2007 tutorial - http://www.fgcu.edu/support/office2007/Excel/index.asp If you are an Excel 2003 to Excel 2007 convert, see the Quick Guide to Excel 2007 (helps with the ribbons)- http://academic.pgcc.edu/psc/Excel_2007_quick_guide.pdf Real good source of environmental science data in Excel format: http://www.seattlecentral.edu/qelp/Data.html For more Excelets (>150 spreadsheets) and information on their design, see the developers Guide to Excelets - http://academic.pgcc.edu/~ssinex/excelets

Computational Spreadsheets: An Introduction/Sinex & Ragan (revised 2010)

10