# Average positions in a 1D random walk

I wrote this to simulate m random walks of n steps

Li[n_] := 2*RandomVariate[BinomialDistribution[n, 1/2], n] - n;
Tb[n_, m_] := Table[Li[n], {i, 1, m}];
y = table[10, 10]


The walker has to start at (0) I don't know how to adjust the function to get that. And I have to write a function that finds the average position after n steps and the average of the square of the distance between the walker after n steps and the origin without using Mean or StandardDeviation. We can take n=10 and m=10

For the average position I wrote that but I don't get the same result as when I use Mean ( and I think I have to do that in one function)

 averagepos[n_] := Total[y]/n;
Total[averagepos[n]]


For the average of the square of the distance walker-origin I don't get what I should calculate.

• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! Oct 9, 2015 at 0:56
• Shouldn't a 1-dimensional random walk start at 0, not {0, 0}? Oct 9, 2015 at 1:57
• You can use Prepend to get the right starting position, like I did here. Oct 9, 2015 at 2:03

To make sure all the walks start at {0}, you could use

Li[n_] := 2*RandomVariate[BinomialDistribution[n, 1/2], n] - n;
Tb[n_, m_] := Table[Join[{0}, Li[n]], {i, 1, m}];
ListPlot[Tb[10, 5], Joined -> True]


Then the average distance for 1 run is calc using

    Ave[n_] := Abs[Total[Flatten[Tb[n, 1], 1]]]/n
N[Ave[1000]]
(* 0.891*)


You can repeat the process for m runs as well. The output is highly sensitive to the parameter (1/2 in this case) which appears in the BionomialDistribution

Regarding the remark about the mean, I don't see it going to zero. Try

Li[n_, p_] := 2*RandomVariate[BinomialDistribution[n, p], n] - n;
Tb[n_, p_, m_] := Table[Join[{0}, Li[n, p]], {i, 1, m}];
Ave[n_, p_] := Abs[Total[Flatten[Tb[n, p, 1], 1]]]/n
Aver[n_, p_, m_] := N[Sum[Ave[n, p]/m, {i, 1, m}]]
Manipulate[
Aver[n, p, m], {n, {100, 500, 1000}}, {p, 0.1,
1}, {m, {100, 200, 300}}]


For p=1/2, you get average < 1, for p values that deviate from 1/2, the average explodes. Unless of course, you have used some other relation for the mean.

• When I do that I get that the mean is always 0 , but I have to show that it tends to 0 when m is big Oct 9, 2015 at 6:06
• I found my error Oct 9, 2015 at 6:19
• For the mean it is correct I was just extracting the wrong element from the tab to calculate it ! thanks for the answer :) Oct 9, 2015 at 6:57