function p = hw2(c); % Calculates probability that P(T>c), where T is the fraction of heads in 1000 flips % of a fair coin. % This is the same as P(B>c*1000), where B is binomial(1000,1/2) % calls ceil() which calculates integers above a given number, and % calls bincoeff() which calculates binomial coefficient % first integer greater than or equal to 1000*c % note: there are other ways to solve this, for example using the binomial CDF start = ceil(1000*c); p=0; for j=start:1000, p = p + bincoeff(1000,j)*( (.5)^1000 ); end; % end of function hw2()