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

2 Answers 2

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$ Commented Jan 26, 2021 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$ Commented Jan 26, 2021 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$ Commented Jan 26, 2021 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$ Commented Jan 26, 2021 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$ Commented Jan 26, 2021 at 18:57

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.