% LMex040401_4th.m
% Larsen & Marx (2006) Introduction to Mathematical Statistics, 4th Edition
% Page 317-318. Application of the geometric pdf and continuous geometric
% to find the probability that more than 4 rolls will be required to roll
% a 7
% Written by Eugene Gallagher 10/2010, Eugene.Gallagher@umb.edu
% Revised 1/9/11
% Problem. A pair of dice are tossed unitl a sum of seven appears for the
% first time. What is the probability that more than four rolls will be
% required for that to happen?
die=repmat([1:6]',1,6);dice=die+die'
[r,c]=size(dice);
dice==7
p=sum(sum(dice==7))/(r*c);
fprintf('The probability of rolling a seven is %6.4f.\n',p)
% p=6/36; % (1,6),(6,1),(3,4)(4,3),(5,2),(2,5)
k=1:4;
P=1-sum( (1-p).^(k-1)*p);
fprintf('Matlab defines the geometric distribution differently from ')
fprintf('Larsen & Marx:\n')
fprintf('The probability that more than four rolls will be required to ')
fprintf('roll a seven is %6.4f.\n',P)
% Matlab defines the geometric probability distribution function
% differently than Larsen & Marx.
% Larsen & Marx: number of rolls before a success k=1, 2, 3, ...
% Mathworks: Number of failures before
% a success. k=0, 1, 2, 3, ...
kMatlab=k-1;
P2 = 1-sum(geopdf(kMatlab,p));
% or
P3=1-geocdf(3,p);
fprintf('The probability that 3 or more failures will be rolled')
fprintf(' before rolling a seven is %6.4f.\n',P3)