I have a question about a MATLAB problem dealing with a bias coin. Suppose I want to simulate a bias coin with the probability of turning up heads that behaves in accordance with the following dataset p ={0.5,0.4,0.3,0.2, 0.1}
.
How would I arbitrarily select an hypothetical coin from this data-set and determine if it is unbiased in MATLAB for a coin flipped N times for N is 100 to 1000 in step-size of 100. Since I have limited knowledge of Matlab, I am hoping to get some pointers to aid in this project. I found this site that has some pointers http://www.wikihow.com/Simulate-a-Fair-Coin-Toss-With-a-Biased-Coin
my matlab code for flipping the coin twice
function side = simulateOneToss
% Make two tosses (outcomes 0 and 1 could stand for heads and tails)
twoTosses = round(rand(1,2));
% If outcome is not HT or TH (both of which sum to 1), try again.
while sum(twoTosses) ~= 1
twoTosses = round(rand(1,2));
end
% Take first of the two tosses as the answer.
side = twoTosses(1);
my first code for the problem
function outcome = mysim(p, N)
P = cumsum(p);
u = rand(1, N);
outcome = zeros(1, N); % A blank array for holding the outcomes `enter code here`
for n=100:100:N,
h = find(u(n)<P, 1 );
outcome(n) = h;
end