Exploring Simulations
Exploring Simulations
Exploring Simulations
1) A biologist puts tracking devices on birds all over the world and
records the geographical coordinates of their movement.
They then use that data to create a computer simulation that predicts
the territory of a bird based on an initial geographic location.
What is a benefit of the computer simulation?
It can be run for a wide range of initial values.
Since a computer simulation is a program, it can accept parameters to
control its output. In this case, the biologist can input geographic
coordinates as parameters and run the simulation for many
coordinates.
2) Jack is trying to plan his financial future using an online tool. The
tool starts off by asking him to input details about his current
finances and career. It then lets him choose different future
scenarios, such as having children. For each scenario chosen, the
tool does some calculations and outputs his projected savings at
the ages of 35, 45, and 55.
They should add details to the simulation that better represent the
diversity of the doctors' patients.
Simulations may contain (accidental or intentional bias) due to the
details they choose to include or exclude. In this case, the simulation
likely did not include conversations with patients who weren't fluent in
the doctor's language, and the exclusion of that detail made for a less
useful simulation.
6)
What is always true of a simulation of a natural phenomenon?
It abstracts away some details of the real world.
A simulation is a representation of a natural phenomenon or real-life
situation that must abstract away some details, since the real world is
infinitely complex.
Creating Simulations
1) A digital artist is writing a program to draw a face.
This is the part of the code that draws the eyes and pupils:
eyeSize ← RANDOM(5, 20)
CIRCLE("white", 20, 20, eyeSize)
CIRCLE("white", 40, 20, eyeSize)
pupilSize ← RANDOM(2, 5)
CIRCLE("black", 20, 20, pupilSize)
CIRCLE("black", 40, 20, pupilSize)
The code relies on the CIRCLE() procedure from a drawing library, which
accepts four parameters for the circle's fill color, x position, y position,
and diameter.
Here's what's drawn from one run of the program:
This condition is true for the 30 values of 1-30, and is false for the 70
values of 31-100. This correctly simulates a 30% chance.
This condition is true for the 75 values of 1-75, and is false for the 25
values of 76-100. This correctly simulates a 75% chance.
RANDOM(1, 4) <= 3
This condition is true for the values of 1, 2, and 3, and the generated
values are 1, 2, 3, or 4. This condition correctly simulates a 75% chance.
This condition is true for the four values of 1, 2, 3, and 4, and there are
100 generated values. This condition correctly simulates a 4% chance.
This condition is true for the 40 values of 1-40, and is false for the 60
values of 41-100. This correctly simulates a 40% chance.
RANDOM(1, 5) <= 2
This condition is true for the two values of 1 and 2, and there are 5
generated values of 1-5. This condition correctly simulates a 40%
chance.
Second Part
1) The following code segment simulates a race between two
horses:
raceLength ← 200
horse1 ← 0
horse2 ← 0
REPEAT UNTIL (horse1 ≥ raceLength OR horse2 ≥ raceLength) {
horse1 ← horse1 + (RANDOM(1, 2) * 2)
horse2 ← horse2 + (RANDOM(1, 1) * 2)
}
IF (horse1 = horse2) {
DISPLAY("tie")
} ELSE {
IF (horse1 > horse2) {
DISPLAY("Horse 1 won")
} ELSE {
DISPLAY("Horse 2 won")
}
}
Horse 1 races at a variable speed while horse 2 races at the same speed
throughout the race.
The code does not include any variables related to whether the
butterfly migrates and only has a single value for the
variable daysAsAdult. A simulation often includes only the details
needed for the purpose of the simulation and excludes other details.
Some Monarch butterflies remain in larvae form for 8 days and others
for 15 days.
Name Description
MIN(a, b) Returns the smaller of the two arguments.
MAX(a, b) Returns the greater of the two arguments.
POW(a, b) Returns a raised to the power of b.
RANDOM(a, Returns a random integer from a to b,
Name Description
b) including a and b.
What line of code could replace line 4 to introduce variability
into the simulation?
particle ← particle - RANDOM(1, 5)
RANDOM(1, 5) will evaluate to a random number between 1 and 5 each
time it is called, so this should introduce variability into the simulation.
6) The following code simulates the spread of a secret throughout a
small town of gossipy individuals.
whoKnowsSecret ← 1
interactionsPerDay ← 6
townPopulation ← 140
numDays ← numDays + 1
Which variables hold values that vary during the course of this
simulation? Note that there are 2 answers to this question.
hurricaneLat
This variable is initialized to 33 and changes whenever the direction is
either "N" or "S" (which happens 3 times in the course of this
simulation).
hurricaneLng
This variable is initialized to 47 and changes whenever the direction is
either "E" or "W" (which happens 2 times in the course of this
simulation).
11) The following code simulates the feeding of 4 fish in an
aquarium while the owner is on a 5-day trip:
numFish ← 4
foodPerDay ← 20
foodLeft ← 160
daysStarving ← 0
REPEAT 5 TIMES {
foodConsumed ← numFish * foodPerDay
foodLeft ← foodLeft - foodConsumed
IF (foodLeft < 0) {
daysStarving ← daysStarving + 1
}
}
Why is this simulation considered an abstraction?
It simplifies a real-world scenario into something that can be modeled
in code and executed on a computer.
A simulation is an abstraction of a complex phenomena that captures
the higher-level details that are necessary for the purposes of the
simulation and excludes other details.
12) The following code simulates the fuel burned by the Saturn
V rocket in the first stage of launch:
weight ← 2800000
engineFuelPerSec ← 2578
numSeconds ← 165
numEngines ← 5
fuelUsed ← 0