TOSS

TOSS - BC=a./(b.*c);%computes the binomial coefficient...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
%Probability distribution for a fair coin,Binomial Coefficients n=input('enter number of tosses:'); k=0:n;% the coin is tossed n times N=n*ones(1,n+1);% vectorizes n so we can do calculations a=factorial(N);% computes the factorial of each term in the vector N b=factorial(k);% computes the factorial of each term in the vector k c=factorial(N-k);%subtracts each elt of k from the corresponding elt of N and computes the factorial of each term in the new vector
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: BC=a./(b.*c);%computes the binomial coefficient P=BC/(2^n);% computes the probability of k heads in n tosses S=sum(P);%sums the probability disp([k' P']);%displays the probabilities disp([k' BC']);%displays the binomial coefficients disp(S);%displays the sum of probabilities which should equal one subplot(1,2,1);%these commands plot a graph and a bar graph of the data on the same plot plot(k,P,'r'),grid; subplot(1,2,2); bar(k,P); Type...
View Full Document

Ask a homework question - tutors are online