In lottery the player has to guess correctly r numbers that are drawn out of n numbers. The probability, P, of guessing m numbers out of the r numbers can be calculated by the expression:
p = Cr,mC(n-r),(r-m)/Cn,r
where Cx,y = x!/y!(x – y)!. Write a user-defined MATLAB function that calculates P. For the function name and arguments, use P = ProbLottery (m, r, n). The input arguments are m the number of correct guesses; r, the number of numbers that need to be guessed; and n, the number of numbers available. Use a subfunction inside ProbLottery for calculating Cx,y.
(a) Use ProbLottery for calculating the probability of correctly selecting 3 of 6 the numbers that are drawn out of 49 numbers in a lottery game.
(b) Consider a lottery game in which 6 numbers are drawn out of 49 numbers. Write a program in a script file that displays a table with seven raws and two columns. The first column has the numbers 0, 1, 2, 3, 4, 5, and 6, which are the number of numbers guessed correctly. The second columns show the corresponding probability of making the guess.
SOLUTION
Script file:
disp('Part (a)')
prob3of6 = ProbLottery(3,6,49)
disp(' ')
disp('Part (b)')
num=0:6;
odds=ProbLottery(num,6,49);
tbl=[num;odds];
disp(' ')
disp(' Number')
disp(' Correct Odds')
fprintf(' %1i %.9f\n',tbl)
fprintf('\nCheck: The sum of the probabilities is %.9f\n',sum(odd
Unlock the complete assignment
You are viewing the free preview. Purchase this assignment once to reveal the complete resource.
Secure checkout is completed by Stripe.