フィルターのクリア

coin toss game simulation

1 回表示 (過去 30 日間)
Lewis Watson
Lewis Watson 2012 年 10 月 26 日
firstly I am very new to Matlab and I apoligise if this seems difficult to understand. I have a simple game in which a coin is tossed 10 times, each time the score is heads you score +1 if tails you score -1. you can stop at any time between 1 and 10 and you're winnings will be your score divided by the number of tosses
I wish to write a simple simulation that genrates an array with all the scores at points 1 to 10.
(I am starting with the score at S(0) being -1)
e.g for i= 1:N (N probably = 10), S(i)= S(i-1) + (random score of +1 or -1), [S(0)/1, S(1)/2, ...... ,S(N)/(N+1)]

回答 (1 件)

Image Analyst
Image Analyst 2012 年 10 月 26 日
Sounds like a homework problem. If so, see this link: http://www.mathworks.com/matlabcentral/answers/8626-how-do-i-get-help-on-homework-questions-on-matlab-answers. Otherwise look into rand() or randi(). You might also look into cumsum(). I think you could do this in only two lines of code using those functions.
  2 件のコメント
Lewis Watson
Lewis Watson 2012 年 10 月 26 日
It is indeed, I know how the program would work and can write in pesudo code, I'm just struggling with matlab.
José-Luis
José-Luis 2012 年 10 月 26 日
編集済み: José-Luis 2012 年 10 月 26 日
Also, I sort of already answered that question here, which in hindsight was probably not the best of ideas since it is a homework question, but it doesn't exactly do what you ask, so you need to modify it a little.
Instead of asking the same question again, we could help you better if you explained what you did not understand. If you are really new to Matlab, arm yourself with some patience and go through the getting started section of the documentation.

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

カテゴリ

Help Center および File ExchangeProbability についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by