Coin toss game simulation.

조회 수: 2 (최근 30일)
Lewis Watson
Lewis Watson 2012년 10월 21일
I'm trying to create a simple coin toss simulation, the game is as follows.
a player flips a coin, if heads they score 1, if tails -1. the player can stop at any point and win the current score divided by the number of games.
I want to create some code that simulates this for say 10 coin tosses and outputs the scores at each toss in for example a vector and the separately outputs the larges score.
any help would be hugely appreciated.

채택된 답변

José-Luis
José-Luis 2012년 10월 21일
편집: José-Luis 2012년 10월 21일
num_toss = 10;
%Toss the coin
vec_toss = rand(num_toss,1) > 0.5;
%Get the average:
mean_vec = cumsum(vec_toss)./(1:num_toss);
  댓글 수: 2
Lewis Watson
Lewis Watson 2012년 10월 21일
thank you very much.
Lewis Watson
Lewis Watson 2012년 10월 21일
I've opted to start the score at -1 as winning on the first toss is the best option.
so I would like the output to be a list/vector with elements being the 10 scores e.g
(-1, S1, S2 ..... S10)

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by