Laboratory 04

October 7, 2005

Clear["Global`*"]

1.

Read in the dataset and, at the same time, put it into a Table with appropriate dimensions to group the data into lists with three elements.

RWData = 
        ReadList["randomwalk.dat", 
          Table[Number, {3}]];

    Dimensions[RWData]

Look at the first few rows of data:

Do[Print[RWData[[kk]]], {kk, 4}]

2.

Initialize Lists that will store data. I use two nested Do loops to accomplish this in a single step.

Do[Do[NumSteps[ii, jj] = {}, {ii, 0.5, 2. , 0.5}], {jj, 25, 100, 
        25}]

NumSteps[0.5, 50]

Now write a somewhat more ambitious routine to examine each row of data and place the number of steps into the appropriate list that we've initialized.

First define a function that will examine a given row of data and write the number of steps to the corresponding data set:

AddStepsToList[StepLength_, BorderPos_] :=  
      If[RWData[[NRow]][[1]] ==  
            StepLength  && RWData[[NRow]][[2]] ==  
            BorderPos, 
        AppendTo[
          NumSteps[StepLength, 
            BorderPos], RWData[[NRow]][[3]]]]

Next, define a function that will sort the data one row at a time until all 8000 rows are completed. Note use of nested Do loops that enable access to all 16 data sets we need to collect.

SortDataSet[NRow_] := 
      Do[Do[AddStepsToList[StepLength, BorderPos], {StepLength, 0.5, 2.0, 
            0.5}], {BorderPos, 25, 100, 25}]

Now sort all the data and check one data set:

Do[SortDataSet[NRow], {NRow, 8000}]

NumSteps[0.5, 25]
Dimensions[%]

OK, this looks good because there are 8000 rows of data to be sorted into 16 data sets, making the number of steps per dataset equal to 500.

3.

<< Graphics`MultipleListPlot`

To make the desired plots, we need to compose four data sets of the form {BorderPos,NoOfSteps}, one data set for each BorderPos.

Results[
        StepLength_] := {{25, Mean[NumSteps[StepLength, 25]]}, {50, 
          Mean[NumSteps[StepLength, 50]]}, {75, 
          Mean[NumSteps[StepLength, 75]]}, {100, 
          Mean[NumSteps[StepLength, 100]]}}

4.

Now repeat the process but this time include both the mean values and the standard deviations (in the form of "error bars") in the data set for plotting:

ResultsEBars[
        StepLength_] := {{{25, Mean[NumSteps[StepLength, 25]]}, 
          ErrorBar[StandardDeviation[NumSteps[StepLength, 25]]]}, {{50, 
            Mean[NumSteps[StepLength, 50]]}, 
          ErrorBar[StandardDeviation[NumSteps[StepLength, 50]]]}, {{75, 
            Mean[NumSteps[StepLength, 75]]}, 
          ErrorBar[StandardDeviation[NumSteps[StepLength, 75]]]}, {{100, 
            Mean[NumSteps[StepLength, 100]]}, 
          ErrorBar[StandardDeviation[NumSteps[StepLength, 100]]]}}

Here is a data set for plotting just the standard deviations:

ResultsStdDev[
        StepLength_] := {{25, 
          StandardDeviation[NumSteps[StepLength, 25]]}, {50, 
          StandardDeviation[NumSteps[StepLength, 50]]}, {75, 
          StandardDeviation[NumSteps[StepLength, 75]]}, {100, 
          StandardDeviation[NumSteps[StepLength, 100]]}}