I would like to simulate and plot multiple paths of the following stochastic difference equation, for any initial condition $\pi_{0} \in (0,1)$: $\pi_{t+1} = \gamma \pi_{t}$ with probability $1/3 \pi_{t}$ and $\pi_{t+1}= (1-\gamma) \pi_{t}$ with probability $2/3 \pi_{t}$, where $\gamma \in (0,1)$ is a parameter. No idea on how to approach the problem... Thanks a lot in advance!
pi0 = RandomReal[]
gamma = RandomReal[]
nextpi[pi_] := RandomChoice[{1/3*pi, 2/3*pi, 1 - pi} -> {gamma*pi, (1 - gamma)*pi, pi}]
trajectory = NestList[nextpi, pi0, 20]
ListPlot[trajectory]
Edit: In response to a comment, to create a table of many such plots for fixed pi0 and gamma:
trajectories = Table[NestList[nextpi, pi0, 20], {3}, {3}];
Grid[Map[ListPlot, trajectories, {2}]]
-
$\begingroup$ Hi Alan. This works perfectly, thanks a lot. Is there a way I could plot multiple paths, for a fixed pi0 and gamma? $\endgroup$ – Federico Nov 10 '20 at 15:50
-
-
$\begingroup$ Hi Alan. Thanks again. One more thing: what if I want to plot all the trajectories on the same graph? Sorry if I was not clear earlier... $\endgroup$ – Federico Nov 10 '20 at 16:31
-
$\begingroup$ Given the code in the answer, you can
ListLinePlot@Catenate@trajectories
. $\endgroup$ – Alan Nov 10 '20 at 17:25