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

Let $X_t$ be IID random variables in $[0,1]$ and CDF $F(\cdot)$. Suppose there exists a variable $Y_t$ given by:

$Y_1 = X_1$ and $Y_t = \phi(X_t, \overline{Y}_{t-1}), \forall t >1$, where

$\overline{Y}_{t} = \frac{1}{t} \sum_{i=1}^{t} Y_i$


$\phi^{\alpha} (x,y) = \left\{ \begin{array}{l l} \alpha x & \quad \text{if $x < y$}\\ x & \quad \text{if $x = y$}\\ \alpha x + (1 -\alpha) & \quad \text{if $x > y$}\\ \end{array} \right.$

I wish to run a simulation for 5 random walks (each with length 100) of $\overline{Y}_{t}$ where $X$ is drawn from a beta distribution with parameters (3,1) and $\alpha = 0.5$.

Normally, we should observe a convergence to the mean of $X$, i.e. $\mathbb{E}[X]$.

I have for $\phi^{\alpha} (x,y)$:

f[a_, {x_, y_}] := Piecewise[{{a x, x < y}, {x, x == y}, {1 - a + a x, x > y}}, 0]

My Beta distribution (with 100 iterations) can be expressed as:

RandomVariate[BetaDistribution[3, 1], 100]

I have difficulties to form the aggregation of data, and plot the evolution of $\overline{Y}_{t}$. Any help would be highly appreciated.

ListPlot[Table[<%simulated_data%>], PlotRange -> All, Joined -> True, Frame -> True]
share|improve this question
up vote 7 down vote accepted


f[a_, {x_, y_}] := Piecewise[{{a x, x < y}, {x, x == y}, {1 - a + a x, x > y}}, 0]

one simulation can be defined by

sim[length_] := 
  Module[{rv = RandomVariate[BetaDistribution[3, 1], length], y, yBar},
    y[1] = First@rv;
    yBar[t_Integer] := yBar[t] = 1/t * Sum[y[i], {i, 1, t}];
    y[t_Integer] := y[t] = f[0.5, {rv[[t]], yBar[t - 1]}];
    yBar /@ Range[length]

and then 5 simulations with a length of 100 can be plotted with

ListPlot[Table[sim[100], {5}], PlotRange -> All, Joined -> True, Frame -> True]


share|improve this answer
Thanks a lot @Karsten. Just edited your answer. y /@ Range[length] should be yBar /@ Range[length] in order to get the plot I wanted. – flo Aug 18 '14 at 12:46
@flo Thanks. Overlooked that bar. – Karsten 7. Aug 18 '14 at 12:53

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.