0% found this document useful (0 votes)
13K views25 pages

Exploring Simulations

Uploaded by

Mirayya Aidarova
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13K views25 pages

Exploring Simulations

Uploaded by

Mirayya Aidarova
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 25

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.

 Would that be considered a simulation and why?

Yes, it's a simulation because it is an abstraction of a real world


scenario that enables the drawing of inferences.
A simulation is an abstraction of a complex object or real world
phenomenon, typically made for the purposes of inquiry, education, or
entertainment.
3) A hospital develops a computer simulation to train doctors how to
converse with their patients about how they're feeling. The
simulation includes 3D animated patients that respond to the
doctor, based on a data set of actual patient responses.
The doctors all train using the simulation and the hospital evaluates the
quality of their patient conversations for a month after the simulation.
They discover that the doctors are conversing better with many
patients, but they are conversing worse with patients who aren't fluent
in the doctor's language. That's when they realize the simulation
contains bias favoring native speakers.
 What should the hospital do about the bias in the simulation?

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.

4) A company is developing a driving simulator to help emergency


responders understand how to drive a wide range of trucks, just
in case the responders find themselves in a situation where it's
necessary.
alwa
 What detail would be least important to include in the
simulation?
Roadside landscape that’s textured based on recent satellite imagery
Since the goal of the simulation is to learn how to drive a truck, the
scenery is not a crucial detail. That sort of detail would be more likely to
be included if the simulation was for entertainment purposes, like in a
video game.
5) Ashlynn is an industrial engineer who is trying to design a safer
parachute. She creates a computer simulation of the parachute
opening at different heights and in different environmental
conditions.

 What are advantages of running the simulation versus an actual


experiment? Note that there are 2 answers to this question.

The simulation can test the parachute design in a wide range of


environmental conditions that may be difficult to reliably reproduce
in an experiment.
A simulation can attempt to simulate a variety of environmental
conditions, limited only to the imagination of the creator and the
capabilities of the computer. An experiment is limited to only the
environmental conditions that are presently happening in the real
world.
The simulation can be run more safely than an actual experiment.
Simulations are often used when real-world experiments would be too
dangerous. That is the case here, where an unsafe parachute design
could hurt the parachuter.

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.

7) A researcher gathers data about the effect of Advanced


Placement®︎classes on students' success in college and career,
and develops a simulation to show how a sequence of AP classes
affect a hypothetical student's pathway.
Several school administrators are concerned that the simulation
contains bias favoring high-income students, however.
 Which of the following statements is true?

The simulation may accidentally contain bias due to the exclusion of


details.
All simulations must simplify what they are modeling, so a simulation
may contain bias based on which real world details were excluded or
included. The bias may be either accidental or intentional.

8) Dominic is an industrial designer who's developing an office chair


that is more comfortable for tall individuals. He hires a software
engineering firm to develop a simulation that can simulate the
chair used by a person working at a desk, and then come up with
an estimate of the resulting comfort level.

 Which detail is least necessary for this simulation?

The range of colors available for the chair's fabric


The goal of the simulation is to understand how comfortable the
person feels using the chair, but the color does not affect the comfort
level. That detail might be important to include in a simulation whose
goal was marketing, but not for this simulation.

9) A city government would like to make their streets more bike-


friendly with features such as protected bike lanes. However,
government officials are concerned about the effect on traffic
flow. They hire a software consultant agency to develop a
simulation of the traffic after the proposed changes.
 What are the most likely benefits of creating a computer
simulation of the proposal? Note that there are 2 answers to this
question.
10)
 What is a simulation?

An abstraction of a real world phenomenon that includes some details


and excludes others.
A simulation is an abstraction of a complex object or real world
phenomenon, typically made for the purposes of scientific inquiry,
education, or entertainment.

11) A hair care products company decides to use computer


simulation to develop a new anti-dandruff conditioner. The
simulation helps them choose the best ingredients, the ratio to
combine them at, and the optimal amount of time to leave the
conditioner in the hair.
When they do user testing to find out how well the conditioner works
on real hair, they see mixed results. Most of the testers reported less
dandruff after, but the testers with curly hair absolutely hated what it
did to their curls.

 What was most likely true about the simulation?


It did not include a representative range of hair types.
A simulation may contain (accidental or intentional) bias based on the
details it chooses to include or exclude. It seems likely that this
simulation excluded some hair types (such as curly hair) and was biased
against curly hair as a result.

12) Sylvia is an industrial engineer working for a sporting goods


company. She is developing a baseball bat that can hit balls with
higher accuracy and asks their software engineering team to
develop a simulation to verify the design.
 Which of the following details is most important to include in
this simulation?
Accurate accounting for the effects of wind conditions on the
movement of the ball
The goal of the simulation is to measure the accuracy of the ball hit,
and that accuracy is based on the physical forces between the bat and
the ball. It needs an accurate modeling of the effects of forces (wind
conditions, gravity, friction, etc.) that closely matches the effects on the
bat in the real world.

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:

 Which of these best describes what his program can draw?

2) An indie game developer is making a grid-based game and using


code to randomly spawn dogs on the game grid.
The following code spawns a dog:
row ← RANDOM(3, 5)
col ← RANDOM(2, 4)
DOG(row, col)
The procedure DOG draws the dog in a 5x5 grid, where the first
parameter represents which horizontal row to draw it in, and the
second parameter represents which vertical column to draw it in. The
rows and columns are both numbered 1 through 5.

 Which of these represents the possible spawn squares for the


dog?
3) A web developer is creating an online lottery scratch card.
This incomplete code segment decides whether the player wins a prize:
IF (<MISSING CONDITION>)
{
awardAmount ← 10
}
The code should only give the player a 3% chance of winning a prize.
 Which of these can replace <MISSING CONDITION> so that the
code works as intended? Note that there may
be multiple answers to this question.
4) A game developer is working on a soccer video game.
This incomplete code segment is run when a player attempts a goal
from outside the 6 yard box:
inGoal ← false
IF (<MISSING CONDITION>)
{
inGoal ← true
DISPLAY("Goal!")
}
ELSE
{
DISPLAY("Miss!")
}
At that distance, the code should give the player a 30% chance of
making the goal.

 Which of these can replace <MISSING CONDITION> so that the


code works as intended? Note that there are 2 answers to this
question.

RANDOM(1, 100) <= 30

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.

RANDOM(1, 10) <= 3


This condition is true for the three values of 1-3, and there are 10
possible values of 1-10. This condition correctly simulates a 30%
chance.
5) A digital artist is writing a program to draw a garden.
This is a segment of the code that draws a single flower:
xPos ← RANDOM(10, 380)
height ← RANDOM(40, 160)
FLOWER("red", xPos, 180, height)
The code relies on the FLOWER() procedure, which accepts four
parameters for the flower's color, x position, y position, and height.
Here's what's drawn from one run of the program:

 Which of these describes flowers that might be drawn from this


program?

A flower at an x position of 50 and a height of 40


This is possible, since 50 is in the range of x positions that can be
generated, and 40 is within the range of heights that can be generated.
A flower at an x position of 10 and a height of 160
This is possible, since 10 is the minimum x position that can be
generated, and 160 is the maximum height that can be generated.
6)
An indie game developer is making a grid-based game and using
code to randomly spawn monsters on the grid.
The following code spawns a monster:
row ← RANDOM(1, 3)
col ← RANDOM(3, 4)
MONSTER(row, col)
The procedure MONSTER draws the monster in a 5x5 grid, where the
first parameter represents which horizontal row to draw it in, and the
second parameter represents which vertical column to draw it in. The
rows and columns are both numbered 1 through 5.
 Which of these represents the possible spawn squares for the
monster?

7) A programmer is creating a simulation of a city where natural


disasters can randomly occur.
This incomplete code segment simulates a Godzilla disaster:
IF (<MISSING CONDITION>)
{
cityHealth ← cityHealth - 30
disasterMode ← "godzilla"
}
The code should only give Godzilla a 2% chance of storming the city.
 Which of these can replace <MISSING CONDITION> so that the
code works as intended? Note that there may
be multiple answers to this question.

RANDOM(1, 100) <= 2


This condition is true for the two values of 1 and 2, and there are 100
generated values. This condition correctly simulates a 2% chance.
RANDOM(1, 100) >= 98
8) A game developer is working on a basketball playing game.
This incomplete code segment simulates a player taking a shot:
shotMade ← false
IF (<MISSING CONDITION>)
{
shotMade ← true
DISPLAY("Score!")
}
ELSE
{
DISPLAY("Miss!")
}
The developer wants to give this player a 75% chance of making the
shot.
 Which of these can replace <MISSING CONDITION> so that the
code works as intended? Note that there are 2 answers to this
question.

RANDOM(1, 100) <= 75

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.

9) A digital artist is writing a program to draw a landscape with a


randomly generated mountain range.
This code draws a single mountain:
xPos ← RANDOM(4, 240)
height ← RANDOM(70, 120)
drawMountain(xPos, 80, height)
The code relies on the drawMountain() procedure, which accepts three
parameters for the mountain's x position, y position, and height.
Here's what's drawn from one run of the program:

 Which of these describes mountains that might be drawn from


this program? Note that there may be multiple answers to this
question.

A mountain at an x position of 4 and a height of 120


This is possible, since 4 is the minimum x position that can be
generated, and 120 is the maximum height that can be generated.
A mountain at an x position of 180 and a height of 110
This is possible, since 180 is in the range of x positions that can be
generated, and 110 is within the range of heights that can be
generated.
10) An indie game developer is making a frog-catching game and
using code to randomly spawn frogs on the game grid.
The following code spawns a frog:
row ← RANDOM(2, 5)
col ← RANDOM(2, 3)
FROG(row, col)
The procedure FROG draws the frog in a 5x5 grid, where the first
parameter represents which horizontal row to draw it in, and the
second parameter represents which vertical column to draw it in. The
rows and columns are both numbered 1 through 5.
 Which of these represents the possible spawn squares for the
frog?

11) A mobile game developer is programming a kitty simulator.


This incomplete code segment determines whether the kitty will meow:
IF (<MISSING CONDITION>)
{
DISPLAY("meow!")
}
The kitty should only meow 4% of the time.

 Which of these can replace <MISSING CONDITION> so that the


code works as intended? Note that there may
be multiple answers to this question.

RANDOM(1, 100) < 96

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.

RANDOM(1, 100) <= 4

12) A game developer is working on a basketball playing game.


This incomplete code segment simulates a player attempting a 3-
pointer shot:
shotMade ← false
IF (<MISSING CONDITION>)
{
shotMade ← true
score ← score + 3
DISPLAY("Score!")
}
ELSE
{
DISPLAY("Miss!")
}
The code should give the player a 40% chance of making the shot.
 Which of these can replace <MISSING CONDITION> so that the
code works as intended? Note that there are 2 answers to this
question.

RANDOM(1, 100) <= 40

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")
}
}

 Which statement best describes the variability in this


simulation?

Horse 1 races at a variable speed while horse 2 races at the same speed
throughout the race.

The value of horse1 increases by (RANDOM(1, 2) * 2) which will


evaluate to a random number between 1 and 2, multiplied by 2. The
value of horse2 increases by (RANDOM(1, 1) * 2) which will evaluate
to the number 1 multiplied by 2. That means that horse1 races at a
variable speed while horse2 races at a constant speed.

2) The following code simulates a piece of bread turning into toast:


temperature ← 350
breadColor ← "white"
moistureContent ← 30
numMinutes ← 10

REPEAT numMinutes TIMES {


IF (moistureContent > 0) {
moistureContent ← moistureContent - temperature/30
} ELSE {
IF (breadColor = "white") {
breadColor ← "yellow"
} ELSE {
breadColor ← "brown"
}
}
}
Which variables hold values that vary during the course of this
simulation? Note that there are 2 answers to this question.
breadColor
This variable is initialized to "white" at the beginning and changes to
"yellow" and then "brown" once the moistureContent reaches 0.
moistureContent
This variable is initialized to 30 at the beginning and decreases in each
iteration of the loop until it reaches 0.
3) The following code simulates the movement of a golf ball in the
air after it's been hit.
initialVelocity ← 44
accelFromGravity ← -9.8
x←0
y←0
t←0

REPEAT UNTIL (y < 0) {


x ← initialVelocity * t;
y ← (initialVelocity * t) + ((accelFromGravity * (t*t)) / 2)
DISPLAY(x)
DISPLAY(y)
t←t+1
}
 Which statement best describes why this simulation is an
abstraction?
It leaves out details that do not effect the results as much, such as air
resistance or golf ball material.

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.

4) The following code simulates the life cycle of a monarch butterfly.


stage ← "egg"
daysAsEgg ← 4
daysAsLarvae ← 12
daysAsPupa ← 12
daysAsAdult ← 36
daysInStage ← 0

REPEAT UNTIL (stage = "death") {


IF (stage = "egg" AND daysInStage ≥ daysAsEgg) {
stage ← "larvae"
daysInStage ← 0
}
IF (stage = "larvae" AND daysInStage ≥ daysAsLarvae) {
stage ← "pupa"
daysInStage ← 0
}
IF (stage = "pupa" AND daysInStage ≥ daysAsPupa) {
stage ← "adult"
daysInStage ← 0
}
IF (stage = "adult" AND daysInStage ≥ daysAsAdult) {
stage ← "death"
daysInStage ← 0
}
daysInStage ← daysInStage + 1
DISPLAY(lifeState)
}
 Which details are excluded from this simulation? Note that there
are 2 answers to this question.

Monarch butterflies that migrate live longer than monarchs that do


not.

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.

The code only has a single value for the variable daysAsLarvae (12), so it


does not capture the variability in the length of that stage. A simulation
often includes only the details needed for the purpose of the simulation
and excludes other details.

5) Kassidy develops a simulation of campfire smoke for a short film.


The following code segment is responsible for fading particles away:
1: particles ← [100, 100, 100, 1100]
2:
3: FOR EACH particle IN particles {
4: particle ← particle - 1
5: }
A particle with a value of 100 displays at full opacity and a particle with
a value of 0 is invisible.
She can use the following mathematical procedures:

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

REPEAT UNTIL (whoKnowsSecret ≥ townPopulation) {


whoKnowsSecret ← whoKnowsSecret * interactionsPerDay;
numDays ← numDays + 1
}
DISPLAY (numDays)
 Which variables hold values that vary during the course of this
simulation?
numDays
This variable is initialized to 0 at the beginning of the code and is
incremented in each iteration of the loop.
whoKnowsSecret
This variable is initialized to 1 at the beginning of the code and is
updated in each iteration of the loop.
7) The following code simulates the spread of virus particles
throughout a room in response to two people breathing and
speaking.
numCopies ← 0
numMinutes ← 10
people ← ["breathing", "breathing"]

REPEAT numMinutes TIMES {


FOR EACH person IN PERSONS {
IF (person = "breathing") {
numCopies ← numCopies + 20
} ELSE {
IF (person = "speaking") {
numCopies ← numCopies + 200
}
}
IF (RANDOM(1, 10) < 5) {
IF (person = "speaking") {
person ← "breathing"
} ELSE {
person ← "speaking"
}
}
}
DISPLAY(numCopies)
};
 Why is this simulation considered an abstraction?
It is a simplification of a more complex phenomena that captures
some aspects and leaves out others.
A simulation is an abstraction of a complex phenomena that captures
the higher-level details that are necessary for the purposes of the
simulation.
8) The following code simulates changing the temperature of water.
temperatureC ← -15
waterStage ← "solid"
meltingPoint ← 0
boilingPoint ← 100

REPEAT UNTIL (waterStage = "gas") {


temperatureC ← temperatureC + 1
IF (temperatureC > boilingPoint) {
waterStage ← "gas"
} ELSE {
IF (temperatureC > meltingPoint) {
waterStage ← "liquid"
}
}
}
 Which details are excluded from this simulation? Note that there
are 2 answers to this question.
The boiling point of water varies based on the atmospheric pressure.
This code only contains one variable for the boiling point of
water, boilingPoint and that variable never changes values, so this
simulation does not include the possibility of different boiling points. A
simulation often includes only the details needed for the purpose of the
simulation and excludes other details.
Water can exist as both a solid (ice) and as a liquid at 0 degrees
celsius.
This code contains a single variable for the stage of the
water, waterStage and that only holds one of three values solid, liquid,
or gas, so this simulation does not represent the detail that water can
be a mix of solid and liquid at 0 degrees. A simulation often includes
only the details needed for the purpose of the simulation and excludes
other details.
9) Deborah is creating a simulation to show the effect of rainfall on
blades of grass.
The following code segment simulates five blades of grass growing
during seven days:
1: blades ← [0, 0, 0, 0, 0]
2: rainPerDays ← [2, 0, 1, 2, 3, 1, 0]
3: FOR EACH dailyRain IN rainPerDays {
4: FOR EACH blade IN blades {
5: IF (dailyRain ≥ 1) {
6: blade ← blade + 0.3
7: }
8: }
9: }
 How can she change the simulation so that each blade of grass
grows at a variable rate?
Change line 6 to:
blade ← blade + (0.3 * RANDOM(1, 2))
This will increase each blade of grass by 0.3 multiplied by a random
number between 1 and 2, so there will be variation in the rates of
growth for each blade of grass.
10) The following code simulates a hurricane moving hour-by-
hour based on predicted wind directions:
hourlyWindDirections ← ["N", "N", "E", "E", "S"];
windSpeed ← 5
hurricaneLat ← 33
hurricaneLng ← 47

FOR EACH (direction IN hourlyWindDirections) {


IF (direction = "N") {
hurricaneLat ← hurricaneLat - 0.1 * windSpeed
}
IF (direction = "S") {
hurricaneLat ← hurricaneLat + 0.1 * windSpeed
}
IF (direction = "E") {
hurricaneLng ← hurricaneLng - 0.1 * windSpeed
}
IF (direction = "W") {
hurricaneLng ← hurricaneLng + 0.1 * windSpeed
}
}

 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

REPEAT numSeconds TIMES {


fuelBurned ← numEngines * engineFuelPerSec
fuelUsed ← fuelUsed + fuelBurned
weight ← weight - fuelBurned
}
DISPLAY(fuelUsed)
DISPLAY(weight)
 Which details are excluded from this simulation? Note that there
are 2 answers to this question.
The rocket engines burned different amounts of two types of fuel
(liquid oxygen and RP-1) each second.
The code only includes one variable representing the fuel burned per
second (engineFuelPerSec), so this simulation does not represent that
there were two types of fuel burned. A simulation often includes only
the details needed for the purpose of the simulation and excludes other
details.
The rocket burned different amounts of fuel per second at each stage
of launch.
The code only includes one variable representing the fuel burned per
second (engineFuelPerSec), since this code only simulates stage 1 of the
launch.

You might also like