4
$\begingroup$

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}

$\endgroup$
0

1 Answer 1

8
$\begingroup$

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[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.

$\endgroup$
5
  • $\begingroup$ 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! $\endgroup$
    – Remi.b
    Apr 3, 2014 at 15:41
  • $\begingroup$ @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. $\endgroup$ Apr 3, 2014 at 15:55
  • $\begingroup$ @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. $\endgroup$ Apr 3, 2014 at 16:03
  • $\begingroup$ 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. $\endgroup$
    – Remi.b
    Apr 3, 2014 at 16:22
  • $\begingroup$ @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. $\endgroup$ Apr 3, 2014 at 18:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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