next up previous
Next: Exercise 11.1: Random walks Up: A one-dimensional random walk Previous: Exact enumeration

Monte Carlo

The Monte Carlo method generates walks with different $N$ using the correct probabilities to ensure that the sampled walks are representative of the total population of possible walks. Clearly, the more walks we use, the close we will come to the exact result. In practice, we obtain the desired accuracy by comparing our results to the increasing number of trials until the results do not appear to vary within a tolerance.

The walker performs a steps to the right with probability $p$, and a step to the left with probability $q=(1-p)$. To simulate this, we pick a random number $r$ between 0 and 1. If $r \leq p$, we move one step to the right, otherwise, we move one step to the left. We repeat this operation $N$ times to obtain the net displacement $x$, and we accumulate the result to calculate the averages.

The pseudocode to generate a random configuration of $N$ steps would look like this:

  1. Start from $x=0$. Let $nstep = 0$.

  2. Pick a random number $r$ between 0 and 1.

  3. If $r \leq p$, then $x=x+1$, else $x=x-1$.

  4. Let $nstep = nstep + 1$. If $nstep < N$, repeat from step 2.

In order to determine the probability $P_N(x)$ we need to perform many trials and record the fraction of times that a walker is at position $x$ after $N$ steps. All the other quantities can be calculated at the end using the values we obtained for $P_N(x)$.


next up previous
Next: Exercise 11.1: Random walks Up: A one-dimensional random walk Previous: Exact enumeration
Adrian E. Feiguin 2004-06-01