Presentation is loading. Please wait.

Presentation is loading. Please wait.

Modeling and Simulation

Similar presentations


Presentation on theme: "Modeling and Simulation"— Presentation transcript:

1 Modeling and Simulation
Dr. X

2 Topics Random Numbers Monte Carlo Simulation

3 Monte Carlo Simulation
Probabilistic model Element of chance Rare event simulation

4 John von Neumann Quantum theory Logic Game theory Economics
Theory and applications of Computer Science Monte Carlo Simulation WWII How system neutrons would behave

5 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?

6 Ranges of random numbers
Math.random: 0<r<1 What if we want a range 0…99? 100…500?

7 Throwing darts Calculus: calculate area
What would you do if area cannot be calculated? 𝑓 𝑥 = cos⁡(𝑥) 2 +1

8 Throwing darts 𝑎𝑟𝑒𝑎=(𝑎𝑟𝑒𝑎 𝑜𝑓 𝑒𝑛𝑐𝑙𝑜𝑠𝑖𝑛𝑔 𝑟𝑒𝑐𝑡𝑎𝑛𝑔𝑙𝑒) #𝑑𝑎𝑟𝑡𝑠 𝑏𝑒𝑙𝑜𝑤 # 𝑑𝑎𝑟𝑡𝑠
𝑎𝑟𝑒𝑎=(𝑎𝑟𝑒𝑎 𝑜𝑓 𝑒𝑛𝑐𝑙𝑜𝑠𝑖𝑛𝑔 𝑟𝑒𝑐𝑡𝑎𝑛𝑔𝑙𝑒) #𝑑𝑎𝑟𝑡𝑠 𝑏𝑒𝑙𝑜𝑤 # 𝑑𝑎𝑟𝑡𝑠 The more darts we throw, the more accurate the results

9 Monte Carlo Algorithm Monte Carlo algorithm to estimate area between x-axis and f from SMALLEST_X to LARGEST_X MAX_Y  number greater than or equal to all f(x) in the interval NUMDARTS  number of darts to be thrown NumHitsBelow  0 Do the following NUMDARTS times: randomX  random number between SMALLEST_X and LARGEST_X randomY  random number between 0 and MAX_Y if(randomY < f(randomX)) increment NumHitsBelow by 1 AreaOfRectangle  (LARGEST_X – SMALLEST_X) *(MAX_Y) EstimatedArea  (AreaOfRectangle)*(NumHitsBelow)/ NUMDARTS

10 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

11 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

12 Generate random numbers from discrete distribution

13 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 = σ ln⁡(𝑟𝑎𝑛𝑑) Exponential x = 1/a * log(rand) where:

14 References Introduction to computational science, Angela Shiflet, George Shiflet, Princeton University Press


Download ppt "Modeling and Simulation"

Similar presentations


Ads by Google