Goals:
Resources:
Coin.java simulation example (http://heather.cs.ucdavis.edu/~matloff/java.html).
LYX (on CSIF PCs, in matloff/Pub; see http://heather.cs.ucdavis.edu/~matloff/lyx.html).
JSwat (on CSIF PCs, in matloff/Pub; see http://heather.cs.ucdavis.edu/~matloff/jswat.html).
Vim/gvim (on CSIF PCs, in /usr/bin and /usr/X11R6/bin/gvim; see http://heather.cs.ucdavis.edu/~matloff/vim.html).
BlueJ (on CSIF PCs, in ~matloff/BlueJ; see http://heather.cs.ucdavis.edu/~matloff/bluej.html).
Note: As stated in my Java tutorial, I recommend that you use JSwat instead of BlueJ. JSwat has more powerful features, and it allows you to use your favorite text editor. But it is up to you; I just want to make sure you use SOME debugging tool.
Problem I:
We will toss a fair coin n times. Let M denote the maxium run length, i.e. the largest number of consecutive heads we get among the n tosses.
(a) Find P(M = 2) analytically (i.e. not by simulation) for the case n = 5.
(b) Verify your answer to (a) by writing a simulation program.
(c) Find E(M) for the case n = 10 by writing a simulation program. (Your answer should be approximately 2.8.)
Problem II:
Suppose X1 and X2 are independent random variables. Suppose also that each is exponentially distributed with mean 1.0, i.e. each has density function f(t) = e-t for t > 0. In other words,
|
for any subset A of the real number line.
Due to independence, their joint density is the product of their marginal densities, i.e. f(r,s) = e-re-s for r,s > 0 and
|
for any subset B of two-dimensional space.
An exponential random variable of mean m can be simulated by generating a U(0,1) random variable, as I did in Rnd() in Coin.java, then taking the natural logarithm, and then finally multiplying by -m.
(a) Find P(X1 > 1.0) analytically, and then check by writing a simulation program.
(b) Find P(X1 > 1.0|X1+X2 > 1.5) analytically, and then check by writing a simulation program.
Note carefully: You should use the formula P(A|B) = P(A and B)/P(B) in your analytical solution but NOT in your simulation. Look at how it is done in Coin.java, where the denominator changes from NREPS to N6. This is because the interpretation of P(A|B) is "the long-run proportion of the time A occurs, AMONG THOSE TIMES IN WHICH B OCCURS."