Implementing a Simple Algorithm with Loops

2 views (last 30 days)
MiauMiau
MiauMiau on 10 Jul 2013
Hi
I want to implement the following algorithm:
I have a value a = 1000. I want to draw a random number from the geometric distribution with probability of success 0.3 on the support [1,..,1000] (that means that the random number should lie between one and one thousand). When this is done, say I have the random number 5, I subtract this number from a, and would store then 995 and 5. Then I would randomly chose either 995 or 5: in case 995 is chosen I draw again a geometric random number with the same probability of success as before but with support [1,..,995] (In case 5 is chosen, I draw a random number from the geometric distribution on the support [1,...,5] etc.). Say now the random variable is 10. Then I would subtract 995 - 10 and would be left with the three pieces: 5, 985 and 10. Then I would again chose between 985 and 10 and repeat this procedure until I get stuck with a piece with length 1.
How can I implement this? For instance, I would be stuck with how to draw a geometric number which is bounded on a specific support in Matlab. Then the "pieces" I get, I am not sure if should them store in arrays or not.
Thanks

Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!