Objectives

  1. Understand how computers can be used to represent real-world phenomena or outcomes
  2. Compare simulations with real-world contexts.
  3. Implement code to mimic real world situations, problems, or phenomena.

What are simulations by College Board definition?

  • Simulations are abstractions that mimic more complex objects or phenomena from the real world
    • Purposes include drawing inferences without the constraints of the real world
  • Simulations use varying sets of values to reflect the changing state of a real phenomenon
  • Often, when developing a simulation, it is necessary to remove specific details or simplify aspects
    • Simulations can often contain bias based on which details or real-world elements were included/excluded
  • Simulations allow the formulation of hypotheses under consideration
  • Variability and randomness of the world is considered using random number generators
  • Examples: rolling dice, spinners, molecular models, analyze chemicals/reactions...

Analyzing an Example: Air-Traffic Simulator

  • Say we want to find out what the optimal number of aircrafts that can be in the air in one area is.
  • A simulation allows us to explore this question without real world contraints of money, time, safety
    • Unfortunately we can't just fly 67 planes all at once and see what happens
  • Since the simulation won't be able to take all variables into control, it may have a bias towards one answer
  • Will not always have the same result

Functions we often need (python)

import random # a module that defines a series of functions for generating or manipulating random integers
random.choice() #returns a randomly selected element from the specified sequence
random.choice(mylist) # returns random value from list
random.randint(0,10) #randomly selects an integer from given range; range in this case is from 0 to 10
random.random() #will generate a random float between 0.0 to 1.

Functions we often need (js)

// Math.random(); returns a random number
// Math.floor(Math.random() * 10); // Returns a random integer from 0 to 9:

College Board Question 1

Question: 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

    }

}

  • This simulation simplifies a real-world scenario into something that can be modeled in code and executed on a computer.
  • Summarize how the code works:

  • The code defines various variables (numfish, foodPerDay, foodLeft, daysStarving) for the simulation.

  • The code then iterates 5 times (representing 5 days), where each day total food consumption is calculated as the product of the number of fish and the food each fish consumes per day. This consumption is then subtrated from the total remaining food left to update the amount of remaining food.
  • Additionally, if the food remaining is found to be negative, then the totla number of days starving will then increment with each iteration, providing the total number of days where the fish starve.

Examples

Card Flip

import random

cards = ["Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"] 
suits = ["Diamonds", "Hearts", "Spades", "Clubs"]

print(random.choice(cards) + " of " + random.choice(suits))
7 of Spades

Coin Flip

import random

def coinflip():         #def function 
    randomflip = random.randint(0, 99) #picks any random vlaue from 0 to 100
    if randomflip >= 25: # if th evalue is greater than or equal to 25, we have heads
        print("Heads")
    else:
        #assigning 1 to be tails--> if 1 is chosen then it will print, "Tails"
        print("Tails")

#Tossing the coin 5 times:
t1 = coinflip()
t2 = coinflip()
t3 = coinflip()
t4 = coinflip()
t5 = coinflip()
Heads
Heads
Heads
Tails
Heads

Your turn: Change the code to make it simulate the flipping of a weighted coin.

We can change the range from 0 to 99 to simulate percentages and various results

Adding images (in Python)

  • Add a heads and tails images into your images directory with the correct names and run the code below
import random

# importing Image class from PIL package
from PIL import Image
 
# creating a object
im = Image.open(r"../images/head.png")
image = Image.open(r"../images/tails.png")

i=random.randint(0,1)

if i == 1:
    print("heads")
    display(im)

else:
    print("tails")
    display(image)
tails

In order to display an image in python, we can use the PIL package we previously learned about.

Spin the Wheel

import random

print("Spin the wheel!")
print("----------------------------------")

n = 300
blue = 0
red = 0
res = ""
count = 0
for i in range(n):
    spin = random.randint(1,2)
    if spin == 1: # head
        blue = blue + 1
        res = res + "🟦"
    else:         # tail
        res = res + "🟥"
        red = red + 1
    count += 1
    if count %10 == 0:
        res = res + "\n"
 
print('Number of blue:', blue)
print('Number of red:', red)
print("Frequency:")
print(res)
Spin the wheel!
----------------------------------
Number of blue: 160
Number of red: 140
Frequency:
🟥🟦🟥🟦🟥🟥🟥🟦🟦🟦
🟥🟥🟥🟥🟥🟥🟥🟥🟦🟥
🟥🟦🟦🟥🟦🟥🟦🟦🟦🟦
🟦🟦🟥🟥🟥🟦🟦🟦🟦🟥
🟦🟦🟥🟦🟦🟦🟥🟥🟦🟥
🟦🟥🟦🟥🟦🟥🟦🟦🟦🟥
🟦🟥🟥🟦🟦🟦🟦🟥🟦🟥
🟦🟦🟦🟦🟥🟥🟦🟦🟦🟥
🟥🟦🟥🟦🟦🟦🟥🟥🟥🟥
🟥🟦🟦🟥🟦🟦🟥🟥🟦🟦
🟦🟦🟦🟥🟦🟥🟦🟦🟥🟥
🟥🟦🟦🟦🟥🟥🟥🟦🟥🟦
🟦🟥🟦🟦🟦🟥🟦🟥🟦🟥
🟦🟥🟥🟥🟦🟦🟥🟥🟦🟥
🟥🟥🟦🟦🟦🟥🟥🟦🟥🟥
🟦🟥🟦🟥🟦🟥🟥🟥🟦🟥
🟦🟦🟥🟦🟦🟥🟦🟦🟥🟦
🟦🟦🟦🟥🟥🟥🟥🟦🟦🟥
🟥🟥🟦🟦🟦🟦🟦🟦🟥🟦
🟦🟥🟥🟦🟦🟥🟦🟥🟥🟦
🟦🟥🟦🟦🟦🟥🟥🟥🟥🟥
🟥🟦🟥🟦🟦🟥🟥🟥🟥🟥
🟦🟥🟦🟦🟦🟥🟦🟥🟦🟦
🟦🟦🟦🟥🟥🟦🟦🟦🟦🟥
🟥🟦🟦🟥🟥🟦🟥🟦🟦🟦
🟦🟥🟥🟦🟥🟥🟦🟦🟥🟦
🟥🟦🟦🟥🟦🟥🟥🟥🟦🟥
🟥🟥🟦🟦🟥🟦🟦🟥🟦🟦
🟥🟥🟦🟦🟦🟥🟦🟥🟦🟥
🟦🟦🟥🟥🟦🟥🟦🟦🟦🟥

Your turn: Add a visual to the simulation!

Population Growth and Plots

import random

totalPopulation = 50 
growthFactor = 1.00005
dayCount = 0 #Every decade the population is reported

while totalPopulation < 1000000:
    totalPopulation *= growthFactor
    #Every year, population is reported
    dayCount += 1
    if dayCount == 3650: 
        dayCount = 0
        print(totalPopulation)
50.9208542158382
51.858667881412835
52.813753340339744
53.786428688693455
54.777017880950645
55.785850837884915
56.81326355644857
57.85959822167812
58.925203320660756
60.01043375859973
61.11565097701727
62.241223074134794
63.38752492746948
64.55493831868948
65.74385206076818
66.95466212748006
68.18777178528205
69.4435917276238
70.72254021173039
72.02504319790533
73.35153449139965
74.70245588689163
76.07825731562963
77.47939699528389
78.90634158255773
80.35956632861088
81.83955523734335
83.3468012265958
84.88180629231839
86.44508167576318
88.03714803375506
89.65853561210007
91.3097844221855
92.99144442083431
94.70407569347027
96.44824864065797
98.2245441680769
100.03355387999595
101.8758802763092
103.75213695320225
105.66294880751367
107.60895224485932
109.59079539159139
111.60913831065932
113.66465322144792
115.75802472366284
117.88995002534043
120.06113917505603
122.27231529840951
124.52421483886611
126.81758780303201
129.15319801044888
131.53182334798672
133.95425602892402
136.42130285679806
138.93378549411435
141.4925407360063
144.0984207889343
146.7522935545166
149.4550429185883
152.20756904558516
155.01078867834698
157.86563544344372
160.77306016212518
163.734031166995
166.74953462452112
169.82057486348165
172.9481747094634
176.13337582551767
179.37723905909223
182.68084479535142
186.04529331700488
189.47170517076083
192.96122154053157
196.51500462750866
200.1342380372423
203.82012717384515
207.5738996414592
211.39680565311517
215.2901184471228
219.25513471112933
223.29317501398702
227.40558424557713
231.59373206473057
235.85901335540058
240.20284869123515
244.626684808708
249.13199508895974
253.72028004851637
258.39306783904266
263.1519147563015
267.99840575848543
272.9341549940971
277.96080633954836
283.08003394665883
288.2935428002461
293.6030692859769
299.0103817686772
304.51728118129796
310.12560162472494
315.8372109786336
321.6540115235985
327.57794057465344
333.610971126528
339.75511251076193
346.01241106492347
352.3849508141526
358.8748541652548
365.4842826135819
372.21543746292775
379.0705605586826
386.0519350344942
393.1618860726737
400.4027816786111
407.7770334694529
415.2870974772987
422.93547496720146
430.72471327022237
438.65740663183334
446.7361970759445
454.9637752848425
463.3428814953356
471.87630641140623
480.5668921336672
489.4175331059368
498.4311770792509
507.6108260936226
516.9595374778909
526.4804248679748
536.1766592438927
546.0514699858688
556.1081459498903
566.3500365630875
576.7805529392721
587.4031690150229
598.2214227067058
609.2389170887882
620.459321593865
631.8863732347806
643.523877849258
655.3757113674577
667.4458211028706
679.7382270669931
692.2570233082117
705.0063792753502
717.9905412063193
731.213833542354
744.680660368286
758.3955068793517
772.3629408750013
786.5876142802376
801.0742646949576
815.8277169718325
830.8528848232548
846.1547724578696
861.7384762472576
877.6091864233018
893.7721888068244
910.2328665680552
926.9967020195277
944.0692784419823
961.4562819439134
979.1635033553559
997.1968401565474
1015.5622984421193
1034.265994921452
1053.3141589558786
1072.713134633408
1092.4693828816492
1112.5894836196626
1133.0801379494264
1153.9481703876918
1175.2005311388937
1196.844298409981
1218.8866807678355
1241.335019540112
1264.1967912603318
1287.4796101579543
1311.191230694346
1335.339550145443
1359.93261123198
1384.978604798156
1410.4858725396355
1436.4629097818006
1462.9183683091562
1489.8610592468467
1517.2999559952555
1545.244197218641
1573.7030898888052
1602.6861123848373
1632.2029176499327
1662.2633364063552
1692.8773804296109
1724.0552458829216
1755.8073167131035
1788.1441681089966
1821.0765700235877
1854.6154907609919
1888.7721006295103
1923.5577756619539
1958.9841014044832
1995.0628767752467
2031.8061179940596
2069.22606258447
2107.3351734495286
2146.1461430226273
2185.6718974947685
2225.925601119707
2266.9206605983704
2308.670729544025
2351.189713029678
2394.491772219253
2438.5913290840067
2483.503071205865
2529.2419566692024
2575.8232190426706
2623.2623724528535
2671.575216751305
2720.7778427767857
2770.886637714385
2821.9182905533635
2873.8897976454996
2926.818468365819
2980.721930877568
3035.6181380033663
3091.5253732044625
3148.4622566701805
3206.4477515194208
3265.50117011645
3325.6421805029754
3386.8908129486813
3449.2674666224266
3512.7929163862764
3577.4883197146887
3643.3752237411036
3710.4755724343454
3778.8117139071587
3848.4064078593556
3919.282833158067
3991.464595557577
4064.9757355613347
4139.840736428758
4216.084532329526
4293.732516648041
4372.810550440771
4453.344971049467
4535.362600872911
4618.890756300287
4703.957256808981
4790.590434230076
4878.819142184374
4968.672765692212
5060.181230960366
5153.375015349066
5248.285157522649
5344.943267787152
5443.381538618298
5543.632755383342
5645.730307260403
5749.708198358917
5855.60105904487
5963.444157474623
6073.273411341135
6185.125399836549
6299.037375835086
6415.047278300283
6533.193744920753
6653.516124978702
6776.054492455376
6900.849659377905
7027.943189411969
7157.377411704782
7289.195434983045
7423.441161910489
7560.159303709923
7699.3953950544965
7841.195809233308
7985.607773596205
8132.679385283114
8282.459627243066
8434.998384548171
8590.346461008141
8748.555596090737
8909.678482153824
9073.768781994897
9240.881146723708
9411.071233964098
9584.395726391067
9760.912350609216
9940.6798963789
10123.758236196467
10310.208345235023
10500.092321652606
10693.473407274272
10890.416008655091
11090.985718531107
11295.249337665295
11503.274897095924
11715.131680794615
11930.890248741764
12150.622460426874
12374.401498781694
12602.301894554219
12834.399551131517
13070.771769819734
13311.497275589658
13556.656243296562
13806.330324382723
14060.602674071937
14319.557979064812
14583.282485744028
14851.864028899145
15125.392060980459
15403.95768189162
15687.653669330835
15976.574509691063
16270.816429529066
16570.477427614267
16875.65730756763
17186.457711101873
17502.982151873675
17825.33604995953
18153.626766966256
18487.963641788483
18828.458027024546
19175.223326062882
19528.375030851705
19888.030760364294
20254.310299772224
20627.335640341
21007.231020059335
21394.122965017476
21788.140331547384
22189.414349138955
22598.078664146615
23014.269384301042
23438.125124040398
23869.787050676667
24309.398931412117
24757.107181221745
25213.06091161743
25677.411980310368
26150.315041788
26631.92759882248
27122.410054927906
27621.925767783323
28130.6411036399
28648.725492730202
29176.35148569761
29713.694811065183
30260.9344337631
30818.252614733767
31385.834971634602
31963.870540659176
32552.551839496547
33152.07493145028
33762.63949073847
34384.448868995845
35017.710163001495
35662.634283653424
36319.436026213385
36988.334141845466
37669.5514104724
38363.31471497371
39069.85511674996
39789.40793267885
40522.21281348906
41268.51382357688
42028.55952229309
42802.60304672725
43590.90219601571
44393.71951720349
45211.322392686554
46043.983129265034
46891.97904883628
47755.59258075859
48635.111355915375
49530.828302512455
50443.0417436389
51372.05549662546
52318.17897423212
53281.72728769992
54263.021351700285
55262.387991216776
56280.160050396735
57316.67650340569
58372.282567325514
59447.329817129816
60542.17630277828
61657.18666846682
62792.73227407432
63949.19131884581
65126.948967353725
66326.39747777894
67547.93633255432
68791.97237141423
70058.91992689493
71349.20096232988
72663.24521238665
74001.49032619284
75364.38201309637
76752.37419111219
78165.9291381017
79605.51764573608
81071.61917629711
82564.72202236338
84085.3234694394
85633.92996157831
87211.05727005652
88817.23066515314
90452.98509109447
92118.86534421994
93815.42625442879
95543.23286996954
97302.86064563192
99094.89563440469
100919.93468266429
102778.58562895708
104671.46750644306
106599.2107490685
108562.45740153427
110561.86133313309
112598.08845552354
114671.81694451514
116783.73746593866
118934.55340567556
121124.9811039244
123355.75009378171
125627.60334421635
127941.29750751943
130297.60317131132
132697.30511518952
135141.20257210292
137630.10949454195
140164.85482562834
142746.28277519898
145375.25310097422
148052.64139490548
150779.33937479474
153556.2551812861
156384.3136803259
159264.4567711956
162197.64370021442
165184.85138022146
168227.07471594284
171325.32693534848
174480.63992711355
177694.06458429378
180966.67115433107
184299.54959550442
187693.80993994625
191150.58266334436
194671.0190614534
198256.29163353852
201907.5944728821
205626.14366448362
209413.17769008293
213269.95784064257
217197.76863642607
221197.91825481562
225271.7389660071
229420.58757672738
233645.845882129
237948.92112600128
242331.24646946148
246794.28146827564
251339.51255897147
255968.453553904
260682.64614543717
265483.6604194141
270373.0953780809
275352.5794726432
280423.7711456283
285588.3593832415
290848.06427788804
296204.63760106056
301659.8633867754
307215.55852575245
312873.5733705427
318635.79235179414
324504.1346058756
330480.5546140496
336567.04285342665
342765.62645990215
349078.36990330165
355507.3756749683
362054.7849880047
368722.7784904156
375513.5769913844
382429.4422009236
389472.67748314975
396645.6286234323
403950.6846096651
411390.2784279354
418966.8878728387
426683.03637272434
434541.2938301333
442544.27747771755
450694.6527499253
458995.1341707345
467448.48625774035
476057.52444289223
484825.1160101862
493754.1810506305
502847.6934347941
512108.68180327216
521540.2305753888
531145.4809764803
540927.6320840907
550889.9418934493
561035.7284025573
571368.3707172631
581891.3101766931
592608.0514994079
603522.1639506654
614637.2825311796
625957.109187782
637485.4140463693
649226.0366675665
661182.8873255101
673359.9483101845
685761.2752537436
698390.9984812613
711253.3243863562
724352.5368321568
737692.9985780552
751279.1527327537
765115.5242340589
779206.7213559411
793557.4372433398
808172.451475245
823056.6316565482
838214.9350392374
853652.410173425
869374.1985887953
885385.5365070227
901691.7565857139
918298.2896944819
935210.6667237249
952434.5204267111
969975.5872956044
987839.7094720285

Here we initialize the total population to be 50, then set the growth factor as 1.00005 (.005 percent change). It will print the population every 56th day until it reaches one million. It multiplies the current population by the growth factor in each iteration, and increments the day count. When the day count reaches 56, it prints the current population and resets the day count to 0.

Note! This simulation assumes that the growth factor remains constant as time progresses, which may not be a realistic assumption in real-world scenarios.

import matplotlib.pyplot as plt

# Define the initial population and growth rate
population = 100
growth_rate = 0.05

# Define the number of years to simulate
num_years = 50

# Create lists to store the population and year values
populations = [population]
years = [0]

# Simulate population growth for the specified number of years
for year in range(1, num_years+1):
    # Calculate the new population size
    new_population = population + (growth_rate * population)
    # Update the population and year lists
    populations.append(new_population)
    years.append(year)
    # Set the new population as the current population for the next iteration
    population = new_population
    
# Plot the population growth over time
plt.plot(years, populations)
plt.xlabel('Year')
plt.ylabel('Population')
plt.title('Population Growth Simulation')
plt.show()

If we create quantative data, we can plot it using the Matplotlib library.

Example on how simplification can cause bias

import random

beak =  ["small-beak", "long-beak", "medium-beak"],
wing = ["small-wings", "large-wings", "medium-wings"],
height = ["short", "tall","medium"]


naturaldisaster = ["flood", "drought", "fire", "hurricane", "dustbowl"]


print("When a" , random.choice(naturaldisaster) , "hit",  random.choice(height), "birds died") 
When a drought hit tall birds died

How does this simulation have bias?

This simulation only selects traits from the heights of the birds, but does not take into accoount the other factors of the bird. Also, it is completely random

JS examples

Hacks

  • Answer all questions and prompts in the notes (0.2)
  • Create a simulation
    1. Create a simulation that uses iteration and some form of data collection (list, dictionary...) (0.4)
      • try creating quantative data and using the Matplotlib library to display said data
      • Comment and describe function of each parts
      • How does your simulation help solve/mimic a real world problem?
      • Is there any bias in your simulation? Meaning, are there any discrepancies between your program and the real event?
  • Answer these simulation questions (0.3)
  • Bonus: take a real world event and make a pseudocode representation or pseudocode on a flowchart of how you would make a simulation for it (up to +0.1 bonus)
from random import randint
import matplotlib.pyplot as plt
from scipy import stats
import numpy as np

total_dice_rolls, snake_eyes = [0], [0]

def snakeEyesSimulation(num_of_iterations):
    for i in range(num_of_iterations):              # Here we generate a data
        if randint(1,6) == randint(1,6):            # If a snake eyes is found, add the new value to our array
            snake_eyes.append(snake_eyes[i]+1)
        else:
            snake_eyes.append(snake_eyes[i])        # Otherwise we keep the current count
        total_dice_rolls.append(total_dice_rolls[i]+1)

    totalnp = np.array(total_dice_rolls)            # Convert our lists into np arrays to perpform statistical analysis
    snakenp = np.array(snake_eyes)
    slope, intercept, rvalue, pvalue, stderr = stats.linregress(totalnp,snakenp) # Perform linear regression, gives us our data values
    line = slope*totalnp+intercept                                               # Get our best fit line
    frequency = str(snake_eyes[-1]/num_of_iterations * 100)[:5] + "%"            # Get our frequency
    plt.style.use('fivethirtyeight')                                             # Spice up our style
    plt.plot(totalnp, line, 'r', label='y={:.2f}x+{:.2f}'.format(slope,intercept))
    plt.plot(total_dice_rolls, snake_eyes)
    plt.plot([], [], ' ', label=f"Frequnecy={frequency}")                        # Some lables to make it fancy
    plt.plot([], [], ' ', label=f"r={rvalue}")
    plt.plot([], [], ' ', label=f"p={pvalue}")
    plt.plot([], [], ' ', label=f"standard deviation={stderr}")
    plt.xlabel('# of dice rolls')                                                # Axis lables
    plt.ylabel('# of Snake eyes')       
    plt.title('Frequency of snake eyes versus total number of d6 dice rolls', fontdict={'fontsize': 15})
    plt.ylim(-1000,num_of_iterations)
    plt.xlim(-1000,num_of_iterations)
    plt.scatter(totalnp,snakenp)                                                 # Graph the data points in a scatter plot
    plt.legend(fontsize=12)
    plt.show()                                                                   # Display the graph

snakeEyesSimulation(10000)

The program that I created above could provide insight towards a popular probability game called snake eyes. The game essentially works by granting the user a win if they roll two dice rolls with the same number. My simulation makes use of the python random module to create randomized dice rolls, then counts the total number of dice roles and the number of total snake eyes that we have. This could solve the real-world problem of gambling, as it shows the small chances of winning the game of snake eyes with an efficient computer simulation

Despite being simple, this algorithm does contain a few inherant biases. This is because the random number generators in python are actually pseudorandom, meaning that they use pre-determined seed values to generate "random values". In reality, these values aren't random, and with any same seed, the program will generate the same result. Thus, this algorithm isn't completely random, but it still provides a good representation. Over the many times I've ran this program, I have consistently gotten a frequency of 16-17% with different seeds, showing how small the chances are to win a game of snake eyes.

Simulation questions:

A theme park wants to create a simulation to determine how long it should expect the wait time at its most popular ride. Which of the following characteristics for the virtual patrons would be most useful? Select two answers

  • A. Ride preference—denotes whether a patron prefers roller coasters, other thrill rides, gentle rides, or no rides.
  • B. Walking preference—denotes how far a patron is willing to walk in between rides.
  • C. Food preference—denotes the type of food that a patron prefers to eat (e.g., chicken, burgers, salads).
  • D. Ticket type—denotes whether the patron has a single-day pass, a multi-day pass, or an annual pass.

The correct answer for this would be A and B, as walking preference shows us how often people will go to a ride, which can give us statistics on how much people arrive at a particular ride, and overall ride perference also allows us find what rides are the most popular, allowing us to predict the waiting time

A programmer has created a program that models the growth of foxes and rabbits. Which of the following potential aspects of the simulation does NOT need to be implemented?

  • A. A representation of grass that rabbits must eat frequently to survive.
  • B. Each rabbit may only have a certain amount of children per litter.
  • C. Each fox must eat a rabbit frequently to survive.
  • D. Each rabbit can only live to a certain age, assuming that they are not eaten.

The correct answer is A, as the type of grass the rabbits consume is not of importance as options B-D, which all have direct impacts on rabbit and fox populations as they model the survivability and reproductivity of foxes and rabbits

The heavy use of chemicals called chlorofluorocarbons (CFCs) has caused damage to the Earth’s ozone layer, creating a noticeable hole over Antarctica. A scientist created a simulation of the hole in the layer using a computer, which models the growth of the hole over many years. Which of the following could be useful information that the simulation could produce?

  • A. The approximate length of time until the hole would be refilled (due to various atmospheric processes)
  • B. The exact size of the hole at any given point in time
  • C. The exact length of time until the hole would be refilled (due to various atmospheric processes)
  • D. The exact depth of the hole at any point in time

The correct answer is A, as we may never be sure of anything "exact" about a computer simulation, which renders options B through D as invalid options

Suppose that an environmentalist wanted to understand the spread of invasive species. What would be a benefit of doing this with a simulation, rather than in real life?

  • A. The species used in the simulation could be designed to mimic many different species at once.
  • B. The species created could be quickly tested in multiple environments to better understand how its spread is affected by environmental factors.
  • C. The simulation could be run much more quickly than in real life.
  • D. All of the above

The correct answer is D. This is because a simulation allows us direct control over our environment, and since it is simulated on the machine, we can reset this environment however many times we wish. Thus, this grants us efficiency, duplicity, and flexibility.

A program is being created to simulate the growth of a brain-based on randomly determined environmental factors. The developer plans to add a feature that lets the user quickly run several hundred simulations with any number of factors kept constant. Why would this be useful? Select two answers.

  • A. It would allow the user to gather data without taxing the computer’s hardware.
  • B. It would allow the user to see the effect of specific variables by ensuring that the others do not change.
  • C. It would quickly provide the user with a large amount of data.
  • D. It would make simulations more detailed.

The correct answer would be B and C. Since we can freely keep certain factors constant, we can use this to analyze individual factors and variables to ensure that we can observe trends for all effects. Additionally, option C is also right as we can run the simulation many times over in a matter of hours on a computer, instead of over many years with actual human participants or subjects.

Which of the following statements describes a limitation of using a computer simulation to model a real-world object or system?

  • A. Computer simulations can only be built afer the real-world object or system has been created.
  • B. Computer simulations only run on very powerful computers that are not available to the general public.
  • C. Computer simulations usually make some simplifying assumptions about the real-world object or system being modeled.
  • D. It is difficult to change input parameters or conditions when using computer simulations.

The correct answer would be C. Many phenomenons in real life and nature have many miniscule and lurking factors that all contribute to the final outcome. The sheer amount of details in nature is too complex and plentiful for modern computers to fully simulate. Thus, even the most detailed and powerful simulations today still make many assumptions about smaller factors in order to have better efficiency and usability. Additionally, many factors are unknown, making them hard to implement.

Pseudo-code for real-life event

For this code, I will be analyzing the traffic at a stop light point

Intersections ← 4

hoursToRun ← INPUT()

Jams ← 0

    REPEAT hoursToRun TIMES {

        Traffic1 ← RANDOM(100,200)

        Traffic2 ← RANDOM(250,300)

        Traffic3 ← RANDOM(50,75)

        Traffic4 ← RANDOM(400,600)

        AverageTraffic ← (Traffic1+Traffic2+Traffic3+Traffic4)//Intersections

        IF (AverageTraffic > 350) {

            Jams ← Jams + 1

        }
    }

DISPLAY("FREQUENCY OF TRAFFIC JAMS: ")
DISPLAY(Jams/hoursToRun)