First Order of Business: Get your notebook

  • Open a terminal in vscode, run command: cd _notebooks, type 'wget' and paste this link into said terminal and run it

  • Take notes wherever you please, but you will be graded on participating

So, what is a simulation anyway?

  • A simulation is a tested scenario used for viewing results/outputs to prepare for them in real world situations

  • These can be used for games like dice rolling, spinners, etc

  • These can be used for practical things such as building structures, testing car crashes, and other things before engaging in them in the real world

  • These simulations can have the option of obeying real world physics (Gravity, collision) or they can go against these norms since this is a fictitious scenario, and couldn't happen in real life

Big Question

  • Which of the following simulations could be the LEAST useful?

  • A retailer trying to identify which products sold the most

  • A restaurant determining the efficiency of robots
  • An insurance company studying the rain impact of cars
  • A sports bike company studying design changes to their new bike design
  • If you guessed a bike company, you're wrong, because the retail simulation was the right answer. Simulating robots in food service, sudying rain impact on vehicles, and new bike design can contribute a lot more to society in comparison to seeing what products sell more than others.

NOTE: you can't stimulate statistics.

Next Big Question

If you were making a simulation for making a new train station, which of the following would be true about this simulation?

  • It could reveal potential problems/safety issues before construction starts
  • It cannot be used to test the train station in different weather
  • Simulation will add high costs to projects
  • Simulation is not needed because this train station already exists
  • Potential Saftey was the right answer, because you need somewhere to test the safety and ethicness of what you're about to do before you start building it. Otherwise, let's just say you'll have a special plaque for FBI's Most Wanted

Simulation 1:

Both programs below do the same thing. Given a height and a weight, they calculate how long it will take for a object to fall to the ground in a vacuum subjected to normal Earth levels of gravity.

However, the second one is a simulation. It calculates the distance the object has fallen every 0.1 seconds. This is useful for if you wanted a visual representation of a falling object, which pure math can't do as smoothly.

height = float(input("height in meters?"))

weight = input("weight in pounds?")

stuff = (2 * (height / 9.8))**(1/2)

print("It will take", stuff,"seconds for an object that weighs",weight,"pounds","to fall ",height,"meters in a vacuum")
It will take 2.0203050891044216 seconds for an object that weighs 20 pounds to fall  20.0 meters in a vacuum
t = 0
g = 0
d = 0
false = True
while false:
    t = t + 0.1
    d = 9.8 / 2 * (t**2)
    if d >= height:
        false = False
    #print(d) # if you want to print the distance every time it calculates it. Too long to output to a terminal, but this could be useful to display graphically. 
    #print(t)

print(t)
print(d)
2.1000000000000005
21.609000000000012

Simulation 2:

  • This simulation is made in order to simulate movement on a 2d plane vs a 3d plane.

  • How it works: we have multiple variables, if statements and equations under a while command in order to randomy generate steps on a 2d plane. Once it reaches the set destination, it will say that the man made it home after x amount of steps.

  • For the 3D plane, it takes a lot longer due to how big and open the 3d environment is, so there are more if statements in the 3d plane

(explain further)

import random
x = 0
y = 0
nights = 0
turn = 0
stopped = 0
turns = []

while (nights < 100):
    step = random.randrange(4)
    if step == 0:
        x = x+1
    if step == 1:
        x = x-1
    if step == 2:
        y = y+1
    if step == 3:
        y = y-1

    turn = turn + 1

    if x == 0 and y == 0:
        nights = nights + 1
        print("The Man Has Made It Home After ", turn, "Turns")
        turns.append(turn)
        turn = 0
    if turn/1000 % 1000 == 0 and x + y != 0:
        print("(", x,y, ")")
    if (turn > 10000000):
        stopped = stopped + 1
        turn = 0
        x = 0
        y = 0
        nights = nights + 1
        print("Caped")

average = sum(turns) / len(turns)
print("Avaerage", average, "Ones that when't too long ", stopped)
( -455 453 )
( -988 656 )
( -1174 1104 )
( -1218 2710 )
( 745 2799 )
( -41 3645 )
( 886 3532 )
( 244 3588 )
( 345 3989 )
( 949 5367 )
Caped
The Man Has Made It Home After  6 Turns
The Man Has Made It Home After  6 Turns
( -815 -395 )
( -1404 26 )
( -579 -159 )
( -2176 -648 )
( -2217 -3 )
( -1250 -452 )
( -853 -1191 )
( -449 -807 )
( -1781 -647 )
( -2520 598 )
Caped
The Man Has Made It Home After  2 Turns
The Man Has Made It Home After  4 Turns
The Man Has Made It Home After  6 Turns
The Man Has Made It Home After  763428 Turns
The Man Has Made It Home After  378 Turns
The Man Has Made It Home After  2 Turns
The Man Has Made It Home After  1260 Turns
The Man Has Made It Home After  82 Turns
( -28 -360 )
( -1916 -1018 )
( -632 226 )
( -1190 1534 )
( -1546 3464 )
( -855 3313 )
( -206 2944 )
( 231 2971 )
( 203 3677 )
( -472 4834 )
Caped
The Man Has Made It Home After  2 Turns
The Man Has Made It Home After  2 Turns
( 542 310 )
( 463 655 )
( 839 723 )
The Man Has Made It Home After  3509138 Turns
The Man Has Made It Home After  2 Turns
The Man Has Made It Home After  2 Turns
The Man Has Made It Home After  282 Turns
The Man Has Made It Home After  39660 Turns
The Man Has Made It Home After  2 Turns
The Man Has Made It Home After  60 Turns
The Man Has Made It Home After  137326 Turns
The Man Has Made It Home After  2 Turns
The Man Has Made It Home After  108 Turns
( -1124 66 )
( -654 424 )
( -1527 693 )
( 253 607 )
( 303 1175 )
( 835 755 )
( 906 1558 )
( 886 1754 )
( 626 2280 )
( 1362 1506 )
Caped
The Man Has Made It Home After  890 Turns
The Man Has Made It Home After  32 Turns
The Man Has Made It Home After  374 Turns
( 1441 -971 )
( 461 -341 )
( 205 459 )
( 1353 707 )
( 1125 509 )
( 2508 -154 )
( 2623 1371 )
( 2235 2073 )
( 2989 2079 )
( 4116 2572 )
Caped
The Man Has Made It Home After  216770 Turns
The Man Has Made It Home After  56 Turns
The Man Has Made It Home After  2 Turns
The Man Has Made It Home After  2 Turns
The Man Has Made It Home After  38 Turns
The Man Has Made It Home After  84 Turns
The Man Has Made It Home After  20 Turns
The Man Has Made It Home After  786 Turns
The Man Has Made It Home After  4 Turns
The Man Has Made It Home After  3924 Turns
The Man Has Made It Home After  60 Turns
The Man Has Made It Home After  4 Turns
The Man Has Made It Home After  2 Turns
The Man Has Made It Home After  14 Turns
The Man Has Made It Home After  2 Turns
The Man Has Made It Home After  2 Turns
( -592 0 )
( -709 -915 )
( -175 257 )
( -379 -201 )
( -747 -561 )
( -952 -394 )
( -599 -1421 )
( -753 -1193 )
( 2 -1610 )
( 398 -984 )
Caped
( -975 689 )
( -1018 1022 )
( -288 1912 )
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
/Users/SreejaGangapuram_1/vscode/Sreeja-Gangapuram/_notebooks/2022-12-12-Simulations.ipynb Cell 10 in <cell line: 9>()
     <a href='vscode-notebook-cell:/Users/SreejaGangapuram_1/vscode/Sreeja-Gangapuram/_notebooks/2022-12-12-Simulations.ipynb#X12sZmlsZQ%3D%3D?line=26'>27</a> if turn/1000 % 1000 == 0 and x + y != 0:
     <a href='vscode-notebook-cell:/Users/SreejaGangapuram_1/vscode/Sreeja-Gangapuram/_notebooks/2022-12-12-Simulations.ipynb#X12sZmlsZQ%3D%3D?line=27'>28</a>     print("(", x,y, ")")
---> <a href='vscode-notebook-cell:/Users/SreejaGangapuram_1/vscode/Sreeja-Gangapuram/_notebooks/2022-12-12-Simulations.ipynb#X12sZmlsZQ%3D%3D?line=28'>29</a> if (turn > 10000000):
     <a href='vscode-notebook-cell:/Users/SreejaGangapuram_1/vscode/Sreeja-Gangapuram/_notebooks/2022-12-12-Simulations.ipynb#X12sZmlsZQ%3D%3D?line=29'>30</a>     stopped = stopped + 1
     <a href='vscode-notebook-cell:/Users/SreejaGangapuram_1/vscode/Sreeja-Gangapuram/_notebooks/2022-12-12-Simulations.ipynb#X12sZmlsZQ%3D%3D?line=30'>31</a>     turn = 0

KeyboardInterrupt: 
import random
x = 0
y = 0
z = 0
nights = 0
turn = 0
stopped = 0
turns = []

while (nights < 100):
    #rando movement
    step = random.randrange(6)
    if step == 0:
        x = x+1
    if step == 1:
        x = x-1
    if step == 2:
        y = y+1
    if step == 3:
        y = y-1
    if step == 4:
        z = z+1
    if step == 5:
        z = z-1
    #Turn counter
    turn = turn + 1
    #Goal check
    if x == 0 and y == 0 and z == 0:
        nights = nights + 1
        print("The Bird Has Made It Home After ", turn, "Turns")
        turns.append(turn)
        turn = 0
    if turn/1000 % 1000 == 0 and x + y + z != 0:
        print("(", x,y, ") ","| ", z)
    #Too long Stoper
    if (turn > 10000000):
        stopped = stopped + 1
        turn = 0
        x = 0
        y = 0
        z = 0
        nights = nights + 1
        print("Caped")

average = sum(turns) / len(turns)
print("Avaerage", average,"Ones that when't too long ", stopped)
The Bird Has Made It Home After  2 Turns
( -1192 258 )  |  98
( -1808 782 )  |  -108
( -696 889 )  |  811
( -65 -120 )  |  901
( -443 1227 )  |  1346
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
/Users/SreejaGangapuram_1/vscode/Sreeja-Gangapuram/_notebooks/2022-12-12-Simulations.ipynb Cell 11 in <cell line: 10>()
     <a href='vscode-notebook-cell:/Users/SreejaGangapuram_1/vscode/Sreeja-Gangapuram/_notebooks/2022-12-12-Simulations.ipynb#X13sZmlsZQ%3D%3D?line=25'>26</a> turn = turn + 1
     <a href='vscode-notebook-cell:/Users/SreejaGangapuram_1/vscode/Sreeja-Gangapuram/_notebooks/2022-12-12-Simulations.ipynb#X13sZmlsZQ%3D%3D?line=26'>27</a> #Goal check
---> <a href='vscode-notebook-cell:/Users/SreejaGangapuram_1/vscode/Sreeja-Gangapuram/_notebooks/2022-12-12-Simulations.ipynb#X13sZmlsZQ%3D%3D?line=27'>28</a> if x == 0 and y == 0 and z == 0:
     <a href='vscode-notebook-cell:/Users/SreejaGangapuram_1/vscode/Sreeja-Gangapuram/_notebooks/2022-12-12-Simulations.ipynb#X13sZmlsZQ%3D%3D?line=28'>29</a>     nights = nights + 1
     <a href='vscode-notebook-cell:/Users/SreejaGangapuram_1/vscode/Sreeja-Gangapuram/_notebooks/2022-12-12-Simulations.ipynb#X13sZmlsZQ%3D%3D?line=29'>30</a>     print("The Bird Has Made It Home After ", turn, "Turns")

KeyboardInterrupt: 

NOTE: these simulations need to be capped at some point.

Simulations in the wild

Simulations are used extremely frequently in real life applications. One of the most common examples of simulations are video games. A games physics engine can accurately simulate objects colliding

Another example is Blender, the software used in 3d animations class, here at Del Norte. Blender is made up of many small simulations, but one big one it uses is simulating the way light bounces off of and interacts with objects.

HW !!!

Create a simulation. It can be anything, just has to simulate something.

Some ideas:

  • Two objects colliding
  • Gravity on other planets

AND

Find an example of a simulation in a software/game you use, screenshot, and explain how it is a simulation

Random Card Picking Simulation

import random

# Initializing lists for card signs and numbers
signs =['Heart','CLUB','DIAMOND','SPADE']
numbers =['A', '2', '3', '4', '5',' 6', '7', '8', '9', '10', 'J', 'Q', 'K']

# initializing sign with random sign from signs and number with random number from numbers
sign = random.choice(signs)
number = random.choice(numbers)

print('Card picked from deck of cards is: ', sign, ' ', number)
Card picked from deck of cards is:  CLUB   7

Images

Example of a Simulation + Explanation

One popular example of a simulation is are VR glasses. The built-in LED screen and eyes of VR headsets are separated by stereoscopic lenses, which distort the image to make it appear three-dimensional and lifelike. These lenses allow the headset to transmit two images, one for each eye, much like how we see. They are used for entertainment, flight simulations, for the training of soilders, etc. Users get to experiance different conditions without actually having to be in a battle or any other place.