module 5a more on interactive animated excel: the boyle’s ... · pdf filemodule 5a more...
TRANSCRIPT
CAST---Module 5A: More on Interactive Animated Excel ©Pittsburgh Supercomputing Center Page 1
Module 5A More on Interactive Animated Excel: The Boyle’s Law Simulator
This module will introduce the interactive features available in Excel by constructing a multivariable
simulation of Boyle’s Law. Boyle’s Law is the classic inverse relationship between pressure, P and
volume, V of a trapped amount of gas at constant temperature, so mathematically PV = k, where k is
constant. It finds itself introduced in chemistry, physics, and general physical sciences plus it is the basis
of air exchange in the lungs. It is a simple experiment to perform with a syringe and pressure probe.
The objectives for this module:
To construct a multivariable simulation to help you become a model builder
To introduce the use of the forms tools and if statements
To demonstrate how errors influence power regression results
To strengthen your computational skills and use naming variables
To show how a simulation can extend a simple laboratory experiment and its data analysis
Let’s construct this spreadsheet by setting up the worksheet to simulate Boyle’s Law. Since Boyle’s Law
is part of the Ideal Gas Law, PV = nRT, we see that k = nRT and we have two variables (n is the amount of
trapped gas in moles, R is the gas constant, and T is Kelvin temperature) normally held constant that can
enter our simulation. The other two variables, noise and Vtubing are errors and will be discussed later.
We are assuming you have completed modules 2 and 3.
Constructing the basic simulation
Boyle’s Law holds if temperature (T) and the amount of trapped gas (n) are constant or considering the
Ideal gas law: PV = nRT where R is the gas constant (0.0821 L-atm/mole-K). We want to create a column
of volume data for a syringe and then we will calculate the pressure as:
PV = k
k nRTP = =
V V
Now we have two more variables to change to see how they influence the pressure and change the
graph.
CAST---Module 5A: More on Interactive Animated Excel ©Pittsburgh Supercomputing Center Page 2
When you do this experiment it can be difficult to hold the syringe at constant volume especially at high
pressures. So let’s add some random error to the volume measurement. This will be done by the
equation below, where “noise” is the random variation in the volume data:
'V = V + noise*(RANDBETWEEN(-10,10)/10)
The “noise” varies from 0 (no error) to some positive value that is multiplied by a random number
between -10 to +10 using the RANDBETWEEN function in Excel.
Another error in this experiment is due to the tubing connecting the syringe to the pressure gauge or
other measuring device. The tubing adds some extra volume that is not accounted for without applying
a correction. So let’s add this in to the equation for volume above and convert it to liters. To get:
'tubingV = (V + noise*(RANDBETWEEN(-10,10)/10) + V )/1000
The final calculation of pressure then becomes:
tubing
nRTP =
((V + noise*(RANDBETWEEN(-10,10)/10) + V )/1000)
Now we have four variables to adjust in this simulation. Okay to the spreadsheet…
Set up the worksheet to look like the screen shot below. If you use the same cells as illustrated here, all
the formulas will be the same as we work through this module.
Now we need to place a formula to
calculate in cell B5. To make the formula
look more like a real formula and not
spreadsheet notation, let’s name the
variable. Go to the Formula tab and
select Define Name and then Define
CAST---Module 5A: More on Interactive Animated Excel ©Pittsburgh Supercomputing Center Page 3
Name… again. This will open the New Name pop-up menu. Click on D2 and the “n” will appear in the
name box as seen below.
Repeat this process for the other variables. Click
on F2, I2, and then K2 to get the four variables
named.
A named variable is automatically made an
absolute reference. It will keep its cell reference
on dragging down a formula. See absolute
reference for more information.
To compose the formula to calculate the pressure, click on cell B5. In B5 start the formula with an equal
sign and type this (you can get the variable by clicking on the appropriate cells):
=n*0.0821*T/((A5+noise*(RANDBETWEEN(-10,10)/10)+Vtubing)/1000)
After typing the formula in, click on B5 and then the formula bar (see below). Notice the colors of the
boxes around the cells that appear and the variable names in the formula bar.
Here is another way of showing how the calculation is done using the variables. This uses the Formula
Auditing tools on the Formula tab.
CAST---Module 5A: More on Interactive Animated Excel ©Pittsburgh Supercomputing Center Page 4
Now drag the formula down the column to complete the calculation of pressures.
Set up a graph by highlighting the data to plot, go to the Insert tab and select Scatter. This is the only
plot in Excel where the x-variable is a numerical scale, all others are categories.
CAST---Module 5A: More on Interactive Animated Excel ©Pittsburgh Supercomputing Center Page 5
Now select the “Scatter with markers only” plot type from the menu as
seen to the right. Your graph should appear.
If you click on the graph, it will highlight the data as shown below. Note the colors of the boxes that
highlight the x and y variables of the data to the left of the graph below. The x-data or V is purple while
the y-data or P box is blue.
With the graph highlighted, you will see the Chart Tools as three new tabs appear on the right end of the
ribbon bar (see screenshot of the ribbon bar on next page).
CAST---Module 5A: More on Interactive Animated Excel ©Pittsburgh Supercomputing Center Page 6
You can add a trendline (power regression) from the Layout tab. This tab also allows you to label axes,
title, etc.
If you select trendlines (really regressions) and go to the bottom and click on More Trendline Option…
the Format Trendline menu seen to the right appears.
Select Power as the trendline option and select the display equation on chart and display R-square value
on chart too. If you move the Format Trendline menu from on top the graph, you can select through
the various trendline to explore fits.
CAST---Module 5A: More on Interactive Animated Excel ©Pittsburgh Supercomputing Center Page 7
Now if you change one of the variables on row 2, the data recalculates, the graph adjusts, and the
regression recalculates as well. Wow, you built a simulation!
Adding the interactive features
Now we are going to add the ‘bells and whistles” to the simulation to increase the level of interactivity.
We will use the Forms toolbar from the Developers Ribbon (to get the Developer ribbon, see the
Developer’s Guide to Excelets for Excel 2010, 2007, or even 2003). Once the Developer tab is turned on
it remains on the ribbon bar on the right end.
The forms controls are under Insert on the Developer ribbon. We use the Forms Controls because they
operate on both PC and Mac platforms.
Now if you cursor over any of the tools they are identified. Find the scroll bar and then click on it. Move
to the worksheet just under the yellow temperature cell then click and drag to the right (this sizes the
scroll bar).
When you release the click, the scroll bar will appear
in the box. Now right click on the scroll bar and go
to the Format Control... Click on it.
CAST---Module 5A: More on Interactive Animated Excel ©Pittsburgh Supercomputing Center Page 8
When the Format Control menu pops us, click in the box
labeled cell link and then click on the yellow cell next to T =
(the cell reference will appear in the cell link box).
Now we need to set the minimum and maximum values for the temperature scroll bar.
CAST---Module 5A: More on Interactive Animated Excel ©Pittsburgh Supercomputing Center Page 9
We will use a range of Kelvin temperatures from 250K to 1000K. Click in the appropriate box and set the
values.
For all the forms tools, the minimum and maximum values and incremental change must be whole
positive numbers. Hence to get the forms tools to control values that are negative values and/or
decimals, we must write a formula.
First let’s copy the original scroll bar for temperature and paste it two cells below each of the other
variables (this maintains the same size for all four scroll bars). Notice that the color of the temperature
has been changed as well since this is now a cell controlled by a scroll bar and not one for typing in!
CAST---Module 5A: More on Interactive Animated Excel ©Pittsburgh Supercomputing Center Page 10
Now to get the scroll bar to control “n =”, right click and select Format Control… Link in the cell link box
and reset the cell to the cell right below the yellow “n =” cell. Reset the minimum and maximum values
too.
Once you have set the control click OK.
Then go to the yellow cell, D2 and enter
this formula:
=D3/100000
Press the enter key and you should see
the value when the scroll bar is set to 50:
=0.0005
This value of n = 0.0005 moles is for a volume of 12.3mL trapped air in a syringe at 298K and 1.0 atm.
Now repeat this process for the other two remaining variables, which are errors, as shown below.
For the noise variable:
For the Vtubing variable:
CAST---Module 5A: More on Interactive Animated Excel ©Pittsburgh Supercomputing Center Page 11
Now reposition the scroll bars to cover the cells where they are linked and you are ready to simulate
with interactive tools.
Let’s add a comparison line based on the initial conditions of the simulation (n = 0.0005, T = 298, noise
and Vtubing both set at zero). To do this we will need to copy the P data and do a Paste Special of just the
values (we do not want the formula to copy). This data then
remains constant when other variables are adjusted. Copy and
Paste Special (green highlight on screenshot) the data into D5 (this
will hide it under the graph).
Next we will need a Check Box to allow the comparison data to be
plotted and moved on the plot out of sight. To get a Check Box, go
to the Developer ribbon and click on it in the Form Controls. Then
click on the worksheet, to the right of the graph, to place it.
Once placed, right click on the
Check Box, select Format Control…
and check the 3-D shading box and
click in the cell link box and then
click on the cell next to the box as
shown. You can click on the Check
box and edit the text. The Check
CAST---Module 5A: More on Interactive Animated Excel ©Pittsburgh Supercomputing Center Page 12
box returns a true to the cell when checked and false when unchecked.
We will use this in combination with an “if statement” to control the position
of the comparison line. Go to cell E5 and add the following:
=IF($N$5=TRUE,D5,-10)
By placing the $ signs on N5 we have made this an absolute reference (it will remain N5 when we drag
the formula down the column). The if statement functions as follows- when N5 is true, the value of D5
will be placed in the cell, when N5 is false, the value of -10 will be placed in the cell. You should see this
by checking and unchecking the Check Box.
Next we want to plot this on the existing graph. First step is to lock the y-axis so the minimum remains
at zero. Go to the graph and click on the y-axis. When the Format Axis menu pops up, select Fixed for
the Minimum under Axis Options as shown below.
Now click on the graph and then right click and click on Select Data… in the pop-up menu. This will get
you the Select Data Source menu to pop up (see next page) where you click on Add.
CAST---Module 5A: More on Interactive Animated Excel ©Pittsburgh Supercomputing Center Page 13
The Edit Series menu pops up and you can name the series, highlight the series x-values (volume) and
then the series y-values (the pressure data in column E). Be sure it looks just like it is shown here on the
Edit Series pop-up window below (watch the formatting of the Series X values and the Series Y values
boxes).
Click the OK button twice on the two menus. Now go to the graph and select the “compare” data on the
graph (may need to move cursor around the data points to get it). Double click to get the Format Data
Series and follow the series of screenshots below.
CAST---Module 5A: More on Interactive Animated Excel ©Pittsburgh Supercomputing Center Page 15
Now you should have a smoothed dashed line with no markers. You can go to line color to change the
color.
Here is the final product, your Boyle’s Law Simulator with a 2mL tubing error to show how the
regression is influenced and shifts compared to the comparison line. The tubing error is a systematic
error while the addition of noise causes more scatter in the data about the curve and is a random error.
Can you think of questions to have your students investigate?
Resources for more information
Developer’s Guide to Excelets – http://academic.pgcc.edu/~ssinex/excelets
For more information on the Boyle’s Law simulator, see The Boyle’s Law Simulator: A Dynamic
Interactive Visualization for Discovery Learning of Experimental Error Analysis, which appeared
in Spreadsheets in Education 3 (1) 20-26 (http://epublications.bond.edu.au/ejsie/vol3/iss1/2/).
Derive the ideal gas law for observational behavior and Excel, see
http://academic.pgcc.edu/psc/chm101/ideal_gas/
More on the tubing error and how the correction is derived -
http://academic.pgcc.edu/~ssinex/PV_tube.xls
For more about random and systematic errors, see Investigating Types of Errors, which appeared
in Spreadsheets in Education 2 (1) Article 7 (http://epublications.bond.edu.au/ejsie/vol2/iss1/7/)
See the other CAST professional development modules at
http://www.psc.edu/index.php/cast/professional-development-program.