Bernoulli trial
丟m個硬幣,重複n次,每次正面x個
function bernoulli(m,n)
y = zeros(1,m+1);
for i = 1:n
x = 0;
for j = 1:m
if (1==randi(2))
x = x + 1;
end
end
y(x+1) = y(x+1) + 1;
end
bar(y);
另外這個是亂做的,感覺沒啥意思
function test(n,m)
y = zeros(1,m);
for i = 1:n
x = 0;
for j = 1:m
x = x + rand;
end
p = x/m;
y(i) = p;
end
y = sort(y);
hist(y,100);