Binomial Simulator in Matlab with M= number of experiments

1 visualización (últimos 30 días)
Matt Trenton
Matt Trenton el 22 de Sept. de 2018
Editada: Matt Trenton el 23 de Sept. de 2018
Hello, I must make a simulator that uses binomial distribution, where
  • n= number of tries in each experiment (is either 0(false) or 1(true)
  • p= success probability
  • m= number of experiments
If for example, let's say n=10, and m= 5, it means the simulator must run 10 tries of F/T events with the given probability (lets say its 0.3) 5 times, which means 50 individual events, and I must graph the results in a histogram with X= number of successes in every N and y= pdf
The thing is, I'm getting confused as how to handle the mix of n and m! Please help
  1 comentario
Matt Trenton
Matt Trenton el 22 de Sept. de 2018
My first idea was to make a cycle like this:
for j=1:m
for i=1:n
r=rand;
if r <= p
B(i)=1;
else
B(i)=0;
end
end
k(j)=B(1);
end
what the part that says k(j)=B(1) is trying to do it's to count all the successes (1s) of the first iteration of the cycle n, but pretty much to no avail. Any ideas?

Iniciar sesión para comentar.

Respuesta aceptada

Jeff Miller
Jeff Miller el 22 de Sept. de 2018
Instead of
k(j)=B(1);
you need
k(j)=sum(B);
  3 comentarios
Jeff Miller
Jeff Miller el 23 de Sept. de 2018
You are only running the simulator m=5 times. That's not nearly enough to ensure a good approximation to the theoretical distribution. Try m=5000.
Matt Trenton
Matt Trenton el 23 de Sept. de 2018
Such an idiotic mistake, thank you!

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by