Anda di halaman 1dari 32

29-Mar-13 Dr.B.

Mishra (Prob & Stat) 1


Simulation
Simulation
Nowadays simulation techniques are being
applied to many problems in Science and
Engineering. If the processes being simulated
involve an element of chance, these simulation
techniques are referred to as Monte Carlo
methods. For example to study the number of
customers arriving at an Airline Company or to
study the amount of stocks in inventory, Monte
Carlo techniques are used.
29-Mar-13 Dr.B.Mishra (Prob & Stat) 2
Random Numbers
In Monte Carlo methods, one uses the
table of random numbers to generate
random deviates (= values assumed by a
random variable). Table of random
numbers consists of many pages on which
the digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 are
distributed in such a way that the
probability of any one digit appearing is
the same, namely
1
10 = 0.1.
29-Mar-13 Dr.B.Mishra (Prob & Stat) 3
Use of random numbers to generate
Heads and Tails
For example, we choose Page 693, Row 22,
Column 4 and go across sequentially. We
read the digits 7 4 1 0 3 4 7 0 7 0 (etc.).
Associating a head to the occurrence of an
even digit and tail to an odd number, we may
interpret this as T H T H T H T H T H
because the probability of getting an even
digit = the probability of an odd digit = 0.5.
29-Mar-13 Dr.B.Mishra (Prob & Stat) 4
We can also associate a head if we get one of
the 5 digits 0, 1, 2, 3, 4 and a tail otherwise.
This means that we got the sequence
T H H H H H T H T H
In problems on Simulation, we shall adopt
the second scheme as it is easy to use and is
easily extendable for more than two
outcomes.
29-Mar-13 Dr.B.Mishra (Prob & Stat) 5
Suppose for example, we have an experiment
with 4 outcomes with probability 0.1, 0.2. 0.3
and 0.4 respectively.
To simulate the outcomes of the above
experiment, we have to allot one of the digits
to the first outcome, two of the remaining 9
digits to the 2
nd
outcome, three of the
remaining 7 digits to the 3
rd
outcome and the
remaining 4 digits to the 4
th
outcome. Though
this can be done in a variety of ways, we
29-Mar-13 Dr.B.Mishra (Prob & Stat) 6
Associate the first digit 0 to the 1
st
outcome
O
1
,
Associate the next two digits, namely 1, 2 to
the 2
nd
outcome O
2
,
Associate next three digits, namely 3, 4, 5 to
the 3
rd
outcome O
3
,
Associate the remaining four digits, namely
6, 7, 8, 9 to the 4
th
outcome O
4
.
choose the simplest way as follows:
29-Mar-13 Dr.B.Mishra (Prob & Stat) 7
Hence the above sequence 7 4 1 0 3 4 7 0
7 0 of random numbers would correspond to
the sequence of outcomes O
4
O
3
O
2
O
1
O
3

O
3
O
4
O
1
O
4
O
1
.
Use of two and higher digit random
numbers in Simulation
Suppose we have a random experiment with
three outcomes with probabilities 0.80, 0.15
and 0.05 respectively.
29-Mar-13 Dr.B.Mishra (Prob & Stat) 8
We now read two digits at a time:
74, 10, 34, 70, 70, 25, 30, 67 etc.
Since P(any one digit) = 0.1, P(any two
digits) = 0.1 0.1 = 0.01 = 1/100. Thus each
two digit random number occurs with a
probability 0.01.
How can we use the table of random numbers
to simulate the above experiment?
29-Mar-13 Dr.B.Mishra (Prob & Stat) 9
Since there are 100 2-digit random numbers,
namely 00, 01, , 10, 11, 12,, 99, we
associate the first 80 2-digit random numbers,
namely, 00, 01, .., 10, 11, , 78, 79 to the first
outcome O
1
, the next 15 2-digit random
numbers, namely 80, 81, , 93, 94 to the
second outcome O
2
, and the remaining 5
2-digit random numbers, namely 95, 96, , 99
to the 3
rd
outcome O
3
. Thus the above
sequence 74, 10, 34, 70, 70 corresponds to the
sequence of outcomes O
1
, O
1
, O
1
, O
1
, O
1
29-Mar-13 Dr.B.Mishra (Prob & Stat) 10
We describe the above scheme in a diagram
as follows:
Outcome Probability Cumulative
Probability *
Random
Numbers **
O
1
0.80 0.80 00 - 79
O
2
0.15 0.95 80 - 94
O
3
0.05 1.00 95 - 99
29-Mar-13 Dr.B.Mishra (Prob & Stat) 11
* Cumulative probability is got by adding
all the probabilities at that position and
above it. Thus the cumulative probability of
the Outcome O
2
= Probability of O
1
and
Probability of O
2
= 0.80 + 0.15 = 0.95.
** We also observe that the beginning random
number is 00 for the 1
st
outcome; and for the
remaining outcomes, it is one more than the
ending random number of the immediately
preceding outcome. Also the ending random
number is one less than the cumulative Prob.
29-Mar-13 Dr.B.Mishra (Prob & Stat) 12
Similarly three digit random numbers are
used if the probability of an outcome has
three decimal places.
29-Mar-13 Dr.B.Mishra (Prob & Stat) 13
Example
Suppose that the probabilities are 0.2466,
0.3452, 0.2417, 0.1128, 0.0395, 0.0111, 0.0026,
and 0.0005 that there will be 0, 1, 2, 3, 4, 5, 6,
or 7 polluting spills in the Great Lakes on any
one day.
(a) Describe the four-digit random numbers
from 0000 to 9999 to the 8 values of this
random variable, so that the corresponding
random numbers can be used to simulate
daily polluting spills in the Great Lakes.
29-Mar-13 Dr.B.Mishra (Prob & Stat) 14
(b) Use the results of (a) to simulate the
numbers of polluting spills in the Great
lakes for 30 days.
29-Mar-13 Dr.B.Mishra (Prob & Stat) 15
No of
polluting
Spills
Probability Cumulative
Probability
4-digit Random
Numbers
0 0.2466
1 0.3452
2 0.2417
3 0.1128
4 0.0395
5 0.0111
6 0.0026
7 0.0005
Scheme for Simulating Polluting Spills
0.2466 0000 2465
0.5918 2466 5917
0.8335 5918 8334
0.9463
8335 9462
9463 9857
9858 9968
9969 9994
9995 9999
0.9858
0.9969
0.9995
1.0000
29-Mar-13 Dr.B.Mishra (Prob & Stat) 16
(b) Let us start on Page 693, Row 22,
Column 4 and go across sequentially:
We read out the 4-digit random numbers as:
7410, 3470, 7025, 3067, 6468, 2638, 4581,
1510, 6646, etc.
The simulated polluting spills are:
2, 1, 2 , 1, 2, 1, 1, 0, 2, etc.
29-Mar-13 Dr.B.Mishra (Prob & Stat) 17
Example
Depending on the availability of parts, a
company can manufacture 3, 4, 5, or 6 units of
a certain item per week with corresponding
probabilities 0.10, 0.40, 0.0.30, and 0.20. The
probabilities that there will be a weekly
demand of 0, 1, 2, , 8 units are, respectively,
0.05, 0.10, 0.30, 0.30, 0.10, 0.05, 0.05, 0.04,
and 0.01. If a unit is sold during the week that it
is made , it will yield a profit of $100; this
profit is reduced by $20 for each week it has to
29-Mar-13 Dr.B.Mishra (Prob & Stat) 18
stored. Use random numbers to simulate the
operation of this company for 50 consecutive
weeks and estimate its expected weekly
profit.
Random Nos. for units produced:
27, 57, 26, 50, 87, 27, 39, 53, 95, 79, 24, 42
Random Nos. for units demanded:
98, 86, 67, 44, 30, 97, 88, 94, 04, 46, 34, 94
29-Mar-13 Dr.B.Mishra (Prob & Stat) 19
Scheme for simulating the number of units
produced per week
No of
units
produced
Probability Cumulative
Probability
Random
Numbers
3 0.10
4 0.40
5 0.30
6 0.20
0.10
0.50
0.80
1.00
00 09
10 49
50 79
80 99
29-Mar-13 Dr.B.Mishra (Prob & Stat) 20
Scheme for simulating the weekly demand
Weekly
Demand
Probability Cumulative
Probability
Random
Numbers
0 0.05 0.05 00 04
1 0.10 0.15 05 14
2 0.30 0.45 15 44
3 0.30 0.75 45 74
4 0.10 0.85 75 84
29-Mar-13 Dr.B.Mishra (Prob & Stat) 21
Scheme for simulating the weekly demand
Weekly
Demand
Probability Cumulative
Probability
Random
Numbers
5 0.05 0.90 85 89
6 0.05 0.95 90 94
7 0.04 0.99 95 98
8 0.01 1.00 99
29-Mar-13 Dr.B.Mishra (Prob & Stat) 22
(1) (2) (3) (4) (5) (6) (7) (8) (9)
Week No
in
Sto
ck
RN
for
prod
No
Pro
duc
ed
RN
for
De
ma
nd
No
de
ma
nde
d
No
sold=
Min
{(2)
+(4),
(6)}
No
unsold
=
max{0,
(2)+(4)-
(7)}
Profit
= (7)
*100
- (2)
* 20
We can continue like this.
4 0 1 27
4
98 7 0 400
2
0
57 5 86 5 5 0 500
3 0 26 4 67 3 3 1 300
4 1 50 5 44 2 2 4 180
5 4 87 6 30 2 2 8 120
Av. Profit =
300
29-Mar-13 Dr.B.Mishra (Prob & Stat) 23
Simulating a Continuous random variate
Suppose X is a continuous random variable
with density f (x) and cdf F(x). We know that

U = F (X)
is a continuous random variable having
uniform density on [0, 1].
29-Mar-13 Dr.B.Mishra (Prob & Stat) 24
Noting that a random number is nothing but
the value assumed by a random variable U
having uniform distribution over [0, 1], we
thus simulate the value assumed by a
continuous random variable X as follows:
Step 1 Find the cdf, F (x) of X
Step 2 Select a (2 or 3 digit) random
number U from a table of random digits.
29-Mar-13 Dr.B.Mishra (Prob & Stat) 25
For example if the random number is 243,
then it corresponds to the value 0.243.
Step 3: Solve for X, the equation
F (X) = U.
Be sure to note U is a decimal between 0 and
1 (and so put a decimal point at the start).
29-Mar-13 Dr.B.Mishra (Prob & Stat) 26
Simulating an exponential density
Example
Let X be a random variable having exponential
density with parameter |.
( ) 1
x
F x e
|

=
= u
Solving for x we get
1
ln
1
x
u
| =

Hence the cdf of X is


29-Mar-13 Dr.B.Mishra (Prob & Stat) 27
Since whenever u is a random number,
so also is 1 u,
we can also write the value assumed by
a random variable having an exponential
density with parameter | as
1
ln x
u
| =
(We ignore the case when u = 0.)
29-Mar-13 Dr.B.Mishra (Prob & Stat) 28
Example
Simulating a uniform density
Let X be a continuous random variable
having uniform density on [a, b].
Hence the cdf of X is
( )
x a
F x
b a

= u
Solving for x, we get
( ) x a b a u = +
29-Mar-13 Dr.B.Mishra (Prob & Stat) 29
Example
Let X be a continuous random variable
having density f (x) = 2x, 0 < x < 1.
Hence the cdf of X is = u
Solving for x, we get
x u =
(only positive square root)
F(x) = x
2
29-Mar-13 Dr.B.Mishra (Prob & Stat) 30
Example
Let X be a continuous random variable
having density f (x) = | x |, -1 < x < 1.
Hence the cdf of X is
2
2
1 1
, 1 0
2 2
( )
1 1
, 0 1
2 2
x x
F x
x x

< <

+ s <

29-Mar-13 Dr.B.Mishra (Prob & Stat) 31


if - 1 < x < 0, 0 < F(x) <
if 0 s x < 1, s F(x) < 1
Hence if u is a random number,
if 0 < u < , we solve for x,
- x
2
= u
and get x = 1 2u
if s u < 1 , we solve for x,
+ x
2
= u
and get
2 1 u +
x =
We note that
29-Mar-13 Dr.B.Mishra (Prob & Stat) 32

Anda mungkin juga menyukai