Computer Data Analysis and Use of Excel
Total Page:16
File Type:pdf, Size:1020Kb
Computer Data Analysis and Use of Excel
I. Theory In this lab we will use Microsoft EXCEL® to do our calculations and error analysis. This program was written primarily for use by the business community, so it is very user friendly and easy to learn. It also has most of the functions and tools necessary for serious scientific calculation and for producing beautiful, customized charts and graphs. Each lab station has an IBM PC, connected over a local network to a laser printer and to a more powerful PC where all the programs and data files are stored. When the computers are turned on, you will need to log on with the user name “student” and the password “student” in order to have access to this network.
II. Experimental Procedure A. Running Microsoft Excel. This program is stored on the hard disk of each computer workstation. (Below, when we say “open,” “choose,” and “select,” that generally means to click on something with the mouse.) To run Excel, use the left mouse button to double click on the Microsoft Excel icon located on the desktop screen.
B. Simple calculations. You should now have an empty spreadsheet, titled Sheet1, open in front of you. Select cell B2, type your name and press “Enter.” Notice that the contents of the selected cell appear on a line near the top of the window, as well as in the spreadsheet. You will be calculating sin() and cos() for ranging from 0.0 to 6.0 radians in increments of 0.1 radian. Details about how to do this follow. In general, formulas to be typed into Excel will be in bold as follows: please type this into Excel. Select cell B5 and enter the number 0. Now enter the number 0.1 in cell B6. Highlight cells B5 and B6 by clicking on cell B5 and dragging the mouse over cell B6. Move the mouse arrow to the bottom right corner of cell B6 (there should be a small black box in this corner, over which the cursor becomes a simple cross: +); push and hold the left mouse button and drag the mouse down column B. Column B should now contain a series of increasing values. Make sure that the value contained in the last cell, B65, is 6.0. Click on cell B4, and enter theta (rad). This column contains values of the angle theta, in radians. Next click on cell C5. Here we want to calculate the value of sin(0), the sine of the theta value in cell B5. To do this, type: =sin(. Now click on cell B5, in the bar near the top of the screen you should see: =sin(B5. Close the parentheses, and press the “Enter” key. The number zero should appear in C5; this is the value of sin(0). Select cell C5. Then move the cursor to the lower right-hand corner of cell C5, until the cursor changes to a simple cross, as before. Hold the mouse button down, and “drag” the formula
Pcintro- 1 all the way down the column, to cell C65, and release the button. An entire column of values of sin() values will be calculated, almost instantly. Now, click on cells C5, C6, and C7, one after the other, and watch the formula appearing in the data bar near the top of the screen. Do you see what happened? As the formula was copied down, the cell number for theta was incremented, so that each cell calculates a different value of sin(). This clever trick is what lets you do a lot of calculations fast with a spreadsheet. To calculate cos() , repeat the process you used to calculate sin() except now use the formula: =cos(B5) for example.
C Graphing. In this section you will graph sine and cosine of theta vs. theta (theta goes on the x-axis). Details about how to do this follow. You should have three columns of numbers: values of theta in B5-B65, values of sin() in C5-C65, and values of cos() in D5-D65. To graph these values, first select the entire block of data by putting the cursor on cell B5, and, holding the button down, dragging down to D65. The data should appear as a highlighted block, in contrasting colors. Click on the ChartWizard button, the third icon from the right on the toolbar across the top of the screen. Now, indicate where to put the chart, by clicking once on the spot where you want your graph. A ChartWizard dialog box should open up, indicating that you are on step one of five.
Step 1: Verify that the range of values to be graphed is correct. In this case, Range = $B$5:$D$65. Click on the Next> button to continue on to step 2. Step 2: This allows you to choose the type of chart you wish to display. For now choose XY (Scatter) by selecting the appropriate box and then clicking the Next> button. Step 3: Here you choose the format of the chart you are going to display, select box 2, and click on the Next> button. Step 4: Leave all the selections unchanged and click on Next> to go straight on to step 5. Step 5: Here, you choose whether or not you wish to display a legend (in general, only use a legend if you are graphing more than one line per graph). You can add a title to your chart in the “Chart title:” box, and you can name each of the coordinate axes. When you are done, click on the Finish button to complete your chart. At any point during this process, you can repeat any step by using the Pcintro- 2 curve. You will get a menu where you can change the type of points, or eliminate points and make a line instead. In general, we will be graphing our data points. 3. Try moving the chart to a different location. Push and hold the left mouse button while the arrow is on the chart, then move the chart around the page by moving the mouse. Let go of the mouse button and the chart drops where you leave it. Before you print your graph, make sure everything fits on one page to save paper. To save ink, highlight the gray area of your graph, then right click on it and choose “Clear” from the popup menu. This makes the background of the graph white instead of gray. You should do this before printing out any graph in the future. To make sure your graph and data look the way you want, preview a printout by selecting Print Preview from the File menu, or by clicking on the print preview icon on the tool bar (the magnifying glass over a sheet of paper, fifth from the left, top row). Here you can zoom in and out to preview the document, as it will be printed. When done, click on the Close box at the top of the preview screen. Print the document by selecting Print… from the File menu, then selecting OK from the Print screen. Or you can print by simply clicking once on the print icon on the toolbar (the printer icon, fourth from the left on the top row). Using the toolbar icon will not prompt you again, it will print the document as is! Close this workbook by selecting Close from the File menu, or by clicking on the box containing an X just above the toolbar. You will be asked if you wish to save changes in ‘Book 1’, select no. Each person in a group should carry out this procedure separately, as it will be used extensively later in the semester. D. Using Excel to perform data analysis. Today most data analysis is done using computers. This section is an introduction to error analysis using Excel. We will be using these techniques in most labs this semester, so take good notes. Please make graphs of the following data, print them out and place them in your lab book, according to the accompanying instructions. In each case: (1) label each axis appropriately, including the units in parentheses; (2) put a title at the top of the graph; (3) when you are graphing data, arrange to have the data either on the same page as the graph for printing, or on a facing page in your lab book from where you paste in your printout. Open a new workbook by selecting New… from the File menu. Under General, select the Workbook, click on OK. You should now have a blank spreadsheet opened on your computer. 1. Trendline Below is a table of voltage measured across a resistor, for various values of the current. You will plot the data, with current on the x-axis and voltage on the y-axis. Then you will draw the best-fit line through the points and determine its slope. Details about how to do this follow. Begin by selecting cell B2, and filling in the names of all lab partners. It is important to do this on all graphs to properly identify your work when printing in the lab. Next copy the Pcintro- 3 table below into your spreadsheet cells A4 through C10 (row 4 should contain the headings: Measurement Number, Current (Amps) and Voltage (Volts). Notice the difference in what happens when you press Tab and when you press Enter. Measurement Number Current (Amps) Voltage (Volts) 1 0.5 1.22 2 1.00 3.11 3 1.5 4.37 4 2.0 5.11 5 2.5 7.02 6 1.25 3.62 Plot the data, by first highlighting cells B5 through C10. Then, click on the ChartWizard button on the toolbar and position the graph on your spreadsheet. In step 1, verify that the Range = $B$5:$C$10. In step 2, select the X-Y Scatter option and then go to step 3. In this example, we want to include the gridlines on our graph, so select option (3) for the graph format selection then click Next>. Do not make any changes in step 4. In step 5, give your graph a title (in Chart title) and label your axes (including units in parentheses), then select Finish. Enlarge your graph to get a better view of your data. The slope of this line gives us important physical information: the value of the resistor. To get the slope, draw in a best-fit line. To do this we will use the Excel function Trendline. Select the graph, then select the data points. Right-click on the data points and select “Add Trendline” from the popup menu. Choose “linear regression” (a straight line), and under “Options”, choose “Display equation on chart.” The best-fit line should appear on your chart, plotted over the data points. The law of physics describing the voltage across a resistor is Ohm’s law, which is written V = I R (1) where V represents the voltage across the resistor, I represents the current through the resistor, and R is the resistance. Q1. From Ohm’s law, what is the theoretical y-intercept? (Hint, compare Ohm’s law with the equation for a straight line.) Q2. For the data points you just plotted, what is the value of the resistance? 2. Linest In order to get a measure of how good your data is, we will use Excel to calculate the error of your slope and y-intercept using its LINEST function. Highlight the four cells B13 through C14. Type =linest(c5:c10,b5:b10,1,1) and press the Ctrl, Shift, and Enter buttons simultaneously. The four squares should contain the following information: B C 13 The slope: The intercept: 2.709061 0.124286 14 The error on the slope: The error on the intercept: Pcintro- 4 0.195643 0.312561 The standard form for writing your result (you should remember this as you will use it in the future) of the experimental value of R is: R = 2.71 Ohms 0.20 Ohms Note: you can require the intercept of the line to be zero, by selecting this option in the trendline method or by entering =linest(c5:c10,b5:b10,0,1) for the linest method. Print out your data table and graph and paste them in your lab book. Now open a new workbook. 3. Semi-log Plot The exponential function occurs frequently in physical phenomena. For example, the voltage across a capacitor as it discharges through a resistor takes the form: -t/ V(t) = Voe (2) where Vo is the maximum value of the voltage and the time constant determines how rapidly it decays. There are two times that are of interest: (1) the “time constant,” . (This is the Greek letter tau, rhymes with “ow”.) When t = , the volt- age decreases by a factor 1/e or V() Vo/3. (2) the “half-life,” T1/2 = 0.693. When t = T1/2, the voltage decreases by a factor 1/2 or V(T1/2) = Vo/2. An exponentially decaying function looks simpler when its logarithm is plotted as a function of time. Taking the natural log of both sides of the above equation yields: -t/ ln(V) = ln(Voe ) -t/ = ln(Vo) + ln(e ) = ln(Vo) – t/ Q3. For the equation of the natural log of voltage, ln(V), what is the theoretical slope and what is the theoretical y-intercept? (Hint: Comparing the above equation with the equation for a straight line.) Now, you will make two graphs using the data below: a linear graph and a log-linear (also called semi-log) graph. You will need the natural log of the voltages, so first calculate those numbers. Then make a graph of V (y-axis) versus time (x-axis), and a separate graph of the natural log of V, ln(V) (y-axis) versus time (x-axis). Determine the slope of the semi-log graph. Enter the table below into your spreadsheet starting with cell B4 for time (sec). You should have lnV in cell D4. In cell D5 use the function =ln(C5) and press Enter. Complete the table using the method explained in part B above. Create a graph of voltage versus time using the method outlined above. Pcintro- 5 Measurement Time (sec) Voltage (V) ln V Number 1 0 10.13 2 2.0 6.93 3 5.0 4.45 4 7.5 3.03 5 10.0 1.81 6 15 0.85 7 20 0.33 8 25 0.18 9 30 0.062 10 35 0.030 Now, create a second graph of the natural log of voltage versus time. This time you can highlight the pertinent cells by first highlighting cells B5 through B14. Then, while pressing the Ctrl button, highlight cells D5 through D14. Now continue as usual. Once you have your graph insert a best-fit line using the Trendline method described above. You may save your data using the procedure outlined above if you choose. Q4. Compare the two graphs you have created. Which one most resembles a straight line? Q5. What is the slope of the ln(V) vs. time graph? Q6. Use the value of the slope to calculate the time constant and the half-life for this data set. 4. Statistical analysis. When we measure a physical quantity more than once, we can use Excel to calculate error on this value. We can also compare our measured values with an expected (or theoretical) value. Suppose that a number, say the focal length of a lens, has been measured twice. The difference between the two measurements gives an idea of the random error in the measurement. We will define some terms, and show how to do the calculation, using EXCEL or by hand. f The measured variable. Here it represents the focal length. f The average value of f. (Pronounce it "eff bar.") f The standard deviation of the set. This represents the error on a single measurement of f. (Pronounce it "sigma eff.") The standard deviation of the mean. f , where N is the number of f f N measurements (N = 2, in our case). This is what we will refer to as the error on the measurement of f. (Pronounce it "sigma eff bar.") disc The "discrepancy," or difference between the measured value f and an expected ("theoretical") value: disc f f theor . # of sigmas The discrepancy, expressed in terms of the standard deviation of the mean: # of sigmas disc/ f . Pcintro- 6 Q The "quality of agreement." This is a qualitative statement about how likely it is that a value measured with the precision indicated by f should disagree with the true value by a certain number of sigmas, due to random errors. Look up Q in the table on page 4 of the appendix on errors in this manual. Let us suppose that the two measured values of the focal length of a lens are 11.5 cm and 9.2 cm, and that the lens is expected a priori to have a focal length of 10 cm. We will calculate f, f , f , disc, # of sigmas, and Q. Open a new spreadsheet. In B3 enter f1. In C3 enter f2. In D3 enter f-bar. In E3 enter sig- f-bar. In F3 enter f-theor. In G3 enter disc. In H3 enter No. of sigmas. And in I3 enter Q. In B4 and C4 enter the two values of f, 11.5 and 9.2. In D4 enter =average(B4:C4). In E4 enter =stdev(B4:C4)/sqrt(2). In F4 enter 10, the theoretical value of f. In G4 enter =abs(D4-F4), this takes the absolute value of the difference. In H4 enter =G4/E4. Then look up the quality of agreement in Table I of the appendix on Theory of Statistics and enter it in I4. Your results should look like this: f1 f2 fbar sig-f-bar f-theor disc No. of sigmas Q 11.5 9.2 10.35 1.15 10 0.35 0.304347826 Very Good You now have the numbers to state the result of the measurement of f. The standard way to state this result is: f = 10.35 cm 1.15 cm . Agreement with expected value is very good (0.3 sigmas). Be sure you understand this procedure, as it will be used repeatedly in the labs to come. Sometimes you may not have the computer available to do these calculations, and you will then need to do them by hand. Calculating the average value f is easy, and dividing by the square root of two is also easy. To calculate the standard deviation by hand, you can use the following formula: N 2 (xi x) i1 two values, f1 and f2 ( f f ) 2 ( f f ) 2 N 1 1 2 You should be able to plug in values for f1, f2, and f and divide by the square root of 2 to verify that Excel calculated the correct value for f . Pcintro- 7