Random process: Coin tossing

Hello,
Could anyone please help me to simulate the following?
Probability that first head appears on n-th toss.
Given the probability of getting Head after each toss is P, i.e., the coin is not a fair one so P is not equal to 1/2.
Any help will be highly appreciated.

回答 (1 件)

Image Analyst
Image Analyst 2016 年 7 月 19 日

0 投票

Try this
p = 0.5; % or whatever you want.
numTosses = 100; % Whatever
tossHist = zeros(1, numTosses);
for expt = 1 : 1000
% Get sample of p% heads with numTosses
heads = rand(1, numTosses) > p;
tossOfFirstHead = find(heads, 1, 'first');
tossHist(tossOfFirstHead) = tossHist(tossOfFirstHead) + 1;
end
bar(tossHist);
grid on;
xlim([1, find(tossHist>0, 1, 'last')]);

1 件のコメント

Anik Adhikary
Anik Adhikary 2016 年 7 月 19 日
Could you please explain the logic?

サインインしてコメントする。

タグ

質問済み:

2016 年 7 月 19 日

コメント済み:

2016 年 7 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by