Monte Carlo Simulation
Monte Carlo simulation basics
• Random number generator• Start with unit uniform random number (r)
• r is uniformly distributed from 0 to 1
0.0 0.2 0.4 0.6 0.8 1.0
Unit, Uniform random number generator
• Excel• RAND()
• Basic• RND
• Do not use random between• There is not enough discrimination
Procedure for generating 1000 Uniform random numbers in Excel
Step 1 Step 2 Step 3
Input formula for randomnumber “=Rand()” in cell A1
Copy and paste the formula from A1 and type here A1:A1000, press <ENTER> twice.
1000 Uniform random numbers are generated. Press F9 several times to generate a new set.
Exercise: Simulate flipping a coin
• Simulate• 10 coin flips
• 100 coin flips
• 1000 coin flips
• 10 000 coin flips
• Use the running average
• How many coin flips do you need to be within 1% deviation:49% and 51%
How many trials?
• Steady-state• A steady-state solution is reached when the output of the simulation from one iteration
to the next changes negligibly
• When calculating means and variances: 1 000 iterations is usually sufficient
• If calculating confidence limits, many more iterations are required; after all, for 99% confidence limits the sample size for the number of random deviates exceeding the confidence limit is 1/100th the number of iterations
• How many coin flips are needed to reach steady-state?
• What is your error?
• Take coin flipping example to steady state
Simulation of 1000 coin flips in Excel
Use formula “=IF(RAND()<0.5,1,0)”
Generating random numbers
• Set r equal to F(x) for the desired distribution and solve for x
• Exponential distribution example
Normal random number generators
• Excel• Use the Normal inverse function
• Slow with large data sets
• Uses numerical integration
• Fast alternative <Random2.xls>
( ) μσπ += )rcos(2)2ln(r-x21
Simulate a Normal random variable
• Mean = 50
• Standard deviation = 4
• Generate 1000 random numbers with Excel
• Verify in Jasp or another software package
• How many outliers?
•P = V2/R• Voltage (V) is Normally distributed
• mean = 12
• standard deviation = 0.1
• Resistance (R) is Normally distributed• mean = 2
• standard deviation = 0.2
Where does input data come from?
• Current production
• Discuss how to obtain mean and standard deviation for voltage and resistance
1. What does the power distribution look like?• Specifications
• 72 ± 10
• Will this circuit design meet specifications?
2. Change standard deviation of voltage to 0.3 and standard deviation of resistance to 0.4
• What is the mean and standard deviation of power?
3. Change standard deviation of voltage to 0.5 and standard deviation of resistance to 0.6
• Simulation can be used to model systems when inputs are known
• Verify all inputs
• Validate models
• Models may be useful even if incomplete