1
$\begingroup$
P = 1;
For[iter = 1, iter < 13, iter++, sigma = 1;
 a = RandomVariate[NormalDistribution[0, sigma], 500];
 Clear[theta, x];
 theta[i_] := theta[i] = theta[i - 1] + a[[i]];
 x[i_] := x[i] = x[i - 1] + P {Cos[theta[i]], Sin[theta[i]]};
 theta[0] = RandomReal[{0, 2 Pi}];
 x[0] = {0, 0};
 For[step = 1, step < 500, step++, r[iter, step] = x[step];]]
Show@Table[
  ListLinePlot[Table[r[s, i], {i, 500}], PlotStyle -> ColorData[1][s],
    PlotRange -> 35
      {{-1, 1}, {-1, 1}}], {s, 1, 12}]

This is my attempt to generate 12 families of a two-dimensional walk. I want to find the length of each random walk. Should I use "Length" function?

Thank you so much.

$\endgroup$
3
  • 1
    $\begingroup$ Replace step < 500 to step < =500 and use Table[Sum[Norm[r[s, i]], {i, 1, 500}], {s, 1, 12}] $\endgroup$
    – cvgmt
    Jan 26 at 2:31
  • 1
    $\begingroup$ As every step is of length: 1, the length is simply the number of steps. Or do you mean "length" to be the distance from the origin? $\endgroup$ Jan 26 at 10:55
  • $\begingroup$ You can use AnglePath to simplify constructing the walk. e.g. ListLinePlot[Table[AnglePath[RandomReal[{0, 2 Pi}, 500]], 12]]. $\endgroup$ Jan 28 at 18:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.