Binomial Simulator in Matlab with M= number of experiments

1 view (last 30 days)
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 Comment
Matt Trenton
Matt Trenton on 22 Sep 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?

Sign in to comment.

Accepted Answer

Jeff Miller
Jeff Miller on 22 Sep 2018
Instead of
k(j)=B(1);
you need
k(j)=sum(B);
  3 Comments
Jeff Miller
Jeff Miller on 23 Sep 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.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!