% LMex020201_4th.m
% Example 2.2.1 p 24 in
% Larsen & Marx (2006) Introduction to Mathematical Statistics, 4th edition
% Written by Eugene.Gallagher@umb.edu for EEOS601 1/13/11
% http://alpha.es.umb.edu/faculty/edg/files/edgwebp.html
% 3 Coin tosses of fair coin. List the sample space S and the sample
% outcomes for event A: majority of faces heads.
coin=['H';'T']
% create the sample space
tosses=3
S=repmat(' ',2^tosses,3); 
i=1;
for face1=1:2
    for face2=1:2
        for face3=1:2
            S(i,:)=[coin(face1) coin(face2) coin(face3)];
            i=i+1;
        end
    end
end
disp('The sample space, S:')
S
% find sample outcomes in sample space S that make up the event A: Majority
% of coins show heads.
[r,c]=size(S);i=find(sum(S'=='H')>c/2);
fprintf('%1.0f of the sample outcomes in Sample Space S constitute the event A:\n',...
    length(i))
A=S(i,:)

        