Advertisement
makispaiktis

Tutorial - Test Biased Coin

Aug 11th, 2021 (edited)
1,232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.45 KB | None | 0 0
  1. clc
  2. clear all
  3.  
  4. % MAIN FUNCTION
  5. p_heads = 0.25;
  6. n = 10000;
  7. testBiasedCoin(p_heads, n);
  8.  
  9. % AUXILIARY FUNCTIONS
  10. function face = biased_coin( p_heads )
  11.  
  12.     if rand < p_heads
  13.         face = 0;
  14.     else
  15.         face = 1;
  16.     end
  17. end
  18.  
  19. function testBiasedCoin( p_heads, n )
  20.     % Initialize
  21.     A = zeros(n,1);
  22.     for i=1:n
  23.         A(i) = biased_coin(p_heads);
  24.     end
  25.     hist(A);
  26.     title('probHeads = 0.25, 0 = head, 1 = tail');
  27. end
  28.  
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement