coin toss game simulation

조회 수: 2 (최근 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