You are on page 1of 24

Excel: 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:
This document was written for use with Excel XP (2002). However, it is also suitable for use
• chart separatewithdata series;
Excel 2000, with a few differences that are noted in the text.
• 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.

University of Bristol Information Services document excelxp-t4

Excel: scientific examples (excelxp-t4)

Document information

Course documents and files

If you are working in the training room the files you need are in C:\User\Excel.
If you want to work through the practical tasks shown in this document on your own system,
obtain the necessary files from:
You will see a link to Practice files. This contains the files you need to work through the course
notes. In Internet Explorer you extract the files as follows:
• Click on Practice files;
• Choose Save.
• Browse to where you want to save the file and click on Save (the practice files are grouped
together, and you need to extract them to be able to use the individual files);
• Go to the file you have just saved, and Open or Run it to show the Self-extracting Archive
• Select where to extract (save) the files on your system using the browse button (as
shown opposite);
• Click Start to save the files.

Related documentation

Other related documents are available from the web at:

Excel: scientific examples (May 06)
If you have any comments or queries about this document mail
This document may be used wholly or in part by the academic community, providing suitable
acknowledgment is made. It may not be used for any commercial or profit-making purpose
without permission. © 2006 University of Bristol. All rights reserved.
Excel: scientific examples (excelxp-t4)


Related documentation

Task 1 Charting separate data series........................................................ .......1

Task 2 Using time in charts............................................... ...............................2
Task 3 Fitting a line to a set of data.................................. ...............................4
Task 4 Array functions (TREND)............................................................... ........6
Task 5 Plotting experimental data................................................... .................8
Task 6 Refreshable text import................................................................ .........9
Task 7 Plotting an arbitrary function................................................. .............11
Task 8 Charts: axis formatting..................................................................... ...13
Task 9 Plotting data points with error bars..................... ..............................14
Task 10 Setting chart preferences............................................................. .....16
Excel: scientific examples (excelxp-t4)

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. Remember that the examples have
been devised to show various aspects of Excel and you do not need to work through them
Data used in these example spreadsheets is fictitious. We remind you that if you store
personal information relating to individuals on a spreadsheet, you must comply with the
requirements of the Data Protection Act. Further information about the Data Protection Act
can be obtained from the Registrar's Office.

This document assumes that you have some previous experience of using spreadsheets,
particularly to create formulas covered in the notes Getting started with Excel (document
excelxp-t1). You should also have experience of using charts, range names and functions,
which are covered in the notes Further Excel (document excelxp-t3).
See the Related Documentation section in the inside front cover for the location of these
Excel: scientific examples (excelxp-t4)

Task 1 Charting separate data series

Objectives To create an Excel graph from separate series of data.
Comments This example uses readings taken at different sites at variable time intervals.

1.1 Open the workbook C:\User\Excel\Scentific.xls and use the sheet Series.
1.2 With no data selected, click the Chart Wizard, select the chart type XY
(Scatter) and the fourth subtype (scatter with data points
connected by lines).
1.3 Click Next and click the Series tab.
1.4 Click the Add button to define Series 1.
 In the Name box type Site 1.
 Click in the X Values box then select the range B3:B6.
 Click in the Y Values box then select the range C3:C6.
1.5 Click the Add button to define Series 2.
 In the Name box type Site 2.
 Click in the X Values box then select the range B10:B13.
 Click in the Y Values box then select the range C10:C13.
1.6 Click the Add button to define Series 3.
 In the Name box type Site 3.
 Click in the X Values box then select the range B17:B21.
 Click in the Y Values box then select the range C17:C21.
1.7 Click Next and add the titles shown in Figure 1.
1.8 Click Next then Finish.

Figure 1 - chart of readings taken at variable time intervals

Excel: scientific examples (excelxp-t4)

Task 2 Using time in charts

Objectives To solve problems with the display of time in charts.
Comments The method you use will depend on the data.

2.1 Click the Time 1 sheet in the workbook C:\User\Excel\Scentific.xls.

Note Ignore the Day data in column A for the present.

2.2 Use the method from to create an XY (Scatter) chart for the two series of data:
Series Name X Values Y Values
Patient 1 B4:B11 C4:C11
Patient 2 B18:B27 C18:C27
It should look like Figure 2.
Warning! In Figure 2, any times beyond midnight on Day 1 (i.e. Day 2, etc) are plotted as
though they are actually on Day 1. The next section solves this problem in
various ways.

Figure 2 - 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 Click the Time 2 sheet.
2.4 In cell C4, enter the formula = A4+B4 and Autofill down as far as C11. Repeat to
create formulae in cells C18:C27.

Excel: scientific examples (excelxp-t4)

2.5 Create an XY (Scatter) chart for the two series of data:

Series Name X Values Y Values
Patient 1 C4:C11 D4:D11
Patient 2 C18:C27 D18:D27

Patients' Readings


40 Patient 1
30 Patient 2
00:00 12:00 00:00 12:00 00:00 12:00

Figure 3 - 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:
 Choose Format/Cells/Number tab, then Custom category.
 Choose the format hh:mm.
The dates are now hidden on the X axis, but the shape of the chart is
If you have a lot of dates to enter, the method shown in the Time 4 sheet will
speed things up.
2.8 Examine the Time 4 sheet, especially the formulas. Columns D and E contain
the plotted data.

Excel: scientific examples (excelxp-t4)

Task 3 Fitting a line to a set of data

Objectives To show how Excel may be used to find the best fit of a straight line to a set of
data points.
Comments 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.

3.1 Open the file C:\User\Excel\Scentific.xls. You will use the sheet Loads.
3.2 Select the range A4:B9.
3.3 Use the Chart Wizard to produce a chart similar to that shown in Figure 4,
choosing an XY (Scatter) chart of Type 1 and insert the headings and labels as

Figure 4 - XY scatter chart (type 1

3.4 Click the chart to activate it.

 Select Chart/Add Trendline from the toolbar, which will produce a dialog box
as shown in Figure 5.
3.5 Select the Linear type for the trend-line.
 Click on the Options tab and choose to display the Equation and the R-
squared value on the chart.
 Click on OK.

Excel: scientific examples (excelxp-t4)

Figure 5 - add trendline dialog box

3.6 Drag the box containing the Equation and the R-squared value to a suitable
position on the chart.
3.7 Save the file.
As can be seen in Figure 6, the results accord very well with the theory (an R-
squared value of 1 would represent a perfect fit).

Figure 6 - linear trendline

Excel: scientific examples (excelxp-t4)

Task 4 Array functions (TREND)

Objectives To predict the length of the spring under different loads using the TREND
Comments 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!

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.
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 7). To do so, it determines the straight line values
that would be plotted on a graph like that produced in .

Figure 7 - example of TREND function

 In the worksheet used in , enter in A10:A14 the new values shown in Figure 7 to
represent the new loads for which the length of the spring will be predicted.
4.1 Highlight the range B10:B14, which will be used to hold the predicted values.

4.2 Click the Insert Function icon , select Statistical and then TREND.
4.3 Click OK.
4.4 In the resulting dialog box, enter the data values as shown in Figure 8, either by
typing them or by clicking each box in turn and highlighting the range of cells in
Hint: you may need to 'collapse' the dialog box by clicking on the button to the
right of the value.

Excel: scientific examples (excelxp-t4)

Figure 8 - TREND function dialog box

 Do not click on OK at this stage.

4.5 The Formula Bar should now read as follows:
4.6 To enter the array function do not click on OK, but hold down <Ctrl> and
<Shift> and then press <Enter>.
Note 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.
4.7 Format the numbers to 2 decimal places.
4.8 These new values can easily be added to the chart created in Task 1 by selecting
the range A10:B14 and dragging and dropping the selection into the chart area.

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.

Excel: scientific examples (excelxp-t4)

Task 5 Plotting experimental data

Objectives To take the average of four sets of readings and plot the result.
Comments This example assumes that a set of experimental data has been obtained 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 9.

Figure 9 - plotting experimental data (finished result)

5.1 In Excel, open the file C:\User\Excel\data1.csv.

5.2 Insert two new rows above the data starting in cell A1.
 Enter worksheet titles in cells A1 and A8, as shown in Figure 9.
5.3 Click in cell A9 and enter the formula to calculate the average for the values in
cells A3:A6 (=AVERAGE(A3:A6)).
5.4 Using the drag and fill handle in the bottom right of cell A9, copy this formula to
cells B9:AW9.

5.5 Select the data range A9:AW9 and click on the Chart Wizard icon to plot
the selected data:
 Select the chart type Line and the second subtype (Stacked Line).
 From Step 3 select Titles to add a chart title.
 Select Gridlines and Legend to remove these 2 features.
 Insert the chart as an object in Data1 (immediately below the data).
5.6 Close the file, saving it as an Excel file called Task3.xls

Excel: scientific examples (excelxp-t4)

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
Comments 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. The
Refreshable Text Import feature is not available in versions of Excel before

6.1 To see what the data we are going to use looks like, open the text editor Notepad
as follows:
 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
 Close Notepad.
6.2 In Excel, open a blank worksheet and click on cell A1.
6.3 From the Data menu, select Import External Data/Import Data (in Excel
2000, select Get External Data/Import Text File).
6.4 From the Files of type dropdown menu, select All Files. Select
C:\User\Excel\Data1.csv and click on Open.
6.5 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 Next.
 Click on Finish.
6.6 Click on OK to place the data in cell A1 of your current spreadsheet.
6.7 Work with the data in the same way as in steps - from Task 5.
6.8 Save the file as a spreadsheet (Task4.xls).
6.9 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.
6.10 Switch back to Excel and click on the worksheet, within the range A3:AW6.
6.11 From the Data menu select Refresh Data. Locate the file data1.csv and click
on Import.
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
Excel: scientific examples (excelxp-t4)

value calculations, but values added after the 49th on each row will not. Any
extra data should be dragged into the chart, and any necessary formulae
extended, to update the chart.

6.12 To change the settings you made in the Text Import Wizard, click Edit Text
Import on the External Data toolbar. Select the text file and click Import.
If you want to import only part of the data in a text file as a refreshable data
range, you can create a query to retrieve the data (see the Office Assistant for
more information).
Note 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
Microsoft Excel 97-2002 format. There are choices to save the existing
formatting (column widths) and to automatically start Excel opening the newly
created file.

Excel: scientific examples (excelxp-t4)

Task 7 Plotting an arbitrary function

Objectives 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.
Comments This data is used to create a chart in the next task.
Excel is a convenient and fairly powerful tool. If you are doing a lot of this type of
work, it will be worth investigating special-purpose packages such as
Mathematica, Maple and Macsyma. For many applications, however, the ease of
use and convenience of a spreadsheet will be a considerable advantage.

7.1 Open the file C:\User\Excel\Scentific.xls. You will use the sheet Function.
In this example, we wish to explore the function
Ax 3 + Bx 2 + Cx + D + E(sin(3x)) 2 .
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
13. The parameters and the plotting increment can be changed by simply typing
the value required in the appropriate cell.

7.2 Typical values for parameters A to E have been entered in cells C4:C8. These
cells have been named (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 10.
 Click in the Name Box and check that the names A, B, CC, D and E apply to
cells C4, C5, C6, C7 and C8.

Figure 10 - 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 10.
 Click in the Name Box and check that the name Inc applies to cell I3.

Figure 11 - function results

7.4 Now set up the X plotting range. To get a smooth curve, we need at least 50

Excel: scientific examples (excelxp-t4)

 Cell B10 has the starting value, of 0. In cell C10 enter the formula:
 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:
 Copy this formula from B11 to the range C11:AZ11.
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.

Excel: scientific examples (excelxp-t4)

Task 8 Charts: axis formatting

Objectives To tidy up the charts displaying the origin on an axis.
Comments You will use the data created in .
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 Chart the data in

the range B10:AZ11 using an XY (scatter) chart of the third type with
smoothed lines and no markers.
8.2 You will see in 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. Format the X-axis as follows:
 Double-click the chart's X-axis to display the Format Axis dialog box.
 Select the Number tab.
 Click on Custom and type 0.0;-0.0;; in the Type: box (positive and negative
numbers will have one decimal place, zero will not be displayed and text
formatting is not being considered).
 Click on OK.

Figure 12 - formatting a chart axis

Excel: scientific examples (excelxp-t4)

Task 9 Plotting data points with error bars

Objectives To chart errors bars with data points.
Comments 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.

9.1 Use the file C:\User\Excel\Scentific.xls. Click the Errors sheet. This
worksheet contains approximately 100 data points and their errors.

9.2 Select A1:B102 and click on the Chart Wizard icon.

 Select chart type XY (Scatter), type 1.
 Click Finish.
9.3 If the X axis scale goes up to 120, change it to 100 as follows:
 Double-click the X axis to open the Format Axis box.
 Click the Scale tab.
 In the Maximum box, type 100 and remove the tick.
 Click OK.

Figure 13 - XY scatter chart

Your graph should now resemble Figure 13.

You can now continue with the exercise to add error bars to the data points.
Note Excel offers the ability to plot several different types of error bars:
Fixed Value - A constant used as the error amount for all data

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.
Excel: scientific examples (excelxp-t4)

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.
9.4 To give each point a custom error of the value in the dE column:
 Click the chart to edit it.
 Double-click a data point to get the Format Data Series dialog box.
 Choose the Y Error Bars tab and select the Custom radio button. This puts
the cursor in the + (positive error) box.
 Click on the worksheet and select C2:C102. The text in the + box should read
9.5 Repeat for the - (negative error) box and click OK.
9.6 Save the file.
Your chart should look like Figure 14.

Figure 14 - XY scatter chart (with error bars)

Excel: scientific examples (excelxp-t4)

Task 10 Setting chart preferences

Objectives To save a preferred chart format.
Comments Having formatted a chart in just the way you want it, you can save this preferred
chart format to save you time on your next spreadsheet. You can save it either
as the default type or as an optional one.

10.1 Using the spreadsheet created in , click the chart to activate it.
10.2 To save a custom chart type:
 From the Chart menu, choose Chart Type.
 Select the Custom Types tab.
 Click the User Defined option button.
 Click Add.
 In the Add Custom Chart Type dialog box, type a name and a description.
 Click OK.
10.3 To try it out:
 In new worksheet, enter the data shown in Figure 15.

Figure 15 - example data (with errors)

 Select A1:B7.
 Click on the Chart Wizard icon.
 At step 1, choose the Custom Types tab.
 Click the User Defined button.
 Select the chart type you created.
 Click Finish (or Next to choose further options).
The graph should appear with all the preferences (default title, axis labelling, etc.)
as applied to the original graph.
Warning! When Excel constructs the error bars for the new set of data; it gets them wrong
(it uses the old ones). If you are using error bars, remember to update this field
when using new data. You can do this by double-clicking either a data point or an
error bar and clicking on the Y Error Bars tab. Enter your error bar information in
the same way as before (Task 7).

Note You can also set a custom chart as the default chart type.