Home | Random Algorithms | Simulation Games | Homework |
Team Teach Simulations
Ethan, Risha, Abby, Soumini
Defining Simulations:
Simulations are the process of modeling a real-world system or process using a computer program. It allows users to draw inferences and investigate various phenomenas without constraints and real barriers.
Simulation code is used in real life to model and predict complex systems, allowing people to test scenarios without real-world risks or costs. It’s widely used in many industries, including engineering, science, business, and healthcare.
Real Life Applications
1. Engineering & Manufacturing
- Product Testing: Engineers use simulation software like MATLAB, ANSYS, and SolidWorks to test designs before physically building prototypes.
- Structural Analysis: Simulating stress, heat, and forces on materials to ensure safety in buildings, bridges, and vehicles.
- Robotics: Testing robot movements and control algorithms in a virtual environment before real-world implementation.
2. Healthcare & Medicine
- Surgical Simulations: Virtual reality (VR) surgery training allows doctors to practice without risk to real patients.
- Drug Development: Simulating how drugs interact with cells, reducing the need for extensive animal or human testing.
- Epidemiology: Simulating the spread of diseases (e.g., COVID-19 models) to predict outbreaks and plan responses.
3. Business & Finance
- Market Simulations: Predicting stock market trends and investment risks.
- Supply Chain Optimization: Simulating transportation and logistics to improve efficiency and reduce costs.
- Risk Analysis: Banks and insurance companies simulate economic downturns to plan for financial stability.
4. Aerospace & Automotive
- Flight Simulators: Pilots train on realistic flight models before operating real aircraft.
- Crash Testing: Simulating car crashes to improve vehicle safety without destroying real cars.
- Space Exploration: NASA uses simulations to test space missions before launching.
5. Entertainment & Game Development
- Physics Engines: Games like Minecraft and GTA use physics simulations for realistic motion and interactions.
- AI Behavior Modeling: Simulating human-like AI characters for video games and virtual assistants.
- CGI & Animation: Special effects in movies use physics-based simulations for water, fire, and destruction scenes.
6. Environmental & Weather Science
- Climate Modeling: Predicting climate change effects using global simulation models.
- Weather Forecasting: Simulating atmospheric conditions to predict storms, hurricanes, and rainfall.
- Disaster Planning: Modeling tsunamis, earthquakes, and wildfires to prepare emergency responses.
Why Use Simulation Code?
- Saves Money – No need for physical prototypes.
- Reduces Risk – Test dangerous scenarios without real-world harm.
- Improves Accuracy – Allows for fine-tuned predictions and optimizations.
- Speeds Up Development – Quickly iterate on designs before production.
Examples
Dice Roll
This code utilizes the random.randint(1, 6) function to generate a random number between 1 and 6, just like an actual dice roll. Each time the program runs, it produces a different outcome, which replicates a real-life dice.
import random
def roll_dice():
return random.randint(1, 6)
dice_roll = roll_dice()
print("Number:", dice_roll)
Number: 5
Popcorn Hack #1
Instead of a dice roll, this time let’s create a number spinner. Use the set up of the dice roll example to simulate a number spinner. Create whatever range of numbers you want and share your range and output with the class when finished!
Rock Paper Scissors
This Python script lets the user play Rock-Paper Scissors against the computer. The Rock-Paper-Scissors game mimics a real-world game by using randomness to generate the outcomes. The computer’s choice is selected using random.choice(), which simulates the unpredictability of a real opponent. By repeatedly running this program, one can observe different possibilities and outcomes.
import random
def play_rock_paper_scissors():
choices = ['rock', 'paper', 'scissors']
computer_choice = random.choice(choices)
user_choice = input("Enter your choice (rock, paper, or scissors): ")
if user_choice not in choices:
print("Invalid choice. Please try again.")
return
print("Computer chose:", computer_choice)
print("You chose:", user_choice)
if user_choice == computer_choice:
print("It's a tie!")
elif (user_choice == 'rock' and computer_choice == 'scissors') or (user_choice == 'paper' and computer_choice == 'rock') or (user_choice == 'scissors' and computer_choice == 'paper'):
print("You win!")
else:
print("You lose!")
play_rock_paper_scissors()
Computer chose: scissors
You chose: scissors
It's a tie!
Popcorn Hack #2
Use the same code from the Rock, Paper, Scissors simulation. Run the cell in your notebook and when prompted to, type out your choice of the three moves. Share your output with the class!
College Board Application: Looking at MCQ’s
In our previous MCQ’s taken, questions on Big Idea 3.16 Simulations can be seen with code but also questions in conceptual form. Let’s practice both!
Predicting Births with a Computer Model
A population researcher is interested in predicting the number of births that will occur in a particular community. She created a computer model that uses data from the past ten years, including number of residents and the number of babies born. The model predicted that there would be 200 births last year, but the actual number of births last year was only 120.
Which of the following strategies is LEAST likely to provide a more accurate prediction?
- A: Gathering data for additional years to try to identify patterns in birth rates
- B: Refining the model used in the computer simulation to more closely reflect the data from the past ten years
- C: Removing as many details from the model as possible so that calculations can be performed quickly
- D: Taking into consideration more information about the community, such as the ages of residents
Mouse and Predator Simulations
A researcher wrote a program to simulate the number of mice in an environment that contains predators. The program uses the following procedures.
Procedure Call | Explanation |
---|---|
InitialMousePopulation() |
Returns the number of mice at the start of the simulation |
InitialPredatorPopulation() |
Returns the number of predators at the start of the simulation |
NextDayPopulation(numberOfMice, numberOfPredators) |
Based on the current numbers of mice and predators, returns the number of mice after one day |
Code for the simulation is shown below.
days ← 0
numMice ← InitialMousePopulation()
numPredators ← InitialPredatorPopulation()
REPEAT UNTIL (days = 365)
{
numMice ← NextDayPopulation(numMice, numPredators)
days ← days + 1
}
DISPLAY("There are")
DISPLAY(numMice)
DISPLAY("mice after one year.")
Based on the code, which of the following assumptions is made in the simulation?
- A: The number of mice increases by 1 each day.
- B: The number of mice does not change from day to day.
- C: The number of predators increases by 1 each day.
- D: The number of predators does not change from day to day.