% LMex020401_4th.m
% A silly program to solve Example 2.4.1 on p 44 from
% Modeled after ex 2.2.6 in
% Larsen & Marx (2006) Introduction to Mathematical Statistics, 4th edition
% Written by Eugene.Gallagher@umb.edu 1/14/11 31
% http://alpha.es.umb.edu/faculty/edg/files/edgwebp.html
% A card is drawn from a poker deck. What is the probability that the card
% is a club, given that the card is a king?
% C is the event card is a club
% K is the event card is a king (indicated by 13 in deckn)
deckn=repmat(1:13,1,4); deckf=repmat('HCDS',1,13);
Ki=find(deckn==13);Ci=find(deckf=='C');
% P(C|K)=P(C ^ K)/P(K);
PK=length(Ki)/length(deckf);
PCintK=length(intersect(Ki,Ci))/length(deckf);
PCgivenK=PCintK/PK;
fprintf('The conditional probability of a Club, \n')
fprintf('given that the card is a King is %6.4f\n',PCgivenK);
% find the unconditional probability P(C)
PC=length(Ci)/length(deckf);
fprintf('The unconditional probability of a Club is % 6.4f\n',PC);