Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following recurrence relation that has no general solution:

$$x(t+1) = \frac{x^2 + x(1-x)(1-sh)}{x^2 + 2x(1-x)(1-sh) + (1-x)^2(1-s)}$$

In Mathematica language it gives:

x[t + 1] == (x[t]^2 + x[t] (1 - x[t]) (1 - s h))/(
   x[t]^2 + 2 x[t] (1 - x[t]) (1 - s h) + (1 - x[t])^2 (1 - s)  )

I'd like to plot $x$ as a function of $t$ (range{0,100}). How can I do this?

Also, that would be awesome if I could directly on my plot, modify the values of $h$ and $s$ in the range {0,1}

share|improve this question
up vote 6 down vote accepted

Maybe try something like

plotter[s_, h_] := 
 plotter[s, h] = 
  ListPlot[RecurrenceTable[{x[t + 1] == 
      N[(x[t]^2 + x[t] (1 - x[t]) (1 - s h))/(x[t]^2 + 
          2 x[t] (1 - x[t]) (1 - s h) + (1 - x[t])^2 (1 - s))], 
     x[0] == 7}, x, {t, 0, 16}]
   PlotRange -> {0, 1}

Manipulate[plotter[s, h], {{s, 1}, 1, 5, 1}, {{h, 2}, 2, 5, 1}]

which gives

Mathematica graphics

Before I applied a transformation to the recurrence table, but there must have been a mistake, because that now seems unnecessary.

share|improve this answer
Thanks a lot. I started today with Mathematica and I'm still far to understand this kind of stuff. Can you just give me a hint for E^-# & /@. It looks like random characters to me! – Remi.b Apr 3 '14 at 15:41
@Remi.b also the trick plotter[s_,t_]:=plotter[s,t]=body is called memoization. It prevents doing the same calculations twice. You can learn about this by using that search term on this site. – Jacob Akkerboom Apr 3 '14 at 15:55
@Remi.b please see my update. I removed that transformation with E^-#&. I must have made a mistake before, because the plots look nice without any transformation now. – Jacob Akkerboom Apr 3 '14 at 16:03
Yes, indeed it is much better now. For info, extending $t$ from 0 to 100 (not only 16) and allowing $s$ to range from -2 to 2 and $h$ from 0 to 1 only give nice results. And they make more sense for the biologists and recognize the Wright-Fisher equation. Thank you Jacob. – Remi.b Apr 3 '14 at 16:22
@Remi.b no problem :), thank you for giving some background to the problem. I think there may be a problem for s=1, h=1, maybe I should fix this if you think this is in the relevant range. – Jacob Akkerboom Apr 3 '14 at 18:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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