Module 9 2 Simulations Angela B Shiflet and
Module 9. 2 Simulations Angela B. Shiflet and George W. Shiflet Wofford College © 2014 by Princeton University Press
Computer simulation • Having computer program imitate reality, in order to study situations and make decisions • Use computer simulations if (1) Not feasible to do actual experiments (example: The Lawrence Livermore Laboratory scientists have studied the greenhouse effect, making predictions based on level of various pollutants).
Use simulations if • System does not exist (The Boeing company designed the Boeing 777 airplane completely using computer-aided design and tested the designs using computer simulations before construction began). • Cost of actual experiments prohibitive (the Los Alamos National Laboratory scientists used simulations to predict the behavior of nuclear reactions before testing a nuclear bomb during World War II) • Money • Time • Danger • Want to test alternatives (the National Oceanographic and Atmospheric Administration performs simulations to predict the path and intensities of hurricanes).
Disadvantages of Computer Simulations • Maybe expensive in time or money to develop. • Because it is impossible to test every alternative, we can provide good solutions but not the best solution. • The result may be difficult to verify because often we don not have real-world data. • We cannot be sure we understand what the simulation actually does. • When a simulation is probabilistic, involving an element of chance, we should be careful of our conclusion.
Monte Carlo simulation • Probabilistic model involving element of chance • Not deterministic • Uses random number generator
Monte Carlo simulation
Monte Carlo simulation
Monte Carlo simulation
Monte Carlo simulation
Monte Carlo simulation Measure of quality To obtain a better estimate, we can • The number of darts in one simulation to be larger • Run many simulations, then take the average. This technique allows to use the standard deviation σ as a measure of the quality of the overall estimate. About 68. 3% (empirical rule) of the estimates are within 1 standard deviation of the mean (i. e. (μ – σ, μ + σ). Thus, a small standard deviation σ relative to the mean indicates a certain consistency for most simulations and gives us more confidence in the men as an estimate.
Monte Carlo simulation Simulation development In the long run, we will save time and improve the quality of our work if we start by analyzing and formulating the simulation model on paper (follow the basic five steps of modeling process). Make the computer code readable and understandable. Each function should be short (no more than 30 lines) and test it before implementation (also easier to find the computer bug This way).
Monte Carlo simulation
Random Number Generator: Multiplicative Linear Congruential Method • random 0 = 10 (called the seed) • randomn = (7 * randomn - 1 + 1) mod 11, for n > 0 • Generates: • 5, 3, 0, 1, 8, 2, 4, 7, 6, 10 before the sequence starts repeating. A maximum of 11 number is generated with mod 11. • If we need float points numbers between 0 and 1, divide each number by the modulus, 11.
Multiplicative Linear Congruential Method • random 0 = seed • randomn = (multiplier * randomn – 1 + increment ) modulus, for n > 0 • modulus often largest integer comp. can store, such as 231 - 1 = 2, 147, 483, 647 • One multiplier: 16, 807 and an increment 0 produces a sequence of 231 – 2 elements. • Not all choices of multiplier and modulus are good. For example, consider r 0 = 10 and rn = (5 rn-1 + 1) mod 11. This only produces 5 numbers: 7, 3, 5, 4, 10 before repeating.
Random floating point number • For random number, suppose rand, is a uniformly distributed random floating-point number with 0. 0 ≤ rand < 1. 0 • rand = randomn/modulus • Example r 0 = 10, rn = (7 * rn - 1) mod 11, for n > 0 • Integers: 10, 4, 6, 9, 8, 1, 7, 5, 2, 3 • Floating point: 10/11, 4/11, …, 3/11
Random floating point number min ≤ r < max • For 0 ≤ rand < 1, if we need a random floating-point number from a min number to a maximum number, then • r = (max - min) rand + min • min ≤ r < max • Example: random floating point number between 20. 0 and 26. 3 using 6. 3 rand + 20. 0
Random integer min ≤ max • For 0 ≤ rand < 1 • n = int( (max - min + 1) rand + min) where int( ) is function returns the integer part of a number. • This way we have min ≤ max where max is a number that is included in the random number generated. • Example: random integer between 20 and 26, inclusively is int(7 rand + 20).
- Slides: 17