Question text is in black, my answers in blue.
No, you can implement this with
variables. The numerical precision problem is that the true probabilities
are fractions and the
double values you'll use are thus
approximations. When you add up lots of numbers that are slightly off, the
errors can accumulate. But here you are only adding a few thousand numbers
and the error shouldn't be significant. The problem of integer overflow is
that if you deal with numbers larger than 2 billion or so the computer wraps
around and gets wrong answers. I don't see why you would want such large
numbers for this problem, particularly if you deal with all the probabilities
double values, but in any case we won't worry about overflow
when grading your paper code.
No, for the homework
you can assume that you have a package lying around that does all this
stuff, so you can just call methods like However, coding up these methods on your own is a good way to internalize
their definitions, and would be fair game as a test question!
binom(n, k) or
bernoulli(n, i, p) and not even worry precisely what they are
called. The point of this problem is to show that you can solve the baseball
problem using the material from the chapter.
However, coding up these methods on your own is a good way to internalize their definitions, and would be fair game as a test question!
First, the standard Poisson variable is equal to 0 with probability 1/e, equal to 1 with probability 1/e, equal to 2 with probability 1/2e, equal to 3 with probability 1/6e, and in general equal to 1 with probability 1/(i!)e. The expected value of P is an infinite sum, 0(1/e) + 1(1/e) + 2(1/2e) + 3(1/6e) + ..., and this is a sum that you should recognize. To get the variance, you need to also calculate the expected value of P2, which is another infinite sum, 02(1/e) + 12(1/e) + 22(1/2e) + 32(1/6e) + ..., that is harder but still possible to evaluate just knowing the basic fact that ex is the sum for all i of xi/i!. (The hard part in MATH 132 was seeing why this is true using Taylor series, but we don't need to get into that.)
Last modified 17 October 2009