14
Modeling and Simulation Dr. X

Modeling and Simulation Dr. X. Topics Random Numbers Monte Carlo Simulation

Embed Size (px)

Citation preview

Modeling and Simulation

Dr. X

Topics

• Random Numbers• Monte Carlo Simulation

Monte Carlo Simulation

• Probabilistic model• Element of chance• Rare event simulation

John von Neumann

• Quantum theory• Logic• Game theory• Economics• Theory and applications of Computer Science• Monte Carlo Simulation– WWII– How system neutrons would behave

Multiplicative linear congruential generator

• Lehmer• Generate 10 random numbers– r0=10

– rn = (7rn-1+1)mod11, n>0

• What is r0?• How do we know it will only generate 10

numbers?

Ranges of random numbers

• Math.random: 0<r<1• What if we want a range 0…99? 100…500?

Throwing darts

• Calculus: calculate area• What would you do if area cannot be

calculated?

Throwing darts

𝑎𝑟𝑒𝑎=(𝑎𝑟𝑒𝑎𝑜𝑓 𝑒𝑛𝑐𝑙𝑜𝑠𝑖𝑛𝑔𝑟𝑒𝑐𝑡𝑎𝑛𝑔𝑙𝑒)( ¿𝑑𝑎𝑟𝑡𝑠𝑏𝑒𝑙𝑜𝑤¿𝑑𝑎𝑟𝑡𝑠 )

Monte Carlo Algorithm

Monte Carlo algorithm to estimate area between x-axis and f from SMALLEST_X to LARGEST_XMAX_Y number greater than or equal to all f(x) in the intervalNUMDARTS number of darts to be thrownNumHitsBelow 0Do the following NUMDARTS times:

randomX random number between SMALLEST_X and LARGEST_XrandomY random number between 0 and MAX_Yif(randomY < f(randomX))

increment NumHitsBelow by 1AreaOfRectangle (LARGEST_X – SMALLEST_X) *(MAX_Y)

EstimatedArea (AreaOfRectangle)*(NumHitsBelow)/ NUMDARTS

Random Numbers from Distributions

• Distribution: description of the portion of times each possible outcome or each possible range of outcomes occurs on average

• Discrete • Continuous

Generate random numbers from discrete distribution

Generate rand, a uniform random floating point number [0, 1)If rand < p1, then return e1

else if rand < p1+ p2, then return e2

…else if rand < p1+ p2+…+pn-1, then return en-1

else return en

Generate random numbers from discrete distribution

Generate random numbers from continuous distribution

Reverse the distribution– Normal – Box Muller

x = b * sin(a) + μ and x = b * cos(a) + μ where:

a = random number between [0, 2π)rand = uniform random number between [0,1)b = σ

– Exponentialx = 1/a * log(rand) where:rand = uniform random number between [0,1)

References

• Introduction to computational science, Angela Shiflet, George Shiflet, Princeton University Press