I have a set of data that is just a "random" (generated by me, not by computer) sequence of length 2000 of 1's and (-1)'s. I used it to plot a 1-D random walk where +1 is step up, (-1) is step down, so my graph looked like this:
I was asked to break the sequence in half and plot the first half against the second to create a 2-D random walk graph. This was easy enough, I just did it in excel.
But I was then asked to turn the graph 45 degrees CCW so it looks like it's laid over a grid. So i guess if the first point is (1,1) it would go to (0,1), if it's (-1,1) it would go to (-1,0) and so on. I'm not sure how to do that. Please let me know if you know of a way to do it in Excel or Mathematica.
Answer
ListLinePlot[Accumulate @ Prepend[RandomChoice[{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}, 1000],
{1, 1}], AspectRatio -> Automatic]
Starting with some random data
rd = RandomChoice[{1, -1}, 2000];
ListLinePlot[Accumulate@rd]
Creating a random walk similar to the one shown in your question
rw = Accumulate@Transpose[{rd[[;; 1000]], rd[[1001 ;;]]}];
ListLinePlot[rw, AspectRatio -> Automatic]
and rotating it by 45°
rwr = rw.(RotationMatrix[45 Degree]/Sqrt[2]);
ListLinePlot[rwr, AspectRatio -> Automatic]
Comments
Post a Comment