# Creating a dynamic plot directly from the recurrence relation

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}

Maybe try something like

ClearAll@plotter
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 == 7}, x, {t, 0, 16}]
,
PlotRange -> {0, 1}
]

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


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

• 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! 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. 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. 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. 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. Apr 3 '14 at 18:29