Distribución de Bernoulli
Publicado por Daniel (2 intervenciones) el 16/09/2017 18:23:21
Me pueden ayudar con un código de matlab que genere números aleatorios con la distribución de Bernoulli y se obtenga la gráfica real y estimada. No encuentro nada acerca de aquello.
Encontré esto, como lo implemento para correrlo
The Binomial distribution is the discrete probability distribution of the number of successes (n) in a sequence of n independent yes/no experiments. The Bernoulli distribution is a special case of the Binomial distribution where n=1.
For example, if I toss a fair coin (p=0.5) 20 times, how many tails will I get?
Encontré esto, como lo implemento para correrlo
The Binomial distribution is the discrete probability distribution of the number of successes (n) in a sequence of n independent yes/no experiments. The Bernoulli distribution is a special case of the Binomial distribution where n=1.
1
2
3
4
5
6
7
8
function pdf = binopdf_(k,n,p)
m = 10000;
idx = 0;
for ii=1:m
idx = idx + double(nnz(rand(n,1) < p)==k);
end
pdf = idx/m;
end
For example, if I toss a fair coin (p=0.5) 20 times, how many tails will I get?
1
2
3
4
5
6
7
8
9
10
11
12
k = 0:20;
y_pdf = binopdf_(k,20,0.5);
y_cdf = cumsum(y_pdf);
figure;
subplot(1,2,1);
stem(k,y_pdf);
title('PDF');
subplot(1,2,2);
stairs(k,y_cdf);
axis([0 20 0 1]);
title('CDF');
Valora esta pregunta


0