5
$\begingroup$
b = RandomVariate[NormalDistribution[0, 1]];
ListlinePlot[b, PlotRange -> 35]

I am so new to Mathematica. I am trying to generate a 2-dimensional walk with variance =1 and plot this. However, I do not get its plot.

Can you help me? Thank you so much.

$\endgroup$
0
6
$\begingroup$
FoldList[Plus, {0, 0}, RandomVariate[NormalDistribution[0, 1], {500, 2}]] // Line // Graphics
$\endgroup$
7
$\begingroup$

Generate a list of random numbers and Accumulate:

b = Accumulate @ RandomVariate[NormalDistribution[0, 1], 500];

ListLinePlot[b, PlotRange -> 35]

enter image description here

For 2D, you can generate pairs of random numbers and Accumulate:

SeedRandom[1]

b2 = Accumulate @ RandomVariate[NormalDistribution[0, 1], {500, 2}];

ListLinePlot[b2, AspectRatio -> Automatic]

enter image description here

$\endgroup$
6
  • 2
    $\begingroup$ Why do we need {500,2}? Thank you so much! $\endgroup$
    – Bora
    Jan 26 '21 at 1:03
  • 3
    $\begingroup$ @Bora, RandomVariate[NormalDistribution[0, 1], {n, m}] generates an nXm matrix the entries of which are independent realizations of a random variable distributed NormalDistribution[0, 1]. $\endgroup$
    – kglr
    Jan 26 '21 at 1:10
  • 1
    $\begingroup$ One last question. Is there any way to start the random walk at the origin? I am really grateful for your help. $\endgroup$
    – Bora
    Jan 26 '21 at 1:49
  • 2
    $\begingroup$ Prepend the list with {0,0} before accumulating: b2 = Accumulate @ Prepend[RandomVariate[NormalDistribution[0, 1], {500, 2}], {0,0}] $\endgroup$
    – kglr
    Jan 26 '21 at 2:15
  • 1
    $\begingroup$ Assuming that the x and y axes are equivalent, it's probably worth using the AspectRatio -> Automatic option on ListLinePlot. $\endgroup$ Jan 26 '21 at 18:57

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.