Customizing the Water Pumping model

advertisement
P R O J E CT G U T S
W AT E R R E S O U R CE S
Water Pumping Model
Customizations #1
Background
Using the base model for the Water Resources unit (pump04rain.sltng) students
can make qualitative observations of the changes that occur as water gets
pumped from a well. In this activity, we will be instrumenting the model to
collect quantitative data then analyzing the data.
Definitions:
Qualitative means relating to, measuring, or measured by the quality of
something (its size, appearance, value, etc.) rather than its quantity.
Quantitative means relating to, measuring, or measured by the quantity of
something rather than its quality.
In order to instrument the model to collect quantitative data we need to add a
table in StarLogo TNG. The table will collect data on the time elapsed since the
model started running and the cumulative number of water molecules that
have been pumped in the time elapsed.
In order for us to count the cumulative number of water molecules that have
been pumped since the start of the simulation we need to create a shared
number variable and a table in StarLogo TNG.
PAGE 2
WATER RESOURCES
Computer Science Background
In order to understand what is going on in the computer, we will have to
understand variables and how they are used in computer science.
Definitions:
Variable: In computer programming, a variable is a container for a value or set
of values. You can think of it as a shoebox with a name label on it. The
computer program will set aside a space (shoebox) and give it a label
(variable name). Then something, usually a value, is put inside the
space. This is akin to storing a number in the shoebox.
Global variable: A global variable is one that can be updated and inspected
anywhere within a program. Its “scope” or “range of accessibility is over
the whole program.
Local variable: In contrast to the Global variable (see above), a local variable is
one that can only be accessed in a limited scope or range. For
example, agent variables are local to that agent and can only be
changed in the agent’s procedures.
There are three steps usually associated with using a variable in most any
programming language.
Step 1: Declare the variable
In this step we tell the program that we want to create a new variable.
The computer reserves space (“allocates” space) to store that variable
and associates the name of the variable with that space.
Step 2: Initialize the variable
In this step we give the variable an initial variable. This usually happens
during the “setup” phase of the program.
Step 3: Alter or update the variable
As the program runs, the variable gets updated. Usually this means that
a new value is stored in the space reserved for the variable.
Adding a Global variable:
To add a Global variable in StarLogo TNG we drag the block called “Shared
Number” from the “variables” drawer onto the runtime panel of the StarLogo
blocks window. This block will just stay unattached to anything. This step
“declares” a new global variable to be used. (Note that you can change the
name of the shared number but we have chosen to leave it as shared number
for clarity.)
WATER RESOURCES
PAGE 3
Declaring and initializing the global (or shared) variable.
Once the variable has been declared, we need to give it an initial value. This is
done in setup, so that it will be reset every time we restart the model. To initialize
the variable we use the “set shared variable” block and initialize the variable to
0. This means that there are no water molecules pumped when the model starts
running.
Next, we need to update the variable to reflect the number of water molecules
pumped as time goes on. This is a running count (or an accumulator) so we
need to add to the number each time a new water molecule is pumped. The
number should increase only if a water molecule hits the yellow part of the
pump head so we update the shared number variable within the if/then
statement.
We do this by adding a set shared number block to the “if true then” part of the
pump procedure. We add the blocks to the “then” part so we only add to the
count if the water molecule made it to the pump.
PAGE 4
WATER RESOURCES
Adding a table:
Starlogo TNG 1.5 has added a new feature that allows a table to be created.
Simply drag the “table” block from the “setup and run” drawer onto the canvas
and plug in the shared number variable you would like to record.
Table block and view of the table within the runtime panel.
Now when running the model you will see the table being updated
automatically. You can specify how often you want the table to update by
double clicking on the table to get the full size view and changing the time
interval in the top right hand lozenge labeled “Set time interval (in seconds)”.
WATER RESOURCES
PAGE 5
Saving the data:
After having students run the model for about a minute, click on the table. It will
open a larger view of the table. Click on “Save Data and give a filename and a
location to save the data.
Once saved (as a .csv file) students can open the file in Microsoft Excel by
double clicking on the file or opening Excel and then opening the file using the
file open command in Excel’s menu interface.
When you open the file, it should look similar to this.
Next, the students will create a graph of this data. Be sure to have them supply
a x axis label and y axis label on the graph by typing in column headers for the
data. (For example, in cell A1 type in “time” and in cell B1 type in “count”. )
To create graph simply highlight all the data on the spreadsheet by dragging
over it with the mouse. Then click the chart wizard or “insert” then “chart”.
Specify that you want an XY scatter plot then click next.
PAGE 6
WATER RESOURCES
Choose XY scatter plot and one with dots and a
line. Click next
The graphed dots should appear. Click next again. Now fill in the title and axis
labels.
cumulative # of H2O molecules pumped
Water pumping (number of H2O molecules
over time)
700
600
500
400
300
cumulative count
200
100
0
0
100
200
300
400
500
Time in seconds
Discussion: Analyzing the data
What is the shape of the curve?
Is there a trend you see?
Is the curve getting steeper or shallower?
If you run the model for longer, how will the shape of the curve change?
WATER RESOURCES
PAGE 7
Advanced activity:
Highlight the data by clicking on one of the blue dots. The set of dots should
now be selected for you. Click on Chart menu item then “add trendline”
Now you can select different types of trend lines. For this data set, the linear
approximation does not yield a good fit (by visual inspection) so try the
logarithmic approximation (this type works well for exponential type curves).
Next under “options” in the
“Format Trendline” window,
click on display equation on
chart and display R-squared
value on chart.
Under the “line” menu the
weight and color of the
trendline can be changed
as well.
PAGE 8
WATER RESOURCES
Water Pumping
Cumulative # of H2O molecules pumped
800
700
600
y = 382.0ln(x) - 1628.
R² = 0.998
500
400
data
300
Log. (data)
200
100
0
0
-100
50
100
150
200
250
300
350
400
450
Time in seconds
Now the equation of the trendline that to some degree “fits” the data collected
from the model is produced.
How closely does it match?
The quantitative value is R2, known as the “goodness of fit” is used to determine
how well the equation fits the data set. It is computed as the fraction of the total
variation of the Y values of data points that is attributable to the assumed model
curve, and its values typically range from 0 to 1. Values close to 1 indicate a
good fit. In this case, the goodness of fit is very high at 0.998.
Discussion:
Given this trendline equation, how could it be used to predict the behavior of
the model in the future? How would you test the prediction?
Should this trendline equation be used to make predictions about the future
behavior of the model? Why or why not?
For a discussion of curve fitting see http://www.aip.org/tip/INPHFA/vol-9/iss2/p24.html
Download