Re: tossing coins

From: No Way (Not_at_real.com)
Date: 08/22/04


Date: Sun, 22 Aug 2004 16:46:49 +0200

On Sat, 21 Aug 2004 18:04:52 +0200, Andersen <alibandali@hotmail.com>
wrote:

>I have a question regarding the distribution of a coin tossing
>experiment. Somebody actually simulated the following experiment and
>claims it is exponentially distributed. I would like to know if this is
>common knowledge, or if it is false. So I describe the experiment:
>
>I continously toss a coin with the outcome H or T. Assume also I have a
>subset of the integers I = {1,...,N} for some large integer constant N.
>I also have a set K = {N+1,..,2*N}.
>
>Each time I toss my coin repeatedly with 1 seconds inter-arrival time I
>do the following:
>- If I get a H I randomly (with uniform distribution) remove one element
>in K and add it to I.
>- If I get a T, I do the reverse, ie. I remove an element randomly (with
>uniform distribution} from I and add it to K.
>
>I do this for sufficiently long time (infinitely). If we count the
>number of seconds each integer was inside K before being removed, and
>plot a frequency diagram over the "lifetime" of each integer in K, will
>it be exponentially distributed? If so why?

Okay, I've simply recreated the simulation (see Matlab code below).
The result is not an exponential distribution.

Hope this helps (I also hope I did it correctly ;) ).

---begin code---

close all;
clear all;

N = 1000;
pH = 0.5; % probability heads
T = 500;

pT = 1 - pH; % probability tails.

for x = 1:(2*N)
    A(x) = 1/x;
    P(1,x) = pH*A(x);
end

for t = 1:T
    for x = 1:(2*N)
        if x == 1
            P(t+1,x) = pT*P(t, x+1);
        elseif x == (2*N)
            P(t+1,x) = pH*(1-A(x))*P(t,x-1) + (pT*P(t, x));
        else
            P(t+1,x) = (pH*(1-A(x))*P(t,x-1)) + (pT*P(t, x+1));
        end
    end
end

plot(1:(T+1), P(:,N));

y = log(P(:,N));

U = polyfit((1:(T+1)), y', 1);
u = U(1)*(1:(T+1)) + U(2);
d = y'-u;

figure;
plot(d);

% d is the difference between an exponential distribution
% and the found 'curve'

--- end code ---