Simulation of Weighted Coin Toss

조회 수: 6 (최근 30일)
MK96
MK96 2016년 11월 9일
댓글: Image Analyst 2016년 11월 9일
Attempting to simulate 4 coin tosses for a weighted coin, e.g. probability of heads = 0.9772 and tails = 0.0228
I want to list all the possible outcomes e.g;
HHHH = 0.9772^4
HHHT = 0.9772^3*0.0228 ...
Was wondering if there is a quicker way to list the outcomes as later on I will be simulating a larger amount of tosses.

답변 (1개)

Image Analyst
Image Analyst 2016년 11월 9일
Here's a way to compute heads or tails for a specified number of tosses and to list your strings of T's and H's.
% The probability of heads = 0.9772 and tails = 0.0228
pHeads = 0.9772;
numTosses = 200;
r = rand(1, numTosses) % Random numbers between 0 and 1
headTosses = r < pHeads
% Initialize character array to all tails
tosses = repmat('T', [1, numTosses])
% Assign the tosses that are heads to 'H'
tosses(headTosses) = 'H'
  댓글 수: 2
MK96
MK96 2016년 11월 9일
Thanks this helped a lot.
Do you know if there is any way to list all the possible outcomes and their probabilities?
Image Analyst
Image Analyst 2016년 11월 9일
Not off the top of my head, but for 200 coin tosses, there will be 2^200 possible combinations so there will not be enough time in the rest of this century to show them all to you. Why do you need to know that?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Chemistry에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by