Sie sind auf Seite 1von 28

Microsoft Excel 2007: Scientific examples

Practical Workbook

Aims and Learning Objectives


By the end of these notes, you will have discovered more features available within Excel in relation to carrying out scientific tasks within the University. You will learn how to: chart separate data series; fit a line to a set of data; enter an array function; predict values using the trend function; plot an arbitrary function; graph data with error bars; create a custom chart format; import data from text files.

Versions
This document was written for use with Excel 2007.

University of Bristol Information Services document exl07-24

Document information
Course files
This document and any associated practice files (if needed) are available on the web. To find these, go to www.bristol.ac.uk/is/learning/resources and in the Keyword box, type the document code given in brackets at the top of this page.

Related documentation
Other related documents are available from the web at: http://www.bristol.ac.uk/is/learning/resources

Microsoft Excel 2007: Scientific examples (August 2010) 2010 University of Bristol. All rights reserved.

Contents
Task 1 Task 2 Task 3 Task 4 Task 5 Task 6 Task 7 Task 8 Task 9 Charting separate data series ............................................................... 1 Using time in charts ............................................................................... 4 Fitting a line to a set of data .................................................................. 7 Array functions (TREND) ....................................................................... 9 Plotting experimental data ................................................................... 11 Refreshable text import ....................................................................... 13 Plotting an arbitrary function .............................................................. 15 Charts: axis formatting ........................................................................ 17 Creating a combination chart .............................................................. 19

Task 10 Plotting data points with error bars .................................................... 20 Task 11 Chart templates .................................................................................... 23

Microsoft Excel 2007: Scientific examples (exl07-24)

Introduction
Excel is the University's recommended spreadsheet product for Windows on PCs. This document contains illustrative examples. These examples can be worked through exactly according to the notes or you can vary them.

Prerequisites
This document assumes that you have a good level of experience of Excel. You must be able to use the following features: Formulas - covered in the course Microsoft Excel level 1: Getting started (document exl07all2). Charts, range names and functions - covered in the course Microsoft Excel level 2: Making more of Excel (document exl07all-3). See the Related Documentation section in the inside front cover for the location of these documents.

Microsoft Excel 2007: Scientific examples (exl07-24)

Task 1 Charting separate data series


Objectives Comments 1.1 1.2 To create an Excel graph from separate series of data. This example uses readings taken at different sites at variable time intervals. Open the workbook C:\User\Excel\Scentific and use the sheet Series. Select the range B3:C6.

Choose the Insert tab on the Ribbon Select the arrow below the chart type Scatter and choose the fourth subtype, scatter with straight lines and markers.

Figure 1 Choosing a scatter chart

The following chart will be created.

Figure 2 First data series

1.3

To change the series title to Site 1, click the Select Data button

Click the Edit button and type Site 1 in the Series name box. Click OK. 1

Microsoft Excel 2007: Scientific examples (exl07-24)

Figure 3 Edit series

1.4

Click the Add button to define Series 2.

In the Series name box type Site 2. Click in the X Values box then select the range B10:B13. Click in the Y Values box and delete the existing data then select the range C10:C13. Click OK. 1.5 Click the Add button to define Series 3. In the Series name box type Site 3. Click in the X Values box then select the range B17:B21. Click in the Y Values box and delete the existing data then select the range C17:C21. Click OK twice. 1.6 Click the first Chart Layouts button which will add heading placeholders to the chart.

Figure 4 Chart layouts

Retype the headings as shown in Figure 5.

Microsoft Excel 2007: Scientific examples (exl07-24)

Figure 5 - chart of readings taken at variable time intervals

Microsoft Excel 2007: Scientific examples (exl07-24)

Task 2 Using time in charts


Objectives Comments 2.1 Note 2.2 To solve problems with the display of time in charts. The method you use will depend on the data. Click the Time 1 sheet in the workbook C:\User\Excel\Scentific. Ignore the Day data in column A for the present. Use the method from Task 1 to create a Scatter chart (4th type) for the two series of data: Series Name Patient 1 Patient 2 Add the headings. Warning! In Figure 6, any times beyond midnight on the first day, Day 0 are plotted as though they are actually on Day 0. The next section solves this problem in various ways. X Values B4:B11 B18:B27 Y Values C4:C11 C18:C27

It should look like Figure 6.

Figure 6 - time chart

The Day 0 method


In this example the readings for the patients start on different dates, but for each patient we want this to be counted as Day 0, so the data are plotted to compare like with like. The first day of sampling is Day 0, the second is Day 1 and so on. 2.3 2.4 Click the Time 2 sheet. In cell C4, enter the formula = A4+B4 and copy to cells C5:C11. Repeat to create formulae in cells C18:C27.

Microsoft Excel 2007: Scientific examples (exl07-24)

2.5

Create a scatter chart (with lines and markers) for the two series of data: Series Name Patient 1 Patient 2 X Values C4:C11 C18:C27 Y Values D4:D11 D18:D27

Patients' Readings
70 60
Reading

50 40 30 20 10 0 00:00 12:00 00:00 12:00 00:00 12:00 Patient 1 Patient 2

Time

Figure 7 - time chart corrected for relative dates

Plotting the date and time (for information)


If you want to see actual dates as well as times on the chart: 2.6 Examine the Time 3 sheet. You will see that explicit dates and times have been given on this sheet and the data has been graphed. Typing the date and time in the same cell is tedious! The date and time are both given on the X axis. 2.7 If you want the date/time to be plotted, but only the time to show on the axis, reformat the data in Column A to show time only as follows:

Select cells A4:A11. Click the arrow on the Number group of formatting options.

Figure 8 Accessing the full number formatting options

From the Number tab, choose the Custom category. Choose the format hh:mm. Click OK.

Microsoft Excel 2007: Scientific examples (exl07-24)

Figure 9 Hours and minutes format

The dates are now hidden on the X axis, but the shape of the chart is unchanged. 2.8 If you have a lot of dates to enter, the method shown in the Time 4 sheet will speed things up.

Examine the Time 4 sheet, especially the formulas. Columns D and E contain the plotted data.

Microsoft Excel 2007: Scientific examples (exl07-24)

Task 3 Fitting a line to a set of data


Objectives Comments To show how Excel may be used to find the best fit of a straight line to a set of data points. The example in this task is based on experimental measurements of the length of a spring under given loads; theory predicts a linear relationship between these two variables. Use the file C:\User\Excel\Scentific and the sheet Loads. Select the range A4:B9. Select the arrow below the chart type Scatter and choose the first subtype.

3.1 3.2 3.3

Choose the Insert tab on the Ribbon

Figure 10 Choosing a scatter chart with markers

3.4

Produce a chart similar to that shown in Figure 11.

Figure 11 - XY scatter chart (type 1

3.5

With the chart selected, choose the Layout tab.

Click the arrow below the Trendline button. Select More trendline options (see Figure 12).

Microsoft Excel 2007: Scientific examples (exl07-24)

Figure 12 Choosing trendline options

In Trendline Options select Linear. Tick (at the bottom of the box) Display Equation on chart and Display Rsquared value on chart. Click on Close. 3.6 3.7 Drag the box containing the Equation and the R-squared value to a suitable position on the chart. Save the file. As can be seen in Figure 13, the results accord very well with the theory (an Rsquared value of 1 would represent a perfect fit).

Figure 13 - linear trendline

Microsoft Excel 2007: Scientific examples (exl07-24)

Task 4 Array functions (TREND)


Objectives Comments To predict the length of the spring under different loads using the TREND function. This is an example of an array function. Array functions are entered a little differently from other functions and it is important to follow the instructions exactly as shown! The same task can be done here by using an ordinary function, and this is also shown. An array formula can perform multiple calculations at once and then return either a single result or multiple results. Array formulas act on two or more sets of values known as array arguments. Each array argument must have the same number of rows and columns. You create array formulas in the same way that you create other formulas, except you press <Ctrl> + <Shift> + <Enter> to enter the formula. 4.1 Use the file C:\User\Excel\Scentific and the sheet Loads. For example, given a series of known spring lengths (in column B) for a series of known loads (in column A), the TREND function can predict the spring lengths for some new loads (see Figure 14). To do so, it determines the straight line values that would be plotted on a graph like that produced in Task 1. The trend calculation can be done as an array, or by an ordinary formula. Both are given here.

Figure 14 - example of TREND function

4.2

Enter in A10:A14 the new values shown in Figure 14 to represent the new loads for which the length of the spring will be predicted:

Highlight the range B10:B14, which will be used to hold the predicted values. Click the Insert Function icon Click OK. In the resulting dialog box, enter the data values as shown in Figure 15, by clicking each box in turn and highlighting the range of cells in question. , select the TREND function.

Microsoft Excel 2007: Scientific examples (exl07-24)

Figure 15 - TREND function dialog box

Do not click on OK at this stage. 4.3 4.4 Note The Formula Bar should now read as follows: =TREND(B4:B9,A4:A9,A10:A14). To enter the array function do not click on OK, but hold down <Ctrl> and <Shift> and then press <Enter>. This is the method used to enter array functions (that produce multiple results), rather than simple functions. The set of numbers in the range B10:B14 represent the predicted length of the spring for the corresponding loads. Note Or, to do this without an array: Use the Insert Function method to enter this formula in B10 =TREND(B4:B9,A4:A9,A10) Alter it to contain absolute references to the existing data by adding dollar signs where shown: =TREND($B$4:$B$9,$A$4:$A$9,A10) Copy the formula to B11:B14. Format the numbers to 2 decimal places. To add these data to the original chart:

4.5 4.6

Right click the chart. Choose Select Data. Click the Edit button. Delete and replace the X and Y series values by highlighting the cell ranges. Click OK twice. Note In the TREND function, the parameter const determines whether or not the line is to pass through the origin; if omitted, or if the value is TRUE, the constant will be evaluated. If the value is FALSE, the line will be forced to pass through the origin. For the purposes of this example, leave Const blank.

10

Microsoft Excel 2007: Scientific examples (exl07-24)

Task 5 Plotting experimental data


Objectives Comments To take the average of four sets of readings and plot the result. This example assumes that a set of experimental data has been obtained from a scientific instrument and stored in a text file in what is known as standard ASCII text. The data consists of four sets of 49 values, each separated by a comma with each set of data on a new line. Most programs and systems can produce data in this form. At the end of this task, the Excel worksheet should look similar to that in Figure 16.

Figure 16 - plotting experimental data (finished result)

5.1 5.2 5.3

In Excel, open the file C:\User\Excel\data1.csv. Insert two new rows above the data starting in cell A1. Click in cell A9 and enter the formula to calculate the average for the values in cells A3:A6 =AVERAGE(A3:A6) Copy this formula to cells B9:AW9. To create the chart:

Enter worksheet titles in cells A1 and A8, as shown in Figure 16.

5.4 5.5

Select the data range A9:AW9. Choose the Insert tab on the Ribbon Select the arrow below the chart type Line and choose the second subtype, stacked line chart.

11

Microsoft Excel 2007: Scientific examples (exl07-24)

Figure 17 Choosing a stacked line chart

Add the chart title Average Values. 5.6 Remove the horizontal gridlines: From the Layout tab click the arrow below Gridlines. Choose Primary Horizontal gridlines Select the option None. 5.7 Remove the legend (see Figure 18): From the Layout tab click the arrow below Legend. Select the option None.

Figure 18 Legend options

5.8 5.9

Save the file as an Excel worksheet asTask5. Close the file.

12

Microsoft Excel 2007: Scientific examples (exl07-24)

Task 6 Refreshable text import


Objectives To create a link between an Excel spreadsheet and a text file, such that the spreadsheet can be refreshed to reflect any changes made to the original text file. This feature is useful in areas where data is collected in raw text format, perhaps by some other equipment and then manipulated in Excel in some way. To see what the data we are going to use looks like, open the text editor Notepad as follows:

Comments

6.1

From the Start menu, choose Programs then Accessories and Notepad. From the File menu, choose Open. From the Files of Type box, select All Files. Find the file C:\User\Excel\data1.csv and click on Open. You will see 4 lines of data separated by commas; the data is known as comma delimited. Close Notepad. 6.2 6.3 In Excel, create a new, blank workbook and click on cell A1. From the Data tab, in the Get External Data group, select From Text..

Figure 19 Choosing type of external data

Navigate to the file C:\User\Excel\Data1.csv and click on Import. 6.4 Use the Text Import Wizard as follows: In Step 1, to accept Delimited as the file type, click on Next. In Step 2, under Delimiters, untick Tab and tick Comma to determine how the data is separated then click on Next. In Step 3, leave the Column data format as General then click on Finish. 6.5 6.6 6.7 6.8 Click on OK to place the data in cell A1 of your current spreadsheet. Work with the data in the same way as in steps 5.2 - 5.5 from Task 5. Save the file as Task6. In NotePad, open the file C:\User\Excel\data1.csv.

Make an obvious change to the data (for example, change the first entry from 10.36503 to 5). Save the file. Switch back to Excel and click on the worksheet, within the range A3:AW6. From the Data tab select Refresh All. 13

Microsoft Excel 2007: Scientific examples (exl07-24)

Locate the file data1.csv and click on Import.

Figure 20 Refresh data

Note

Care should be taken when the original data file is extended rather than simply modified as new data sets will not automatically be included in the range used by the chart. In this example, additional rows of data will be included in the average value calculations, but values added after the 49th on each row will not. Any necessary formulae should be extended. If necessary, extend the data range plotted in the chart as described in 4.6. To obtain data from Microsoft Access, start from Access, select a table or query and from the File menu, choose Export. Save the data as a workbook in the latest Microsoft Excel format. There are choices to save the existing formatting (column widths) and to automatically start Excel opening the newly created file.

Note

14

Microsoft Excel 2007: Scientific examples (exl07-24)

Task 7 Plotting an arbitrary function


Objectives Comments 7.1 To show how Excel may be used to plot functions and to investigate the way in which the nature of the function depends on parameters. This data is used to create a chart in the next task. Open the file C:\User\Excel\Scientific. You will use the sheet Function. In this example, we wish to explore the function 3 2 2 Ax Bx Cx D E(sin(3x)) . In order to make the worksheet flexible, it is necessary to be able to change the parameters A, B, C, D and E and also change the plotting increment. Note The final worksheet (at the end of the next task) will look similar to that on Page 17. The parameters and the plotting increment can be changed by simply typing the value required in the appropriate cell. Typical values for parameters A to E have been entered in cells C4:C8. These cells have been given range names (A, B, CC, D and E) for ease of use in the formula you will create. Note that C is not a valid name so CC has been used. See Figure 21.

7.2

Use the Name Box to check that the names A, B, CC, D and E apply to cells C4, C5, C6, C7 and C8.

Figure 21 - names used in spreadsheet

7.3

The values for x will start at 0 and be increased successively by the value in cell I3, the typical plotting increment (0.04). I3 has been named Inc for ease of use in the formula you will create. See Figure 21. Now set up the X plotting range. To get a smooth curve, we need at least 50 points.

Use the Name Box to check that the name Inc applies to cell I3. 7.4

Cell B10 has the starting value, of 0. In cell C10 enter the formula: =B10+Inc. Copy this formula to the range D10:AZ10. 7.5 Enter the formula to calculate the Y values produced by the function as follows: Select cell B11 and enter the formula: =A*B10^3+B*B10^2+CC*B10+D+E*(SIN(3*B10))^2. Copy this formula from B11 to the range C11:AZ11. See Figure 22

15

Microsoft Excel 2007: Scientific examples (exl07-24)

Figure 22 - function results

You can now see the nature of the function. The parameters A, B, C, D and E and also the plotting increment, Inc, can be easily changed and the effects observed. This ability to explore the nature of complex functions is one of the key features of a spreadsheet. 7.6 Save the file. In the next task you will plot a chart of the function.

16

Microsoft Excel 2007: Scientific examples (exl07-24)

Task 8 Charts: axis formatting


Objectives Comments To tidy up the charts displaying the origin on an axis. You will use the data created in Task 7. The custom number format used below is a code in up to four parts. The format codes, separated by semicolons, define the formats for positive numbers, negative numbers, zero values, and text, in that order. If you specify only two sections, the first is used for positive numbers and zeros, and the second is used for negative numbers. If you specify only one section, it is used for all numbers. If you skip a section, include the ending semicolon for that section. For example:

8.1

Continue using the Scientific workbook and the Function sheet. If you have not done the previous exercise, use the Function 2 sheet. Chart the data in the range B10:AZ11 using a scatter chart of the third type with smoothed lines and no markers. You will see in Figure 23 that the X-axis origin is displayed on the Y-axis (above the point -2.00).You will remove it for cosmetic reasons. You will also change the number of decimal places displayed for the X-axis figures.

8.2

Figure 23 - formatting a chart axis

8.3

With the chart selected, format the X-axis as follows:

From the Layout tab, click the arrow below Axes and choose Primary Horizontal Axis.

17

Microsoft Excel 2007: Scientific examples (exl07-24)

Figure 24 Choosing axis layout

Select More Primary Horizontal Axis Options. 8.4 Select the Number option. See Figure 25. Click the category Custom Click in the Format Code box and type 0.0;-0.0;;. This means: positive and negative numbers will have one decimal place, zero will not be displayed and text formatting is not being considered. Click Add.

Figure 25 Custom number format for an axis

Click Close. 8.5 8.6 Remove the legend. Save the file.

Adding a secondary axis (For reference)


It is sometimes helpful to plot one set of data on a secondary axis. To do this, select the data series you want to plot separately, then right click on it and choose Format Data Series. In the dialog box that appears, click on Series Options on the left (if youre not taken straight there) then choose to plot the series on the Secondary Axis then click Close. A secondary axis will appear on the right. For more information, search for secondary axis in Excels help system. Warning! This technique should be used carefully as it is easy to make the data look misleading or confusing. 18

Microsoft Excel 2007: Scientific examples (exl07-24)

Task 9 Creating a combination chart


Objectives Comments 9.1 9.2 9.3 To create a chart which combines more than one chart type It is common to combine a column chart with a line chart Open the file C:\User\Excel\Formulas and open the garage sheet. Using the SUM function, create totals in the cells B7:E7 Select the range A3:E7 and create a column chart to display this data.

Note that this will include the totals. Your chart will look like the one below:

Figure 26 - simple column chart displaying all the data

It is not that helpful having the totals charted as columns alongside the raw data. It would be more helpful to have the totals showing as a line chart which would give a clearer idea of total sales over the year. 9.4 9.5 Click on one of the totals columns to select the whole data series On the Chart Tools: Design tab, click on Change Chart Type then click OK.

Click on the first Line chart option

It is now easier to see the gradual increase in total vehicle sales over the year.

Figure 27 - column chart combined with a line chart

19

Microsoft Excel 2007: Scientific examples (exl07-24)

Task 10 Plotting data points with error bars


Objectives Comments To chart errors bars with data points. When plotting scientific, experimental or statistical data, it is often useful to include some measure of the error associated with the sample or reading. Excel has the ability to associate error bars with data points, and to implement these quite easily. Excel offers several different types of error bars: Fixed Value - A constant used as the error amount for all data points. Percentage - A percentage value, to be calculated from each data point to be used as the error amount. Standard Deviations - A number of standard deviations from the mean of plotted values to be used as the error amount. Standard Error - Uses the standard error of the plotted values as the error amount for each data point. Custom - A worksheet range or array (for example, {4, 3.75, 3.25, 2.5}) containing the same number of values as there are data points in the series. Each value is a custom amount for the corresponding data point. 10.1 10.2 10.3 Use the file C:\User\Excel\Scentific. Click the Errors sheet. This worksheet contains approximately 100 data points and their errors. Select A1:B102 Create a chart of the type: Scatter with only markers, ie type 1.

Figure 28 Scatter chart

10.4

To give each point a custom error of the value in the dE column:

Click the chart to edit it. From the Layout tab select Error Bars (see Figure 29).

20

Microsoft Excel 2007: Scientific examples (exl07-24)

Figure 29 Error bars command

Choose More Error Bar Options.

Figure 30 The Format Error Bars dialogue box

Choose Custom then click Specify Value. The Custom Error Bars dialogue box opens.. For both the Positive Error Value box and the Negative Error Value box in turn, delete the existing data then select C2:C102.

Figure 31 Defining custom error bars

Click OK. Click Close. 10.5 Save the file. 21

Microsoft Excel 2007: Scientific examples (exl07-24)

Your chart should look like Figure 32.

Figure 32 Chart with error bars

Format the X axis and gridlines


10.6 To tidy up the X axis: Right click the values on the X axis and choose Format Axis. From Axis Options, locate Minimum Choose Fixed and type 0 in the box. For Maximum choose Fixed and type 100 in the box.

Figure 33 Axis options

Click Close. 10.7 10.8 Remove the horizontal gridlines. Save.

22

Microsoft Excel 2007: Scientific examples (exl07-24)

Task 11 Chart templates


Objectives Comments To save a preferred chart format as a template. To reuse a favourite chart type that you customised to meet your needs, you can save that chart as a chart template (*.crtx) in the charts template folder. Instead of re-creating the chart settings, you can simply apply the chart template.

Save a chart as a chart template


11.1 Using the spreadsheet created in Task 9, click the chart to activate it. On the Design tab, in the Type group, click Save As Template. In the Save in box, make sure that the Charts folder is selected. In the File name box, type a name for the chart template, eg Error Bars. Click Save.

Apply a chart template


In a new worksheet, starting in cell A1, enter the data shown in Figure 34.

Figure 34 - example data (with errors)

Select A2:B7. Create a chart of the type: Scatter with only markers, ie type 1 Select the chart. To make a selected chart match a template, on the Design tab, in the Type group, click Change Chart Type. Click the Templates folder at top left. In My Templates, on the right, click the icon for the template that you want to use. Click OK. The graph should appear with all the preferences, eg axis settings, as applied to the original graph. Warning! 11.2 When Excel constructs the error bars for the new set of data; it gets them wrong (it uses the old ones). Set the correct error bars using the method shown at 10.4.

23

Microsoft Excel 2007: Scientific examples (exl07-24)

To delete a chart template


11.3 On the Insert tab, in the Charts group, click any chart type, and then click All Chart Types.

Click Manage Templates. Do one of the following: To delete the chart template from your computer, right-click it, and then click Delete. Close the window. In the Insert Chart dialog box click Cancel.

24