In: Electrical Engineering
MATALB MATALAB
Getting 4-of-a-kind
Consider the following experiment:
oYou draw 5 cards from a deck of 52 cards. This is considered a single experiment. If you get 4-of-a-kind the experiment is considered a "success".
oYou repeat the experiment N=100,000 times, keeping track of the"successes".
oAfter the N experiments are completed count the total successes, andcalculate the probability of getting4-of-a-kin
Hello,
Please find the answer
attached below. If the answer has helped you please give a
thumbs up rating. Thank you and have a nice
day!
********** Matlab Code **********
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Four-of-a-kind experiment in Matlab
%%%%%%%%%% Define the parameters %%%%%%%%%%
numOfTrials =
100000 %
persons playing cards.
numCardsPerTrial =
5 % cards each
person holds
four_Of_A_Kind = 0;
% Perform Monte Carlo simulations for the random distribution
game:
for h = 1 : numOfTrials
% Get the cards. Each card is numbered from 1 -
52
cards_pick = randperm(52,
numCardsPerTrial);
% picking the cards randomly
% Check for four of a kind
sameSuit = (min(cards_pick) >= 1 &&
max(cards_pick) <= 13) || ... % cards
are numbered from 1 till 52
(min(cards_pick) >= 14 && max(cards_pick)
<= 26) ||
...
% a gap of 13 in the card numbering indicates a different
kind
(min(cards_pick) >= 27 && max(cards_pick)
<= 39) || ...
(min(cards_pick) >= 40 && max(cards_pick)
<= 52);
if sameSuit
four_Of_A_Kind = four_Of_A_Kind +
1;
% counting the successes
end
end
success =
four_Of_A_Kind;
% total number of successes
prob_success = success/numOfTrials %
probability of the success
************ End of Code **********
Output:
numOfTrials =
100000
numCardsPerTrial =
5
prob_success =
0.0019
Final answer: The code gives the probability of success as 0.0019 or 0.19%
NOTE 1: Since this is a random experiment, the answer that you obtain might be slightly different from the answer that is given here. The answers can be made quite close by repeating the experiment for a large number of times.
NOTE2: The complete program has been commented in a manner that it is easy to re-code and understand the code.