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 CenterFile Exchange 中查找有关 Probability 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by