% Some simple probability experiments in Matlab % Toss a coin x=rand<.5 % Roll a die x=ceil(6*rand) % Toss a coin a bunch of times n=10 x=rand(1,n)<.5 % Toss a coin a bunch of times; count the number of heads n=10 t=rand(1,n)<.5; x=sum(t) % Roll a die a bunch of times; make a histogram n=10 x=ceil(6*rand(1,n)); hist(x,1:6) % Toss a coin a bunch of times many times clear p=.7 n=100 trials=10000 x=zeros(1,trials); for i=1:trials t=rand(1,n)=1 k=k+1; rec(k)=aces; end end hist(rec,0:4) meansaces=mean(rec) % Having the aces of spades is better. reps=10^4 rec=NaN(1,reps); k=0; while(k