0

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 
dirty_sanchez
  • 69
  • 1
  • 1
  • 12
  • Do you want to generate N coin tosses with a certain bias? Or do you want to estimate the bias from statistics of N coin tosses? It sounds like you wan to do both, both if you know the bias why do you want to estimate it? – Silas Apr 27 '14 at 21:23
  • yes, I would like to generate N coin tosses with a certain bias with respect to each bias value in the vector X. vector x is an observation vector. Id like to select an arbitarily value from the vector x and flip coins and see if the observation matches the the bias value, if it does not it fails etc. There is no estimation involved. thanks – dirty_sanchez Apr 27 '14 at 22:53
  • @Silas I found this site that has information about the problem. I'm seeking to implement concepts for this problem from the site. The site is http://www.pcoder.net/change-an-unfairly-biased-coin-to-a-fair-coin-a-classical-randomized-algorithm/#axzz308a9TpBx – dirty_sanchez Apr 28 '14 at 03:16
  • function outcome = mysim(p, N) P = cumsum(p); u = rand(1, N); outcome = zeros(1, N); % A blank array for holding the outcomes for n=100:100:N, h = find(u(n)

    – dirty_sanchez Apr 28 '14 at 03:36
  • It doesnt make sense to me. What do you mean by "if the observation matches the bias value"? When you repeat the coin toss many times, the frequency of heads will converge to the probability of heads. It doesnt really make sense to consider individual tosses. The two links you have posted show how to overcome bias in the coin toss and get an unbiased result. Is that what you want to do? – Silas Apr 28 '14 at 07:05
  • @Silas, yes that is what I would like to do, just as depicted by the two sites. the only thing is I will need to arbitrarily select a value from the dataset for each N coin toss. Any pointers, I will be grateful. Thanks – dirty_sanchez Apr 29 '14 at 01:47
  • @Silas, i have matlab code for the simulation on the webpage. But I'm still confused about how to incorporate from 100 to 1000 trials in steps of 100. – dirty_sanchez Apr 29 '14 at 18:29

0 Answers0