So I have the following scenario:

Assume you have this organism that reproduces by itself. An organism either reproduces 0, 1, 2, or 3 organisms at a time. Assume they're asexual and reproduce only in sets of event. It can create:

no offspring with probability 11/32 1 offspring with probability 3/8 2 offspring with probability 3/16 3 offspring with probability 3/32

So, for example, an organism can create 0 offspring and stop creating forever, or it can create 1 offspring and stop forever, or it can create 2 offspring at once and stop forever, or it can create 3 offspring and stop forever.

How would I simulate 6 generations 100 times and find the average? I'm confused on the syntax. I feel like there's a lot of lists, tables, etc. to juggle and things to define.

I was thinking of doing something like this:

    (*define some counter variable*)
    (*Assume I start off with 1 person, so counter=1*)
    (*If X<=11/32, counter=counter, 11/32<X<=3/8, counter=counter+1, etc.*)
    (*That's generation 1)
    (*generation 2 has new counter individuals, and I repeat the process until 6 generations, potentially do something like (for i = 1 to counter, do the if X rules again*)

    Then stick on a bigger for loop from j = 1 to 100 at the top, print it, put it in a table, and average the table?

Does this sound reasonable? Can someone help me put this code to fruition? Also, does anyone know of a more efficient process?

  • $\begingroup$ This problem lends itself to recursion, which you really should master in order to get the most out of Mathematica. It is also a good idea to tell yourself to avoid for loops as much as possible, you have one in your algorithm - from that alone I could tell that that's not how experienced Mathematica users would implement this, before I even knew the problem. $\endgroup$ – C. E. Apr 21 '15 at 0:10
nextGen[n_] := Total@RandomChoice[{11/32, 3/8, 3/16, 3/32} -> {0, 1, 2, 3}, n]
simulate[n0_, nrOfGenerations_] := Total@NestList[nextGen, n0, nrOfGenerations]

Now we can simulate six generations a hundred times and compute the mean value. The initial number of organisms is 10 in this example.

Table[simulate[10, 6], {100}] // Mean // N
(* Out: 75.42 *)
| improve this answer | |
  • $\begingroup$ I think you forgot to add the existing population at each iteration (unless the OP means one-shot at reproduction per new generation). $\endgroup$ – ciao Apr 21 '15 at 6:21
  • $\begingroup$ @rasher The OP explicitly says that each generation can only reproduce one time ("...and stop creating forever.") $\endgroup$ – C. E. Apr 21 '15 at 9:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.