Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
DataScienceUWL
GitHub Repository: DataScienceUWL/DS775
Path: blob/main/Lessons/Lesson 10 - Simulation/Self_Assess_Solns_10.ipynb
871 views
Kernel: Python 3 (system-wide)

Lesson 10 - Self-Assessment Solutions

Self-Assessment: Simulation - Solution

Answer: True

Self-Assessment: Simulating a System - Solution

Answer: True

Self Assessment: Simulation and Time - Solution

Answer: True

Self-Assessment: Generalizing Simulation Results - Solution

Answer: False. Generalizing beyond he conditions of the simulation could lead to erroneous results.

Self-Assessment: Type of Simulation - Solution

Answer:

a. The number of products sold over time. (yes)

b. The air pressure in submarine during its time under the water. (no)

c. The arrival of customers to a queue. (yes)

d. Whether is rains or not in a day over a 10-year period. (yes)

e. The temperature of an engine over a period of operation. (no)

Self-Assessment: Discrete-Event Simulation - Solution

(b) A baseball pitcher who throws a strike 60 percent of the time and a ball 40 percent of the time.

Let 0 <= rand <= 0.6 correspond to strikes and 0.6 < rand <= 1 correspond to balls.

Random observations:

0.3039 = strike

0.7914 = ball

0.8543 = ball

0.6902 = ball

0.3004 = strike

0.0383 = strike

Note that the results would be different if you make the arbitrary choice that 0 to 0.4 corresponds to balls and 0.4 to 1 correspond to strikes.

(c) The color of a traffic light found by a randomly arriving car when it is green 40 percent of the time, yellow 10 percent of the time, and red 50 percent of the time.

One way is to let 0 <= rand <= 0.4 correspond to green lights, 0.4 < rand <= 0.5 correspond to yellow lights, and 0.5 < rand <=1 correspond to red lights.

Random observations:

0.3039 = green

0.7914 = red

0.8543 = red

0.6902 = red

0.3004 = green

0.0383 = green

Self-Assessment: Discrete-Event Simulation 2 - Solution

(a) Since the data for sales covers 25 days, the number of days for each number of sales can be used to estimate the probability of selling that number of stoves on any given day as

P(2)=425P(2)=\frac{4}{25}, P(3)=725P(3)=\frac{7}{25}, P(4)=825P(4)=\frac{8}{25}, P(5)=525P(5)=\frac{5}{25}, P(6)=125P(6)=\frac{1}{25}.

(b) For a discrete random variable like this, the mean is computed analytically as

μ=2425+3725+4825+5525+6125=3.68\mu = 2 \cdot \frac{4}{25} + 3 \cdot \frac{7}{25} + 4 \cdot \frac{8}{25} + 5 \cdot \frac{5}{25} + 6 \cdot \frac{1}{25} = 3.68.

(e) See the following cell for the simulation. How close is the simulated answer to the exact answer given in part (b)?

# Simulation for Textbook Problem 20.3 (e) import numpy as np np.random.seed(seed=222) # for reproducible results SimSize = 300 dailySales = np.zeros(SimSize) for i in range(SimSize): salesResult = np.random.uniform(low=0.0, high=1.0, size=1) if salesResult <= 0.16: dailySales[i] = 2 elif (salesResult > 0.16 and salesResult <= 0.44): dailySales[i] = 3 elif (salesResult > 0.44 and salesResult <=0.76): dailySales[i] = 4 elif (salesResult > 0.76 and salesResult <=0.96): dailySales[i] = 5 else: dailySales[i] = 6 print(f"The average of daily sales over 300 days is {np.mean(dailySales):.2f}.")
The average of daily sales over 300 days is 3.72.

Alternately you can use numpy.random.choice as follows:

import numpy as np np.random.seed(seed=222) # for reproducible results SimSize = 300 dailySales = np.random.choice([2,3,4,5,6],size=SimSize,p=[.16,.28,.32,.20,.04]) print(f"The average of daily sales over 300 days is {np.mean(dailySales):.2f}.")
The average of daily sales over 300 days is 3.72.

Self-Assessment: Simulation Results - Solution

Answer: False. Simulations have inherent variability, so they provides only statistical estimates rather than exact results.

Self-Assessment: Simulating Outcomes - Solution

Answer: random number generator.

*Self-Assessment: Random Variables in Simulation - Solution

Answer: False. An effort should be made to determine a distribution that most closely models the physical process.

Self-Assessment: Simulation Reproducibility - Solution

Answer: seed.