Question: MATLAB probability question I need to find the probability 3 GREEN balls came from box 1 I put THIS SECTION for the part where my
MATLAB probability question
I need to find the probability 3 GREEN balls came from box 1
I put "THIS SECTION" for the part where my code is. The actual calculated probability is 64.4% and my code gets 21.5ish %. Anyone know what I am doing wrong?
I put: if results4(2) == 3 && box_choice > 0.5 % because that is "if 3 green balls and box 1" but I am not getting correct #
function [] = EE380Proj1B ()
% a) prob 2 red balls and 1 green ball
% b) if all 3 balls are green, prob that box 1 was chosen
% box 1
%R1 = 1;
%G1 = 3;
% box 2
%R2 = 5;
%G2 = 8;
%total = 13
counter = 0;
counter2 = 0;
processes = 100000;
for i = 1:processes
box_choice = rand;
results = [0 0];
choice1 = rand;
choice2 = rand;
choice3 = rand;
% [red, green]
if box_choice > 0.5
% box 1
%fprintf("box 1 chosen: ");
if choice1 > 0.75
results2 = results + [1 0];
else
results2 = results + [0 1];
end
if choice2 > 0.75
results3 = results2 + [1 0];
else
results3 = results2 + [0 1];
end
if choice3 > 0.75
results4 = results3 + [1 0];
else
results4 = results3 + [0 1];
end
else % box_choice
% box 2
%fprintf("box 2 chosen: ");
if choice1 > (8/13)
results2 = results + [1 0];
else
results2 = results + [0 1];
end
if choice2 > (8/13)
results3 = results2 + [1 0];
else
results3 = results2 + [0 1];
end
if choice3 > (8/13)
results4 = results3 + [1 0];
else
results4 = results3 + [0 1];
end
end % end if-else
% disp(results4)
% part a)
if results4(1) == 2
counter = counter + 1;
else
end
% ======================================================================= %
THIS SECTION
% ======================================================================= %
% part b)
if results4(2) == 3 && box_choice > 0.5
counter2 = counter2 + 1;
else
end
% ======================================================================= %
SECTION ABOVE
% ======================================================================= %
% use this to see if 3 green balls were chosen
end % end for loop
RandG = ((counter) ./ (processes)) * 100;
G3 = ((counter2) ./ (processes)) * 100;
fprintf("Probability of 2 Red Balls & 1 Green Ball = %d percent. ",RandG);
fprintf("Probability 3 greens came from box 1 = %d ",G3);
end % end function



function % a) prob 2 red balls and 1 green bau % b) if 3 balls are green, prob that box 1 was chosen %box 1 %box 2 %total13 counter - 0; counter2 - 0; processes - 1000000; for box_choice - rand; results[0 0] choice1 - rand; choice2 - rand; choice3 - rand; % [red, green] i - 1:processe:s box choice > 0.5 %box 1 ofprintf ("box 1 chosen:") 1 choice1 > 0.75 results2 -results[1 0] else results2-results[0 1]; end
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
