Download 2.10 Consider the following sequence of (0,1) random numbers

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts

Law of large numbers wikipedia, lookup

Elementary mathematics wikipedia, lookup

Addition wikipedia, lookup

Large numbers wikipedia, lookup

Mathematics of radio engineering wikipedia, lookup

Tweedie distribution wikipedia, lookup

Infinite monkey theorem wikipedia, lookup

Karhunen–Loève theorem wikipedia, lookup

History of network traffic models wikipedia, lookup

Negative binomial distribution wikipedia, lookup

Transcript
© Manuel D. Rossetti, All Rights Reserved
Chapter 2 Solutions for Simulation Modeling and Arena, 2nd Edition, by Manuel
D. Rossetti, John-Wiley & Sons.
Exercises
2.1 The sequence of random numbers generated from a given seed is called a
random number (a)
.
(a) Stream
2.2 State three major methods of generating random variables from any
distribution.
(a) __________________ (b) _____________________ (c)_________________
(a) inverse transform, (b) convolution, (c) acceptance/rejection
2.3 Consider the multiplicative congruential generator with (a = 13, m = 64, and
seeds X0 = 1,2,3,4)
a) Does this generator achieve its maximum period for these parameters?
Use Theorem 2.1 to justify your answer.
b) Generate a period’s worth of uniform random variables from each of the
supplied seeds.
a = 13, m = 64, and X0 = 1, 2, 3, 4
a.) The multiplicative linear congruential generator is a special case of the linear
congruential generator, therefore the LCG theorem can be applied to check if the
generator will achieve its maximum period. The theorem states that an LCG has
a full period if and only if the following three conditions hold:
1. The only positive integer that (exactly) divides both m and c is 1 (i.e. c and m
have no common factors other than 1).
2. If q is a prime number that divides m then q should divide (a-1) (i.e. (a-1) is a
multiple of every prime number that divides m).
3. If 4 divides m, then 4 should divide (a-1) (i.e. (a-1) is a multiple of 4 if m is a
multiple of 4).



Condition 1 does not hold because c = 0, meaning that m and c have multiple
common factors.
Condition 2 holds because the prime numbers, q, that divide m = 64 are 1 and
2. (a-1) = 12, and both 1 and 2 divide 12.
Condition 3 holds because 4 divides both m = 64 and (a-1) = 12.
Also, since m is a power of 2 (m = 64 = 26) and c = 0, the longest possible period
is m/4 = 64/4 = 16.
1
© Manuel D. Rossetti, All Rights Reserved
b.) Below is a period’s worth of uniform random variables from each of the supplied
seeds.
For Xo = 1,
i
Table 4 – A Period’s Worth of Uniform Random Variables
Ri
Ui
1
13
0.2031
2
41
0.6406
3
21
0.3281
4
17
0.2656
5
29
0.4531
6
57
0.8906
7
37
0.5781
8
33
0.5156
9
45
0.7031
10
9
0.1406
11
53
0.8281
12
49
0.7656
13
61
0.9531
14
25
0.3906
15
5
0.0781
16
1
0.0156
For Xo = 2,
Table 5 – A Period’s Worth of Uniform Random Variables
i
Ri
1
2
3
4
5
6
7
8
Ui
26
18
42
34
58
50
10
2
0.4063
0.2813
0.6563
0.5313
0.9063
0.7813
0.1563
0.0313
For Xo = 3,
Table 6 – A Period’s Worth of Uniform Random Variables
2
© Manuel D. Rossetti, All Rights Reserved
i
Ri
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Ui
39
59
63
51
23
43
47
35
7
27
31
19
55
11
15
3
0.6094
0.9219
0.9844
0.7969
0.3594
0.6719
0.7344
0.5469
0.1094
0.4219
0.4844
0.2969
0.8594
0.1719
0.2344
0.0469
For Xo = 4,
i
1
2
3
4
Table 7 – A Period’s Worth of Uniform Random Variables
Ri
Ui
52
0.8125
36
0.5625
20
0.3125
4
0.0625
2.4 Consider the multiplicative congruential generator with (a = 11, m = 64, and
seeds X0 = 1,2,3,4)
a) Does this generator achieve its maximum period for these parameters? Use
Theorem 2.1 to justify your answer.
b) Generate a period’s worth of uniform random variables from each of the
supplied seeds.
Condition 1 does not hold because c = 0, meaning that m and c have multiple
common factors. Thus, it cannot reach its full period. Also, since m is a power of
2 (m = 64 = 26) and c = 0, the longest possible period is m/4 = 64/4 = 16.
3
© Manuel D. Rossetti, All Rights Reserved
4
© Manuel D. Rossetti, All Rights Reserved
2.5 Analyze the following LCG: Xi = (11Xi1 + 5)(mod(16)), X0 = 1 using Theo-
rem 2.1.
a) What is the maximum possible period length for this generator? Does this
generator achieve the maximum possible period length? Justify your answer.
b) Generate 2 pseudo-random uniform numbers for this generator.


Condition 1 holds because the only positive integer that divides both m = 16
and c = 5 is 1
The prime numbers, q, that divide m = 16 are q = 1 and 2. (a-1) = 11-1=10,
and both 1 and 2 divide 10. Thus, condition 2 holds.
5
© Manuel D. Rossetti, All Rights Reserved

Condition 3 does not hold because 4 divides m = 16 but not (a-1) = 10.
Thus, the LCG does not obtain full period.
6
© Manuel D. Rossetti, All Rights Reserved
2.6 Analyze the following LCG generator: Xi = (13Xi1 + 13)(mod(16)), X0 = 37
using Theorem 2.1.
. a) What is the maximum possible period length for this generator? Does this
generator achieve the maximum possible period length? Justify your
answer. . b) Generate 2 pseudo-random uniform numbers for this generator. a = 13, c = 13, m = 16
Condition 1: 1 is the only common factor of c =13 and m=16
Condition 2: The prime numbers, q, that divide m = 16 are q = 1 and 2. (a-1) = 131=12, and both 1 and 2 divide 12. Thus, condition 2 holds.
Condition 3: 4 divides m = 16 and 4 divides (a-1)=12. Thus, condition 3 holds.
Thus, LCG obtains the full period of 16
R1 = (13*37+13)mod 16 = 494 mod 16 = 494 – 16 floor(494/16) = 494 – 16(30) =
14
U1 = 14/16 = 0.875
R2 = (13*R1 + 13) mod 16 = (13*14+13)mod 16 = 194 – 192 = 2
U2 = 2/16 = 0.125
2.7 Analyze the following LCG generator: Xi = (4Xi1 + 3)(mod(16)), X0 = 11 using
Theorem 2.1.
. a) What is the maximum possible period length for this generator? Does this
generator achieve the maximum possible period length? Justify your
answer. . b) Generate 2 pseudo-random uniform numbers for this generator. a = 4, c = 3, m = 16
Condition 1: 1 is the only common factor of c=3 and m = 16, Condition 1 holds.
Condition 2: The prime numbers, q, that divide m = 16 are q = 1 and 2. (a-1) = 4-1=3,
since 2 does not divide 3, condition 3 does not hold. No need to check condition 3.
7
© Manuel D. Rossetti, All Rights Reserved
R1 = (4*11+3)mod 16 = 47 mod 16 = 47 – 16 floor(47/16) = 15
U1 = 15/16 = 0.9375
R2 = (4*R1 + 3) mod 16 = (4*15+3)mod 16 = 63 – 48 = 15
U2 = 15/16 = 0.9375
This generator is degenerate at 15
2.8 Analyze the following LCG generator: Xi = (8Xi1 + 1)(mod(10)), X0 = 3 using
Theorem 2.1.
. a) What is the maximum possible period length for this generator? Does this
generator achieve the maximum possible period length? Justify your
answer. . b) Generate 2 pseudo-random uniform numbers for this generator.
a = 8, c = 1, m = 10
Condition 1: 1 is the only common factor of c =1 and m=10
Condition 2: The prime numbers, q, that divide m = 10 are q = 1, 2, 5. (a-1) = 8-1=7,
only 1 divides 7, so condition 2 does not hold
Condition 3: 4 does not divide 10, thus condition 3 does not hold
Thus, LCG does not reach full period
R1 = (8*3+1)mod 10 = 25 mod 10 = 25 – 10 floor(25/10) = 25 – 10(2) = 5
U1 = 5/10 = 0.5
R2 = (8*5 + 1) mod 10 = (41)mod 10 = 41 – 10 floor(41/10) = 41 – 40 = 1
U2 = 1/10 = 0.1
8
© Manuel D. Rossetti, All Rights Reserved
2.9 The following results are from a random sample of 100 uniform(0,1) numbers.
n
𝑥̅
s
minimum
1st Quartile
median
3rd Quartile
maximum
D+
-D
100
0.4615
0.2915
0.0102
0.1841
0.4609
0.7039
0.9687
0.090733
0.080733
. a) Form a 95% confidence interval for the mean. State any assumptions you
need in order to make this confidence interval. . b) What sample size would be necessary to estimate the mean to within ±0.01
with 95% confidence? . c) What would you conclude based on the Kolmogorov-Smirnov Test results at
the α= 0.01 level? Justify your answer using statistics. a) If n = 100 is large enough to assume that the sample average is normally distributed,
we have a 95% confidence interval based on the student-t statistic of:
0.4615 ± 1.66 * 0.2915/10 = 0.4615 ± 0.04839, [0.4131, 0.5099]
b) Using the normal approximation, approximately 3265
c) Dn = max(0.0907, 0.0807) = 0.0907, D(0.01) ≈ 1.63/10 = 0.163. Since Dn < D(0.01)
do not reject the hypothesis of U(0,1)
2.10 Consider the following sequence of (0,1) random numbers:
0.943
0.498
0.102
0.398
0.528
0.057
0.372
0.272
0.409
0.943
0.899
0.398
0.204
0.294
0.400
0.794
0.156
0.997
Test if the sequence is distributed U (0, 1) using both a K-S test and a Chi-Squared
9
© Manuel D. Rossetti, All Rights Reserved
test.
The chi-square test will vary based on intervals selected.
Five equally spaced intervals:
Do not reject
Kolmogorov-Smirnov Test
Test Statistic = 0.202
Corresponding p-value
> 0.15
2.11 Consider the following set of pseudo-random numbers.
0.2379
0.2972
0.9496
0.3045
0.1246
0.3525
0.1489
0.5095
0.5195
0.6536
0.7551
0.8469
0.2268
0.6964
0.842
0.8075
0.5480
0.4047
0.6545
0.3427
0.2989
0.4566
0.8699
0.1709
0.6557
0.9462
0.9537
0.9058
0.1117
0.6653
0.247
0.6146
0.9084
0.3387
0.9672
0.9583
0.9376
0.3795
0.3258
0.7864
0.3237
0.6723
0.5649
0.9804
0.3356
0.3807
0.8364
0.6242
0.8589
0.5824
a) Test the hypothesis that these numbers are drawn from a U (0, 1) at a 95%
confidence level using the Chi-squared goodness of fit test using 10 intervals.
b) Test the hypothesis that these numbers are drawn from a U (0, 1) at a 95%
confidence level using K-S Test.
10
© Manuel D. Rossetti, All Rights Reserved
c) Test the hypothesis that these numbers are uniformly distributed within the unit
square, {(x, y) : x 2 (0, 1), y 2 (0, 1)} using the 2-D Chi-Squared Test at a 95%
confidence level. Use 4 intervals for each of the dimensions.
d) Test the hypothesis that these numbers have a lag-1 correlation of zero. Make
an autocorrelation plot of the numbers.
(a)
> myFile = file.choose() #ch2P11data.txt
> data = read.table(myFile)
> b = seq(0,1, by = 0.1)
> h = hist(data$V1, b, right = FALSE)
> chisq.test(h$counts)
Chi-squared test for given probabilities
data: h$counts
X-squared = 17.2, df = 9, p-value = 0.04567
Since the p-value = 0.04567 <= 0.5, the hypothesis should be rejected. It is close.
b) > ks.test(data, "punif", 0, 1)
One-sample Kolmogorov-Smirnov test
data: data
11
© Manuel D. Rossetti, All Rights Reserved
D = 0.1572, p-value = 0.1516
alternative hypothesis: two-sided
Since the p-value = 0.1516 >= 0.05, the hypothesis should not be rejected.
c) Run the R code from Listing 2.1 using the supplied data for the problem.
> nd = 100 #number of data points
> myFile = file.choose() #u01data.txt
> data <- read.table(myFile) #read in the data
> d = 2 # dimensions to test
> n = nd/d # number of vectors
> #m = t(matrix(u,nrow=d))
> m = t(matrix(data$V1,nrow=d)) # convert to matrix and transpose
> # b = seq(0,1, by = 0.1)
> b = seq(0,1, by = 0.25) # setup the cut points
> xg = cut(m[,1],b,right=FALSE) # classify the x dimension
> yg = cut(m[,2],b,right=FALSE) # classify the y dimension
> xy = table(xg,yg) # tabulate the classifications
> k = length(b) - 1 # the number of intervals
> en = n/(k^d) # the expected number in an interval
> vxy = c(xy) # convert matrix to vector for easier summing
> vxymen = vxy-en # substract expected number from each element
> vxymen2 = vxymen*vxymen # square each element
> schi = sum(vxymen2) # compute sum of squares
> chi = schi/en # compute the chi-square test statistic
> dof = (k^d) - 1 # compute the degrees of freedom
> pv = pchisq(chi,dof, lower.tail=FALSE) # compute the p-value
> # print out the results
> cat("#observations = ", nd,"\n")
#observations = 100
> cat("#vectors = ", n, "\n")
#vectors = 50
> cat("size of vectors, d = ", d, "\n")
size of vectors, d = 2
> cat("#intervals =", k, "\n")
#intervals = 4
> cat("cut points = ", b, "\n")
cut points = 0 0.25 0.5 0.75 1
> cat("expected # in each interval, n/k^d = ", en, "\n")
expected # in each interval, n/k^d = 3.125
> cat("interval tabulation = \n")
interval tabulation =
12
© Manuel D. Rossetti, All Rights Reserved
> print(xy)
yg
xg
[0,0.25) [0.25,0.5) [0.5,0.75) [0.75,1)
[0,0.25)
0
1
1
2
[0.25,0.5)
1
2
2
2
[0.5,0.75)
1
1
2
1
[0.75,1)
1
2
3
3
> cat("\n")
> cat("chisq value =", chi,"\n")
chisq value = 15.68
> cat("dof =", dof,"\n")
dof = 15
> cat("p-value = ",pv,"\n")
p-value = 0.4036319
Since the p-value = 0.40 >= 0.5, we do not reject the hypothesis. Caution should
be considered here since the number in each interval is less than 5.
d) There is nothing unusual looking about the ACF plot. Lag-k estimates are well
within testing region
rho = acf(data, main="ACF Plot for P2-11", lag.max = 9)
> rho
Autocorrelations of series ‘data’, by lag
0 1
2
3
4
5
6
7
8
9
1.000 -0.045 -0.138 -0.088 0.078 0.025 0.029 0.016 -0.254 -0.009
13
© Manuel D. Rossetti, All Rights Reserved
2.12 Consider the following discrete distribution of the random variable X whose
probability mass function is p(x).
. a) Determine the CDF F(x) for the random variable, X. . b) Create a graphical summary of the CDF. See Example 2.9. . c) Create a look-up table that can be used to determine a sample from the
discrete distribution, p(x). See Example 2.9. . d) Generate 3 values of X using the sequence of (0,1) random numbers in
Exer
cise 2.10 (starting with the first row, reading across). U1 = 0.943
U2 = 0.398
U3 = 0.372
X=4
X=1
X=1
14
© Manuel D. Rossetti, All Rights Reserved
2.13 Consider the following uniformly distributed random numbers:
. a) Generate an exponentially distributed random number with a mean of 10
using the 1st random number. . b) Generate a random variate from a (12,22) discrete uniform distribution using
the 2nd random number. a) X = -10 ln (1 – 0.9396) = 28.0677
b) X = 12 + Floor((22-12+1)*0.1694) = 13
2.14 Consider the following uniformly distributed random numbers:
a) Generate a uniformly distributed random number with a minimum of 12
and a maximum of 22 using U8. b) Generate 1 random variate from an Erlang(r = 2, β = 3) distribution
using U1 and U2 c) The demand for magazines on a given day follows the following
probability distribution Using the supplied random numbers for this problem starting at U1,
generate 4 random variates from this distribution. a) X = 22 + 0.3734*(22-12) = 25.734
b) Use convolution to generate 2 exponential random variables
X1 = -3ln(1-0.9559) = 9.364
X2 = -3ln(1-0.5814) = 2.612
X = X1 + X2 = 11.976
15
© Manuel D. Rossetti, All Rights Reserved
c) Make the table look up as per example 2.9
U1 = 0.9559 X = 80
U2 = 0.5814 X = 50
U3 = 0.6534 X = 60
U4 = 0.5548 X = 50
2.15 Suppose that customers arrive at an ATM via a Poisson process with mean 7
per hour. Determine the arrival time of the first 6 customers using the data given in
Exercise 2.10 (starting with the first row). Use the inverse transformation method.
Customers arrive at an ATM via a Poisson process with mean 7 per hour (λ = 7). The
CDF of the exponential distribution is:
F(x) = 0
x<0
-λx
1-e
x≥0
The inverse CDF is computed as follows:
F(x) = 1-e-λx
U = 1-e-λx
F-1(U) = -1/λ * ln(1-U)
Using the data given in Problem 3-14 and the above inverse CDF, the arrival time for
the first six customers can be calculated.
Arrival Times of First Six Customers (in hours)
Ui
Customer
1
2
3
4
5
6
0.943
0.498
0.102
0.398
0.528
0.057
InterArrival Arrival
Time time
0.4092
0.4092
0.0985
0.5077
0.0154
0.5231
0.0725
0.5956
0.1073
0.7029
0.0084
0.7113
The demand, D, for parts at a repair bench per day can be described by the
following discrete probability mass function:
2.16
16
© Manuel D. Rossetti, All Rights Reserved
Generate the demand for the first 4 days using the sequence of (0,1) random
numbers in Exercise 2.10 (starting with the first row).
To generate the demand for the first four days using the sequence of (0,1) random
numbers in Problem 3-14, we first need to find the inverse CDF for the discrete
distribution.
Table 2 - CDF of the Discrete Distribution
xi
f(xi)
F(xi)
0
0.3
0.3
1
0.2
0.5
2
0.5
1.0
The above CDF can also be written as:
0
if 0 ≤ x ≤ 0.3
F(x) = 1
if 0.3 < x ≤ 0.5
2
if 0.5 < x ≤ 1.0
Using the above function and the random numbers in Problem 3-14, the demand for
the first four days is as follows:
Table 3 - Demand for the First Four Days
Ui
Demand
Day 1
0.943
2
Day 2
0.498
1
Day 3
0.102
0
Day 4
0.398
1
2.17 The service times for an automated storage and retrieval system has a shifted
exponential distribution. It is known that it takes a minimum of 15 seconds for any
retrieval. The parameter of the exponential distribution is = 45. Using the sequence
of (0,1) random numbers in Exercise 2.10 (starting with the first row) generate 2
service times for this situation.
X1 = 15 + -(1/45)ln(1-.943) = 15.064
X2 = 15 + -(1/45)ln(1-0.398) = 15.011
2.18 The time to failure for a computer printer fan has a Weibull distribution with
shape parameter α = 2 and scale parameter β= 3. Using the sequence of (0,1)
random numbers in Exercise 2.10 (starting with the first row) generate 2 failure
times for this situation.
U1 = 0.943
X1 = 3[-ln(1-0.943)]^(1/2) = 5.0776
17
© Manuel D. Rossetti, All Rights Reserved
U2 = 0.398
X1 = 3[-ln(1-0.398)]^(1/2) = 2.1372
2.19 The time to failure for a computer printer fan has a Weibull distribution with
shape parameter α = 2 and scale parameter β= 3. Testing has indicated that the
distribution is limited to the range from 1.5 to 4.5. Using the sequence of (0,1)
random numbers in Exercise 2.10 (starting with the first row) generate 2 failure
times for this this truncated distribution.
Notice that the range is truncated. Following example 2.14, we have:
F(1.5) = 1-exp(-(1.5/3)^2) = 0.22119
F(4.5) = 1-exp(-(4.5/3)^2) = 0.8946
W = 0.22119 + (0.8946 – 0.22119)*0.943 = 0.8562169
X = 3[-ln(1-0.8562169)]^(1/2) = 4.1779
2.20 The interest rate for a capital project is unknown. An accountant has
estimated that the minimum interest rate will between 2% and 5% within the next
year. The accountant believes that any interest rate in this range is equally likely.
You are tasked with generating interest rates for a cash flow analysis of the
project. Using the sequence of (0,1) random numbers in Exercise 2.10 (starting
with the first row) generate 2 independent interest rate values for this situation.
Equally likely means uniformly distributed: U(a=0.02, b = 0.05), using inverse transform:
X = a + (b-a)*U
For U1 = 0.943 and U2 = 0.398
X1 = 0.02 + (0.05-0.02)*0.943 = 0.04829
X2 = 0.02 + (0.05-0.02)*0.398 = 0.03194
2.21 Customers arrive at a service location according to a Poisson distribution with
mean 10 per hour. The installation has two servers. Experience shows that 60% of
the arriving customers prefer the first server. By using the first row of (0,1)
random numbers given in Exercise 2.10, determine the arrival times of the first
three customers at each server.
18
© Manuel D. Rossetti, All Rights Reserved
2.22 Consider the triangular distribution:
a) Derive an inverse transform algorithm for this distribution.
b) Using the first row of random numbers from Exercise 2.10 generate 5 random
numbers from the triangular distribution with a = 2, c = 5, b = 10.
a) The inverse CDF is given on page 687 of the text.
b) U1 = 0.943 and U2 = 0.398
(c-a)/(b-a) = 0.375
For U1 = 0.943, since 0.943 > 0.375, we have X = b-SQRT(b-a)(b-c)*(1-U1)) = 8.8304
For U2 = 0.398, since 0.398 > 0.375, we have X = b-SQRT(b-a)(b-c)*(1-U2)) = 6.1989
19
© Manuel D. Rossetti, All Rights Reserved
2.23 Consider the following probability density function:
a) Derive an inverse transform algorithm for this distribution. b) Using the first row of random numbers from Exercise 2.10 generate 2
random numbers using your algorithm. a) For 𝑥 < −1, 𝐹(𝑥) = 0
1
For −1 ≤ 𝑥 ≤ 1, 𝐹(𝑥) = 2 (𝑥 3 + 1)
For 𝑥 > 1, 𝐹(𝑥) = 1
3
𝐹 −1 (𝑢) = √2𝑢 − 1
b) 𝐹 −1 (0.943) = 0.9604
𝐹 −1 (0.398) = −0.5886765
2.24 Consider the following probability density function:
. a) Derive an inverse transform algorithm for this distribution. . b) Using the first row of random numbers from Exercise 2.10 generate 2
random numbers using your algorithm. a) For 𝑥 < 2, 𝐹(𝑥) = 0
For 2 ≤ 𝑥 ≤ 4, 𝐹(𝑥) =
𝑥2
4
−𝑥+1
For 𝑥 > 4, 𝐹(𝑥) = 1
Solve the following equation for x:
𝑥 2 − 4𝑥 + 4(1 − 𝑢) = 0
Using the quadratic equation:
20
© Manuel D. Rossetti, All Rights Reserved
−𝑏 ± √𝑏 2 − 4𝑎𝑐
𝑥=
2𝑎
Yields
𝑥=
4 ± √16 − 4 ∗ 4(1 − 𝑢)
2
𝑥=
4 ± 4 √𝑢
= 2 ± 2√𝑢
2
Since the final number must be 2 ≤ 𝑥 ≤ 4, we have
𝑥 = 2 + 2√𝑢 = 2(1 + √𝑢)
b) 𝐹 −1 (0.943) = 3.94216
𝐹 −1 (0.398) = 3.2617
2.25 Consider the following probability density function:
. a) Derive an inverse transform algorithm for this distribution. . b) Using the first row of random numbers from Exercise 2.10 generate 2
random numbers using your algorithm. a) For 𝑥 < 0, 𝐹(𝑥) = 0
For 0 ≤ 𝑥 ≤ 5, 𝐹(𝑥) =
𝑥2
25
For 𝑥 > 5, 𝐹(𝑥) = 1
2
𝐹 −1 (𝑢) = 5 √𝑢
b) 𝐹 −1 (0.943) = 4.8554
𝐹 −1 (0.398) = 3.1544
21
© Manuel D. Rossetti, All Rights Reserved
2.26 Consider the following probability density function:
. a) Derive an inverse transform algorithm for this distribution. . b) Using the first row of random numbers from Exercise 2.10 generate 2
random numbers using your algorithm. a) For 𝑥 ≤ 1, 𝐹(𝑥) = 0
1
For 𝑥 > 1, 𝐹(𝑥) = 1 − 𝑏2
2
1
𝐹 −1 (𝑢) = √
1−𝑢
b) 𝐹 −1 (0.943) = 4.1885
𝐹 −1 (0.398) = 1.2888
2.27 The times to failure for an automated production process have been found to
be randomly distributed according to a Rayleigh distribution:
. a) Derive an inverse transform algorithm for generating random variables from
this distribution. . b) Using the first row of random numbers from Exercise 2.10 generate 5
random numbers from your algorithm with β = 2. x
F ( x)  
0
2
2
  x 2 
 

    


xe
dx
2
2
u   x  , du  2 x dx
 

F (u )    e u du  e u  F ( x)  e
 x2
2
x
0
 e
 x2
2
1
The inverse of the CDF is:
22
© Manuel D. Rossetti, All Rights Reserved
F ( x )  e
U  e
x
 x2
2
1
2
2
ln( 1  U ) 
1
 x2

2
  x 2   2 ln( 1  U )  x    2 ln( 1  U )
Using the inverse CDF from above, with β = 2.0, and the uniform numbers given
problem 2-10 yields:
u=
𝐹
−1 (𝑢)
=
0.943
0.398
0.372
0.943
0.204
0.794
3.385087302
1.424777644
1.36413359
3.385087302
0.955313756
2.513864841
2.28 Using the first two rows of random numbers from Exercise 2.10, generate 5
random numbers from the negative binomial distribution with parameters
(r = 4, p = 0.4) using:
a) the convolution method
b) the number of Bernoulli trials to get 4 successes.
a) Convolution method: The negative binomial distribution ( r  4, p  0.4 ) is the
sum of 4 geometric random variables with ( p  0.4 ).
U
GEOM(p=0.4) = 1+floor(ln(1-u)/ln(1-p))
0.943
6
0.498
2
0.102
1
0.398
1
Answer: 10 trials
a) Bernoulli trials: Generate Bernoulli trials until you get 4 successes
U
Bernoulli trial
1
0.943
0
2
0.498
0
3
0.102
1
4
0.398
1
5
0.528
0
6
0.057
1
7
0.372
1
Answer: 7 trials
23
© Manuel D. Rossetti, All Rights Reserved
2.29 Suppose that the processing time for a job consists of two distributions. There
is a 30% chance that the processing time is lognormally distributed with a mean of
20 minutes and a standard deviation of 2 minutes, and a 70% chance that the time is
uniformly distributed between 10 and 20 minutes. Using the first row of random
numbers from Exercise 2.10 generate two job processing times.
Hint: X ~ LN(μ, σ2) if and only if ln(X) ~ N(μ, σ2). Also, note that:
This is a mixture distribution. Let 𝐹1 represent the lognormal distribution with 𝜔1 = 0.3.
Let 𝐹2 represent the uniform distribution with 𝜔2 = 0.7.
Using U1 = 0.943 to pick the distribution implies, X ~ U(10,20) because 0.943 > 0.3
X = a + (b-a)U2 = 10 + 10*0.398 = 13.98
Using U3 = 0.372 to pick the distribution implies, X ~ U(10,20) because 0.372 > 0.3
X = a + (b-a)U4 = 10 + 10*0.943 = 19.43
We “got lucky” and did not have to generate from the lognormal distribution. To
generate from the lognormal distribution, we can use the inverse for the normal
distribution found in Excel.
𝑚 = 𝐸[𝑋]
𝑣 = 𝑉[𝑋]
Then,
𝑚
𝜇 = 𝑙𝑛
(
√1 +
𝜎 2 = 𝑙𝑛 (1 +
𝜇 = 𝑙𝑛
20
4
√
( 1 + 202 )
𝜎 2 = 𝑙𝑛 (1 +
𝑣
𝑚2 )
𝑣
)
𝑚2
= 2.99076
4
) = 0.00995
202
24
© Manuel D. Rossetti, All Rights Reserved
Generate Y ~ N(𝜇, 𝜎) via NORM.INV(p, mu, sigma), then X = EXP(Y) will be
lognormal, where p will be the U(0,1). So to generate a lognormal use the equation:
EXP(NORM.INV(RAND(), mu, sigma)).
2.30 Suppose that the service time for a patient consists of two distributions. There
is a 25% chance that the service time is uniformly distributed with minimum of 20
minutes and a maximum of 25 minutes, and a 75% chance that the time is
distributed according to a Weibull distribution with shape of 2 and a scale of 4.5.
Using the first row of random numbers from Exercise 2.10 generate the service
time for two patients.
This is a mixture distribution. Let 𝐹1 represent the U(20,25) distribution with 𝜔1 = 0.25.
Let 𝐹2 represent the Weibull distribution with 𝜔2 = 0.75.
Using U1 = 0.943 to pick the distribution implies, X ~ Weibull because 0.943 > 0.25
1
𝑋 = 𝛽[−𝑙𝑛(1 − 𝑢)]𝛼
Using U2 = 0.398
X = 4.5[-ln(1-0.398)]^(1/2) = 3.2057
Using U3 = 0.372 to pick the distribution implies, X ~ Weibull because 0.372 > 0.25
Using U4 = 0.943
X = 4.5[-ln(1-0.943)]^(1/2) = 7.616
Use Z = NORM.S.INV(U) where U is read from the table. Do this for 5 PRN’s
and, square and sum the values. Students could also use the z-table in the book.
25
© Manuel D. Rossetti, All Rights Reserved
1
2
3
4
5
1
2
3
4
5
U
Z~N(0,1)
Z^2
0.943 1.580466818 2.497875364
0.398 -0.258527277 0.066836353
0.372 -0.326560927 0.106642039
0.943 1.580466818 2.497875364
0.204 -0.827418321 0.684621077
sum = 5.853850198 Y1
0.794 0.820379146 0.673021943
0.498 -0.005013278 2.5133E-05
0.528 0.070243314 0.004934123
0.272 -0.606775364 0.368176342
0.899 1.275874179 1.627854921
sum = 2.674012462 Y2
2.32 In the (a)
technique for generating random variates, you want
the (b)
function to be as close as possible to the distribution function
that you want to generate from in order to ensure that the (c)_________
is as high
as possible, thereby improving the efficiency of the algorithm.
(a) acceptance/rejection
(b) majorizing
c) acceptance probability
2.33 Prove that the acceptance-rejection method for continuous random variables
is valid by showing that for any x,
Hint: Let E be the event that the acceptance occurs and use conditional probability.
Let A be the event that acceptance occurs:

f (W ) 
A  U  g (W )  f (W )  U 

g (W ) 

We want to show that F ( x)  PX  x 
x
 f  y dy

26
© Manuel D. Rossetti, All Rights Reserved
Now X equals W if and only if the event A occurs. Thus,
PX  x  P{W  x | A} 
P( A  {W  x})
P( A)
x
P( A  {W  x})   P( A  {W  x} | W  w)h(w)dw (Law of total probability by

conditioning on h(w)
x
x


P( A  {W  x})   P( A | W  w)h( w)dw   P( A | W  w)
g ( w)
dw
c



f (W )
f (W )  f (W )
because U and W are
P( A | W  w)  PU 
| W  w  PU 

g (W )
g (W )  g (W )



independent and U is uniform(0,1)
PX  x  P{W  x | A} 
P( A  {W  x})

P( A)

x

f ( w) g ( w)
dw
x
g ( w) c
  f ( w)dw

1
c
Q.E.D
2.34 Consider the following probability density function:
a) Derive an acceptance-rejection algorithm for this distribution.
b) Using the first row of random numbers from Exercise 2.10 generate 2 random
numbers using your algorithm.
Choose g(x) = 3/2. Integrating over [-1, 1] yields c = 3. Thus, w(x) = ½ over [-1,1]
Algorithm
Repeat
Generate W ~ w(x) which is U(-1,1)
Generate U ~ U(0,1)
Until U*g(W) <= f(W)
Return W
W = a + (b-a)* U = -1 + (1 - -1)U = 2*U -1
27
© Manuel D. Rossetti, All Rights Reserved
U1 = 0.943
W = 2*0.943 -1 = 0.886
U2 = 0.398
Is 0.398*1.5 <= 1.5(0.886)^2?
0.597 < 1.177, therefore accept X = W = 0.886
U1 = 0.372
W = 2*0.372 -1 = -0.256
U2 = 0.943
Is 0.943*1.5 <= 1.5(-0.256)^2?
1.4145 < 0.098304, therefore reject W
Continue in this manner until you get the 2nd acceptance.
28
© Manuel D. Rossetti, All Rights Reserved
hx   ab
H x  
x a 1
a 2
xa
b  x a 
 bu 
H (u )  

1  u 
1
for x  0
b  x 
for x  0
1
a
2.36 Parts arrive to a machine center with three drill presses according to a Poisson
distribution with mean 𝜆. The arriving customers are assigned to one of the three
drill presses randomly according to the respective probabilities p1, p2, and p3 where
p1 + p2 + p3 = 1 and pi > 0 for i = 1, 2, 3. What is the distribution of the inter-arrival
times to each drill press? Specify the parameters of the distribution.
Suppose that p1, p2, and p3 equal to 0.25, 0.45, and 0.3 respectively and 𝜆 that
is equal to 12 per minute. Generate the first three arrival times using numbers from
the first row of random numbers from Exercise 2.10.
Because of the splitting rule for Poisson processes, the drill presses each see
arrivals according to the following three Poisson processes:
𝜆1 = 𝜆𝑝1 = 12 ∗ 0.25 = 3
𝜆2 = 𝜆𝑝2 = 12 ∗ 0.45 = 5.4
𝜆3 = 𝜆𝑝3 = 12 ∗ 0.3 = 3.6
Since the time between arrivals will be exponential, we have the following
first arrival time to each drill press:
X1 = -(1/3)ln(1-0.943) = 0.9549
29
© Manuel D. Rossetti, All Rights Reserved
X2 = -(1/5.4)ln(1-0.398) = 0.09398
X3 = -(1/3.6)ln(1-0.372) = 0.12923
Alternative solution procedure:
Generate inter-arrival times by using 𝜆=12. At each arrival, determine which drill press
sees the arrival by using the PMF (0.25, 0.45, 0.3) to pick the drill press. Continue
generating until you get the first arrival at each drill press.
30