8
$\begingroup$

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: enter image description here

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. enter image description here

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.

$\endgroup$

3 Answers 3

5
$\begingroup$
ListLinePlot[Accumulate @ Prepend[RandomChoice[{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}, 1000], {1, 1}], AspectRatio -> Automatic] 

enter image description here

Starting with some random data

rd = RandomChoice[{1, -1}, 2000]; ListLinePlot[Accumulate@rd] 

enter image description here

Creating a random walk similar to the one shown in your question

rw = Accumulate@Transpose[{rd[[;; 1000]], rd[[1001 ;;]]}]; ListLinePlot[rw, AspectRatio -> Automatic] 

enter image description here

and rotating it by 45°

rwr = rw.(RotationMatrix[45 Degree]/Sqrt[2]); ListLinePlot[rwr, AspectRatio -> Automatic] 

enter image description here

$\endgroup$
6
  • $\begingroup$ Oo! Very nice :] But I need to do that with the data that I already have. The whole point is that it's not randomly generated by a computer, but randomly generated by a person. $\endgroup$ Commented Mar 27, 2015 at 0:37
  • 1
    $\begingroup$ @Solarmew In my edit I show a way how to start with random data similar to yours, create the 2D random walk the same way you did, and than rotate it by 45 degrees. $\endgroup$ Commented Mar 27, 2015 at 1:10
  • $\begingroup$ @Solarmew Do you want the rotated data to be on a 1 x 1 grid as shown in the last plot of my answer or on a Sqrt[2] x Sqrt[2] grid as shown in the other answers? $\endgroup$ Commented Mar 27, 2015 at 1:22
  • 1
    $\begingroup$ Rotation is clockwise instead of CCW. see my solution in this thread for correct answer $\endgroup$ Commented Mar 27, 2015 at 1:37
  • 2
    $\begingroup$ @penguin77 Rotation is 45 degrees. For a -45 degrees rotation just replace RotationMatrix[45 Degree] with RotationMatrix[-45 Degree]. $\endgroup$ Commented Mar 27, 2015 at 8:48
4
$\begingroup$
rw = Accumulate@RandomChoice[{-1, 1}, 400]; ListLinePlot[rw, AspectRatio -> 1] 

enter image description here

rw2 = Transpose[{rw[[ ;; 200]], rw[[201 ;; ]]}]; llp2 = ListLinePlot[rw2, AspectRatio -> 1] 

enter image description here

To rotate llp2:

Show[MapAt[GeometricTransformation[#, RotationTransform[-45 Degree]] &, llp2, {1}], PlotRange -> All] 

enter image description here

Aside: Using InterpolationOrder->0 gives "axes-aligned" lines (but it does not actually correspond to rw2)

ListLinePlot[rw2, AspectRatio -> 1, InterpolationOrder -> 0] 

enter image description here

$\endgroup$
4
$\begingroup$

No need folding 1D graph to get a 2D Random walk in Mathematica. and the CCW easy in Mathematica. Here we go:

Generate data set for the random sequence with 2000 steps. Alternatively, you may use your "own generated" data set.

rdata = Accumulate[RandomChoice[{-1, 1}, {2000, 2}]] 

Now plot it with similar layout as your example

ListLinePlot[rdata, GridLines -> {{0}, Range[-40, 30, 10]}] 

Here the result (Nicer than Excel...much nicer,hi,hi,hi) enter image description here

Now you wish to turn it CCW, for whatever reason? Ok no problem Create a Transformation Function

r = RotationTransform[45 Degree, {{1, 0}, {0, 1}}] 

Apply this function....

 ListLinePlot[r @ rdata , GridLines -> {{0}, Range[-40, 30, 10]}] 

enter image description here

What you mean with Excel??? never heard about it...hi,hi,hi

$\endgroup$
0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.