Static Model Simulation - Monte Carlo Simulation Examples Examples - - PowerPoint PPT Presentation

static model simulation monte carlo simulation examples
SMART_READER_LITE
LIVE PREVIEW

Static Model Simulation - Monte Carlo Simulation Examples Examples - - PowerPoint PPT Presentation

Static Model Simulation - Monte Carlo Simulation Examples Examples 1 Coin-tossing experiment. Toss the coin for 1 million times and note down the outcomes. 1 2 Rolling-die experiment. Roll the die for 1 million times and note down the


slide-1
SLIDE 1

Static Model Simulation - Monte Carlo Simulation — Examples

Examples

1 Coin-tossing experiment. 1

Toss the coin for 1 million times and note down the outcomes.

2 Rolling-die experiment. 1

Roll the die for 1 million times and note down the outcomes.

3 Simulate π. 4 Evaluate the definite integral

b

a

g(x)dx.

5 Coin-tossing problem. 6 Birthday and nearly birthday problems. 7 Lottery problem. R.B. Lenin (rblenin@daiict.ac.in) () Introduction to Discrete SimulationIntroduction Autumn 2007 28 / 46

slide-2
SLIDE 2

Evaluating definite integral

Example (· · · )

Let I = b

a

g(x)dx. Let X = U[a, b] and Y = (b − a)g(X). E[Y ] = E[(b − a)g(X)] = (b − a)E[g(X)] = (b − a) b

a

g(x)fX(x)dx = (b − a) b

a

g(x) 1 b − adx = b

a

g(x)dx = I.

R.B. Lenin (rblenin@daiict.ac.in) () Introduction to Discrete SimulationIntroduction Autumn 2007 29 / 46

slide-3
SLIDE 3

Evaluating definite integral · · ·

Example (· · · )

Algorithm:

1 Set sum = 0 and count = 0. 2 while (count <= n)

Generate r from U[a, b] Compute: y = (b − a)g(r) sum = sum + y count = count + 1 endwhile

3 I ≈

sum counter

R.B. Lenin (rblenin@daiict.ac.in) () Introduction to Discrete SimulationIntroduction Autumn 2007 30 / 46

slide-4
SLIDE 4

Coin-tossing problem

Example

Two players A and B throw a fair coin N times. If Head, then A gets 1 point; otherwise B.

◮ What is the probability that one of the players is leading between

50% and 55% of the time? Or more than 95% of the time?

◮ In case of 20 trials, say, what is the probability of 5 Heads in a row? R.B. Lenin (rblenin@daiict.ac.in) () Introduction to Discrete SimulationIntroduction Autumn 2007 31 / 46

slide-5
SLIDE 5

Coin-tossing problem · · ·

Example (· · · )

Let P(α, β) be the probability that one of the players is leading between 100α% and 100β% of the time, where 0 ≤ α < β ≤ 1. To determine P(α, β) do the following:

1

Repeat the experiment of “Throwing N times with a coin” many times.

2

An experiment is successful if one of the players is leading between 100α% and 100β% of the time.

3

Then P(α, β) = # successful experiments total # experiments

R.B. Lenin (rblenin@daiict.ac.in) () Introduction to Discrete SimulationIntroduction Autumn 2007 32 / 46

slide-6
SLIDE 6

Coin-tossing problem · · · – Pseudo code for M experiments

Example (· · · )

Variables timeA and timeB denote, respectively, the number of times player A leads player B and player B leads player A: success = 0; for run = 1 to M do invoke the subprogram coin tossing which returns timeA and timeB; if (α < timeA

N

< β) or (α < timeB

N

< β) success = success +1; endif endfor Print

success M

R.B. Lenin (rblenin@daiict.ac.in) () Introduction to Discrete SimulationIntroduction Autumn 2007 33 / 46

slide-7
SLIDE 7

Coin-tossing problem · · · – Pseudo code for subprogram coin tossing

Example (· · · )

n = 0; pointsA = 0; pointsB = 0; timeA = 0; while (n < N) do if (random < 0.5) pointsA = pointsA + 1; else pointsB = pointsB + 1; endif if (pointsA − pointsB > 0) timeA = timeA + 1; endif n = n + 1; endwhile timeB = N − timeA; return timeA and timeB;

R.B. Lenin (rblenin@daiict.ac.in) () Introduction to Discrete SimulationIntroduction Autumn 2007 34 / 46

slide-8
SLIDE 8

Coin-tossing problem · · ·

Example (· · · )

(α, β) P(α, β) (0.5, 0.55) 0.06 (0.5, 0.6) 0.12 (0.9, 1.0) 0.40 (0.95, 1.0) 0.28 (0.98, 1.0) 0.16

R.B. Lenin (rblenin@daiict.ac.in) () Introduction to Discrete SimulationIntroduction Autumn 2007 35 / 46

slide-9
SLIDE 9

Coin-tossing problem · · ·

Example (· · · )

Two players A and B throw a fair coin N times. If Head, then A gets 1 point; otherwise B gets 1 point.

◮ What is the probability that one of the players is leading between 50%

and 55% of the time?

◮ What is the probability that one of the players is leading 95% of the

time?

◮ In case of 20 trials, say, what is the probability of 5 Heads in

row?

R.B. Lenin (rblenin@daiict.ac.in) () Introduction to Discrete SimulationIntroduction Autumn 2007 36 / 46

slide-10
SLIDE 10

Coin-tossing problem · · ·

Example (· · · )

Let P(k) be the probability of at least k successive Heads in case of 20 trials. To determine P(k) do the following:

◮ Repeat the experiment

“Throw 20 times with a coin” many times

◮ An experiment is successful if a row of at least k heads appears.

Then P(k) = number of successful experiments total number of experiments

R.B. Lenin (rblenin@daiict.ac.in) () Introduction to Discrete SimulationIntroduction Autumn 2007 37 / 46