"Derek Ross" <[EMAIL PROTECTED]> wrote:
> I have four coins in my hand. Each coin has a number on both sides.
> All coins have a zero on one side, and the other side has a number
> from 1 to 4.
>
> I then hurl the handful of coins at the ground, then add up the
> values of all the coins. [...]
Well, the hard part of this problem is figuring out the coefficients
of (1+u)(1+u^2)(1+u^3)...(1+u^n), where n is the number of coins.
There must be a simple formula, but since I am a bear of little brain,
it's not obvious to me, and I don't have any references handy.
But here is a snippet of Matlab code that will do the trick:
sum = 1;
for k=1:n
zk = zeros(1,k);
zk_sum = [ zk sum ];
sum_zk = [ sum zk ];
sum = zk_sum + sum_zk;
end
ps = sum/(2^n);
When this completes, ps(k+1) contains the mass on the possible value k
of the sum. This is fairly primitive, and slows down for large n.
My K6-200 can carry out this calculation for n=200 in about 4 seconds.
Plotting ps shows a nice Gaussian-like bump -- the central limit
theorem in action. :)
By the way, I use Octave, a free math environment which implements
most Matlab commands. See http://www.octave.org/.
Hope this helps,
Robert Dodier
Sent via Deja.com
http://www.deja.com/
=================================================================
Instructions for joining and leaving this list and remarks about
the problem of INAPPROPRIATE MESSAGES are available at
http://jse.stat.ncsu.edu/
=================================================================