Sampling 100 four-child families to estimate the probability that a four-child family has three girls

2 次查看(过去 30 天)
So I am able to create the familys and count how many familys have 3 daughters but I cant figure out how I would estimate the probability so that I could make a line plot
S = 2; % 1=boy 2=girl
R = 1; % coin fliped once
N = 4; % flip 4 coins at once
T = 100; % repeat 100 times
Out = randi([1 S],[R N T]);
formatSpec = "%x";
for i = 1:T
for j = 1:N
a = num2str(Out(:,j,i),formatSpec);
fam(i,j) = a;
end
end
match1 = ('1222'); %row you want
eq1 = sum(all(bsxfun(@eq,fam,match1),2)); %engine
match2 = ('2122'); %row you want
eq2 = sum(all(bsxfun(@eq,fam,match2),2)); %engine
match3 = ('2212'); %row you want
eq3 = sum(all(bsxfun(@eq,fam,match3),2)); %engine
match4 = ('2221'); %row you want
eq4 = sum(all(bsxfun(@eq,fam,match4),2)); %engine
f = [eq1 eq2 eq3 eq4];
fd = sum(f);

采纳的回答

Image Analyst
Image Analyst 2021-2-14
Scrap almost all that and do this:
S = 1; % 0=boy 1=girl
R = 1000000; % a million families with 4 children
N = 4; % flip 4 coins at once
Out = randi([0, S], [R, N]);
numGirls = sum(Out, 2);
fd = mean(numGirls == 3) / N
fd =
0.06245675

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by