Professional Documents
Culture Documents
BITF21M510 Assigment MonteCarlo Simulation
BITF21M510 Assigment MonteCarlo Simulation
Afeef wadood
BITF21M533
Assigment
MONTE CARLO SIMULATION:
Monte Carlo simulation is a statistical technique used for modeling and
analyzing complex systems or processes through random sampling and
probability. It's named after the Monte Carlo Casino in Monaco because
of the element of chance and randomness inherent in the method.
First Problem:
John is a dentist who schedule all her patients for 30 minutes
appointment. Some of his patients take more or less than 30 minutes
depending on type of dental work to be done.
The following summary shows various categories of work, their possible
& time required to complete work:
Filling 45 min 40
crown 60 min 15
cleaning 15 min 15
1|Page
extracting 45 min 10
checkup 15 min 20
Simulate dentist's clinic for four hours & find out average waiting time
for patients as well as illness of doctor. Assume all patients show up at
clinic at exactly their scheduled, arrival time starting at 8:00am.
Use following random numbers for handling above problem: 40, 82, 11,
34, 25, 66, 17, 79
2|Page
print(f"{name} arrives at {env.now} minutes for a {appointment_type}
appointment.")
yield request
3|Page
# Start patient arrivals
env.process(generate_patient_arrivals(env, dentist))
OUTPUT:
Second Problem:
Monte Carlo Simulations to estimate value of PI
4|Page
Using Monte Carlo simulation to estimate the value of π by simulating
random points within a unit square and calculating the ratio of points
inside a quarter of a unit circle.
import random
def monte_carlo_pi(num_samples):
inside_circle = 0
for _ in range(num_samples):
x = random.uniform(0, 1)
y = random.uniform(0, 1)
if x**2 + y**2 <= 1:
inside_circle += 1
estimated_pi = monte_carlo_pi(num_samples)
print(f"The estimated value of π using {num_samples} samples: {estimated_pi}")
OUTPUT:
5|Page