% Bernoulli and Binomial processes %
N=50; p=0.4; 
X = ( rand(N,1) < p );
for n=1:N; 
if X(n)==1; plot(n,0,'r*'); axis([0 N -1 1]); else plot(n,0,'bo'); axis([0 N -1 1]); end; hold on; 
pause(0.5); end; pause; hold off; 

S=0; 
for n=1:N; S=S+X(n); 
subplot(2,1,1); if X(n)==1; plot(n,0,'r*'); axis([0 N -1 1]); else plot(n,0,'bo'); axis([0 N -1 1]); end; hold on; 
subplot(2,1,2); plot(n,S,'m*'); axis([0 N 0 max(S,N*p)]); hold on;
pause(0.5); end;