coin toss game simulation
2 views (last 30 days)
Show older comments
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)]
0 Comments
Answers (1)
Image Analyst
on 26 Oct 2012
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 Comments
José-Luis
on 26 Oct 2012
Edited: José-Luis
on 26 Oct 2012
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.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!