(* Content-type: application/mathematica *)

(*** Wolfram Notebook File ***)
(* http://www.wolfram.com/nb *)

(* CreatedBy='Mathematica 6.0' *)

(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[       145,          7]
NotebookDataLength[     30418,        997]
NotebookOptionsPosition[     25944,        848]
NotebookOutlinePosition[     26490,        869]
CellTagsIndexPosition[     26447,        866]
WindowFrame->Normal*)

(* Beginning of Notebook Content *)
Notebook[{

Cell[CellGroupData[{
Cell["PwM`RandomWalks`", "Section",
 InitializationGroup->True,
 CounterAssignments->{{"Chapter", 0}}],

Cell[TextData[{
 StyleBox["From",
  FontWeight->"Bold"],
 ": ",
 StyleBox[ButtonBox["Programming with Mathematica: An Introduction",
  BaseStyle->"Hyperlink",
  ButtonData->{
    URL["http://www.cambridge.org/wellin"], None},
  ButtonNote->"http://www.cambridge.org/wellin"],
  FontSlant->"Italic",
  FontVariations->{"Underline"->True}]
}], "Text",
 CellMargins->{{28, 10}, {7, 7}},
 FontSize->14],

Cell[CellGroupData[{

Cell["Metadata", "Subsection"],

Cell[BoxData[
 RowBox[{"(*", " ", 
  RowBox[{":", 
   RowBox[{"Name", ":", " ", "PwM`RandomWalks`"}]}], " ", "*)"}]], "Input"],

Cell[BoxData[
 RowBox[{"(*", " ", 
  RowBox[{":", 
   RowBox[{"Book", ":", " ", 
    RowBox[{"Programming", " ", "with", " ", 
     RowBox[{"Mathematica", ":", " ", 
      RowBox[{"An", " ", "Introduction"}]}]}]}]}], " ", "*)"}]], "Input"],

Cell[BoxData[
 RowBox[{"(*", " ", 
  RowBox[{":", 
   RowBox[{"Author", ":", " ", 
    RowBox[{"Paul", " ", "Wellin"}]}]}], " ", "*)"}]], "Input"],

Cell[BoxData[
 RowBox[{"(*", " ", 
  RowBox[{
   RowBox[{":", 
    RowBox[{"Summary", ":", " ", 
     RowBox[{
     "This", " ", "package", " ", "contains", " ", "the", " ", "random", " ", 
      "walk", " ", "functions", " ", "defined", " ", "throughout", " ", "the",
       " ", "book", " ", "but", " ", "particularly", " ", "in", " ", 
      "Chapter", " ", "13"}]}]}], ",", " ", 
   RowBox[{"Applications", " ", "and", " ", 
    RowBox[{"packages", "."}]}]}], " ", "*)"}]], "Input"],

Cell[BoxData[
 RowBox[{"(*", " ", 
  RowBox[{":", 
   RowBox[{"Context", ":", " ", "PwM`RandomWalks`"}]}], " ", "*)"}]], "Input"],

Cell[BoxData[
 RowBox[{"(*", " ", 
  RowBox[{":", 
   RowBox[{"Package", " ", 
    RowBox[{"Version", ":", " ", "1.0"}]}]}], " ", "*)"}]], "Input"],

Cell[BoxData[
 RowBox[{"(*", " ", 
  RowBox[{
   RowBox[{":", 
    RowBox[{"Copyright", ":", " ", 
     RowBox[{"Copyright", " ", "2012"}]}]}], ",", " ", 
   RowBox[{"Cambridge", " ", "University", " ", "Press"}]}], " ", 
  "*)"}]], "Input"],

Cell[BoxData[
 RowBox[{"(*", " ", 
  RowBox[{
   RowBox[{":", 
    RowBox[{"History", ":", " ", 
     RowBox[{
     "Version", " ", "1.0", " ", "by", " ", "Paul", " ", "Wellin"}]}]}], ",", 
   " ", 
   RowBox[{"Dec", " ", "2012"}]}], " ", "*)"}]], "Input"],

Cell[BoxData[
 RowBox[{"(*", " ", 
  RowBox[{
   RowBox[{":", 
    RowBox[{"Keywords", ":", " ", 
     RowBox[{"random", " ", "walks"}]}]}], ",", " ", 
   RowBox[{"lattice", " ", "walks"}], ",", " ", 
   RowBox[{"off", "-", 
    RowBox[{"lattice", " ", "walks"}]}], ",", " ", 
   RowBox[{"mean", "-", 
    RowBox[{"square", " ", "distance"}]}], ",", " ", 
   RowBox[{"radius", " ", "of", " ", "gyration"}]}], " ", "*)"}]], "Input"],

Cell[BoxData[
 RowBox[{"(*", " ", 
  RowBox[{":", 
   RowBox[{"Source", ":", " ", 
    RowBox[{"RandomWalks", ".", "nb"}]}]}], " ", "*)"}]], "Input"],

Cell[BoxData[
 RowBox[{"(*", " ", 
  RowBox[{":", 
   RowBox[{"Mathematica", " ", 
    RowBox[{"Version", ":", " ", 
     RowBox[{"8.0", ".4"}]}]}]}], " ", "*)"}]], "Input"]
}, Closed]],

Cell[CellGroupData[{

Cell["BeginPackage", "Subsection"],

Cell[BoxData[
 RowBox[{"Remove", "[", 
  RowBox[{"RandomWalk", ",", "ShowWalk", ",", "RadiusOfGyrationTensor"}], 
  "]"}]], "Input"],

Cell[BoxData[
 RowBox[{"BeginPackage", "[", "\"\<PwM`RandomWalks`\>\"", "]"}]], "Input"]
}, Open  ]],

Cell[CellGroupData[{

Cell["Usage statements", "Subsection"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"AnimateWalk", "::", "usage"}], "=", "\"\<AnimateWalk[\!\(\*
StyleBox[\"walk\", \"TI\"]\), \!\(\*
StyleBox[\"opts\", \"TI\"]\)] creates an animation of a two-dimensional \
random walk. A red ball will be seen to move to the current position in the \
walk to aid in visualizing the animation.\>\""}], ";"}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"Dimension", "::", "usage"}], "=", 
   "\"\<Dimension is an option to RandomWalk that determines whether the \
random walk will be a one-, two-, or three-dimensional walk. Possible values \
are 1, 2, or 3.\>\""}], ";"}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"LatticeWalk", "::", "usage"}], "=", 
   "\"\<LatticeWalk is an option to RandomWalk that determines whether the \
random walk will be a lattice walk or an off-lattice walk. Possible values \
are True and False.\>\""}], ";"}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"MeanSquareDistance", "::", "usage"}], "=", 
   "\"\<MeanSquareDistance[\!\(\*
StyleBox[\"t\", \"TI\"]\), \!\(\*
StyleBox[\"m\", \"TI\"]\)] computes the mean square end-to-end distance of \!\
\(\*
StyleBox[\"m\", \"TI\"]\) \!\(\*
StyleBox[\"t\", \"TI\"]\)-step lattice walks.\>\""}], ";"}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"MeanSquareRadiusGyration", "::", "usage"}], "=", 
   "\"\<MeanSquareRadiusGyration[\!\(\*
StyleBox[\"t\", \"TI\"]\), \!\(\*
StyleBox[\"m\", \"TI\"]\)] computes the mean square radius of gyration of a \
random walk. This is the sum of the squares of the distances of the step \
locations from the center of mass, divided by the number of step locations, \
where the center of mass is the sum of the step locations divided by the \
number of step locations.\>\""}], ";"}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"RadiusOfGyrationTensor", "::", "usage"}], "=", 
   "\"\<RadiusOfGyrationTensor[\!\(\*
StyleBox[\"walk\", \"TI\"]\)] computes the radius of gyration tensor for the \
random walk \!\(\*
StyleBox[\"walk\", \"TI\"]\).\>\""}], ";"}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"RandomWalk", "::", "usage"}], "=", "\"\<RandomWalk[\!\(\*
StyleBox[\"t\", \"TI\"]\)] generates a \!\(\*
StyleBox[\"t\", \"TI\"]\)-step random walk. The default behavior gives a \
two-dimensional lattice walk with steps in one of the four compass \
directions. The option LatticeWalk takes values True or False. The value of \
the option Dimension can be any of 1, 2, or 3.\>\""}], ";"}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"ShowWalk", "::", "usage"}], "=", "\"\<ShowWalk[\!\(\*
StyleBox[\"walk\", \"TI\"]\)] displays a one, two, or three-dimensional \
random walk connecting each site with a line. Graphics options can be passed \
to ShowWalk. E.g., ShowWalk[\!\(\*
StyleBox[\"walk\", \"TI\"]\), Background\[Rule]GrayLevel[0]] to produce a \
black background.\>\""}], ";"}]], "Input"]
}, Closed]],

Cell[CellGroupData[{

Cell["Warning messages", "Subsection"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"RandomWalk", "::", "rwn"}], "=", 
   "\"\<Argument `1` is not a positive integer.\>\""}], ";"}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"RandomWalk", "::", "baddim"}], "=", 
   "\"\<The value `1` of the option Dimension is not an integer between 1 and \
3.\>\""}], ";"}]], "Input"]
}, Closed]],

Cell[CellGroupData[{

Cell["Options", "Subsection"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"Options", "[", "RandomWalk", "]"}], "=", 
   RowBox[{"{", 
    RowBox[{
     RowBox[{"LatticeWalk", "\[Rule]", "True"}], ",", 
     RowBox[{"Dimension", "\[Rule]", "2"}]}], "}"}]}], ";"}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"Options", "[", "ShowWalk", "]"}], "=", 
   RowBox[{"Join", "[", 
    RowBox[{
     RowBox[{"Options", "[", "ListLinePlot", "]"}], ",", 
     RowBox[{"Options", "[", "Graphics3D", "]"}]}], "]"}]}], ";"}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"Options", "[", "AnimateWalk", "]"}], "=", 
   RowBox[{"Options", "[", "Animate", "]"}]}], ";"}]], "Input"]
}, Closed]],

Cell[CellGroupData[{

Cell["Begin private context", "Subsection"],

Cell[BoxData[
 RowBox[{"Begin", "[", "\"\<`Private`\>\"", "]"}]], "Input"]
}, Closed]],

Cell[CellGroupData[{

Cell["The function definitions", "Subsection"],

Cell[BoxData[
 RowBox[{
  RowBox[{"latticeWalk", "[", 
   RowBox[{"steps_", ",", "dim_"}], "]"}], ":=", " ", 
  RowBox[{"Module", "[", 
   RowBox[{
    RowBox[{"{", "w", "}"}], ",", "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{"w", "=", 
      RowBox[{"Accumulate", "[", 
       RowBox[{"RandomChoice", "[", 
        RowBox[{
         RowBox[{"Join", "[", 
          RowBox[{
           RowBox[{"IdentityMatrix", "[", "dim", "]"}], ",", 
           RowBox[{"-", 
            RowBox[{"IdentityMatrix", "[", "dim", "]"}]}]}], "]"}], ",", 
         "steps"}], "]"}], "]"}]}], ";", "\[IndentingNewLine]", 
     RowBox[{"If", "[", 
      RowBox[{
       RowBox[{"dim", "\[Equal]", "1"}], ",", 
       RowBox[{"Flatten", "[", "w", "]"}], ",", "w"}], "]"}]}]}], 
   "\[IndentingNewLine]", "]"}]}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{"offLatticeWalk", "[", 
   RowBox[{"t_", ",", "dim_"}], "]"}], ":=", 
  RowBox[{"Module", "[", 
   RowBox[{
    RowBox[{"{", 
     RowBox[{"f1", ",", "f2", ",", "f3"}], "}"}], ",", "\[IndentingNewLine]", 
    
    RowBox[{
     RowBox[{"f1", "=", 
      RowBox[{"RandomReal", "[", 
       RowBox[{
        RowBox[{"{", 
         RowBox[{
          RowBox[{"-", "1"}], ",", "1"}], "}"}], ",", "t"}], "]"}]}], ";", 
     "\[IndentingNewLine]", 
     RowBox[{"f2", "=", 
      RowBox[{"Map", "[", 
       RowBox[{
        RowBox[{
         RowBox[{"{", 
          RowBox[{
           RowBox[{"Cos", "[", "#", "]"}], ",", 
           RowBox[{"Sin", "[", "#", "]"}]}], "}"}], "&"}], ",", 
        RowBox[{"RandomReal", "[", 
         RowBox[{
          RowBox[{"{", 
           RowBox[{"0", ",", 
            RowBox[{"2", " ", "\[Pi]"}]}], "}"}], ",", "t"}], "]"}]}], 
       "]"}]}], ";", "\[IndentingNewLine]", 
     RowBox[{"f3", "=", 
      RowBox[{"Table", "[", 
       RowBox[{
        RowBox[{
         RowBox[{"Function", "[", 
          RowBox[{
           RowBox[{"{", 
            RowBox[{"\[Theta]", ",", "u"}], "}"}], ",", 
           RowBox[{"{", 
            RowBox[{
             RowBox[{
              RowBox[{"Cos", "[", "\[Theta]", "]"}], 
              RowBox[{"Sqrt", "[", 
               RowBox[{"1", "-", 
                RowBox[{"u", "^", "2"}]}], "]"}]}], ",", 
             RowBox[{
              RowBox[{"Sin", "[", "\[Theta]", "]"}], 
              RowBox[{"Sqrt", "[", 
               RowBox[{"1", "-", 
                RowBox[{"u", "^", "2"}]}], "]"}]}], ",", "u"}], "}"}]}], 
          "]"}], "@@", 
         RowBox[{"{", 
          RowBox[{
           RowBox[{"RandomReal", "[", 
            RowBox[{"{", 
             RowBox[{"0", ",", 
              RowBox[{"2", "Pi"}]}], "}"}], "]"}], ",", 
           RowBox[{"RandomReal", "[", 
            RowBox[{"{", 
             RowBox[{
              RowBox[{"-", "1"}], ",", "1"}], "}"}], "]"}]}], "}"}]}], ",", 
        RowBox[{"{", "t", "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", 
     RowBox[{"Which", "[", "\[IndentingNewLine]", 
      RowBox[{
       RowBox[{"dim", "\[Equal]", "1"}], ",", 
       RowBox[{"Accumulate", "[", "f1", "]"}], ",", "\[IndentingNewLine]", 
       RowBox[{"dim", "\[Equal]", "2"}], ",", 
       RowBox[{"Accumulate", "[", "f2", "]"}], ",", "\[IndentingNewLine]", 
       RowBox[{"dim", "\[Equal]", "3"}], ",", 
       RowBox[{"Accumulate", "[", "f3", "]"}]}], "\[IndentingNewLine]", 
      "]"}]}]}], "]"}]}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{"RandomWalk", "[", 
   RowBox[{"t_", ",", 
    RowBox[{"OptionsPattern", "[", "]"}]}], "]"}], ":=", 
  RowBox[{"Module", "[", 
   RowBox[{
    RowBox[{"{", 
     RowBox[{"dim", ",", "latticeQ"}], "}"}], ",", "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{
      RowBox[{"{", 
       RowBox[{"latticeQ", ",", "dim"}], "}"}], "=", 
      RowBox[{"OptionValue", "[", 
       RowBox[{"{", 
        RowBox[{"LatticeWalk", ",", "Dimension"}], "}"}], "]"}]}], ";", 
     "\[IndentingNewLine]", 
     RowBox[{"Which", "[", "\[IndentingNewLine]", 
      RowBox[{
       RowBox[{"!", 
        RowBox[{"(", 
         RowBox[{
          RowBox[{"IntegerQ", "[", "t", "]"}], "&&", 
          RowBox[{"t", ">", "0"}]}], ")"}]}], ",", 
       RowBox[{"Message", "[", 
        RowBox[{
         RowBox[{"RandomWalk", "::", "\"\<rwn\>\""}], ",", "t"}], "]"}], ",", 
       "\[IndentingNewLine]", 
       RowBox[{"!", 
        RowBox[{"(", 
         RowBox[{
          RowBox[{"IntegerQ", "[", "dim", "]"}], "&&", 
          RowBox[{"1", "\[LessEqual]", "dim", "\[LessEqual]", "3"}]}], 
         ")"}]}], ",", 
       RowBox[{"Message", "[", 
        RowBox[{
         RowBox[{"RandomWalk", "::", "baddim"}], ",", "dim"}], "]"}], ",", 
       "\[IndentingNewLine]", "True", ",", 
       RowBox[{"If", "[", 
        RowBox[{"latticeQ", ",", 
         RowBox[{"latticeWalk", "[", 
          RowBox[{"t", ",", "dim"}], "]"}], ",", 
         RowBox[{"offLatticeWalk", "[", 
          RowBox[{"t", ",", "dim"}], "]"}]}], "]"}]}], "\[IndentingNewLine]", 
      "]"}]}]}], "\[IndentingNewLine]", "]"}]}]], "Input"],

Cell[BoxData[{
 RowBox[{
  RowBox[{
   RowBox[{"RandomWalk", "[", "x__", "]"}], "/;", 
   RowBox[{"Message", "[", 
    RowBox[{
     RowBox[{"RandomWalk", "::", "rwn"}], ",", "x"}], "]"}]}], ":=", 
  "Null"}], "\n", 
 RowBox[{
  RowBox[{
   RowBox[{
    RowBox[{"RandomWalk", "[", "]"}], "/;", 
    RowBox[{"Message", "[", 
     RowBox[{
      RowBox[{"General", "::", "argx"}], ",", "RandomWalk", ",", "0"}], 
     "]"}]}], ":=", "Null"}], ";"}]}], "Input"]
}, Closed]],

Cell[CellGroupData[{

Cell["Numerical analysis functions", "Subsection"],

Cell[BoxData[
 RowBox[{
  RowBox[{"MeanSquareDistance", "[", 
   RowBox[{"t_Integer", ",", "trials_Integer"}], "]"}], ":=", 
  "\[IndentingNewLine]", 
  RowBox[{"Mean", "[", 
   RowBox[{"Table", "[", 
    RowBox[{
     RowBox[{
      RowBox[{
       RowBox[{"SquaredEuclideanDistance", "[", 
        RowBox[{
         RowBox[{"First", "[", "#", "]"}], ",", 
         RowBox[{"Last", "[", "#", "]"}]}], "]"}], "&"}], " ", "[", " ", 
      RowBox[{"RandomWalk", "[", "t", "]"}], "]"}], ",", 
     RowBox[{"{", "trials", "}"}]}], "]"}], "]"}]}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{"squareRadiusGyration", "[", "t_Integer", "]"}], ":=", 
  RowBox[{"Module", "[", 
   RowBox[{
    RowBox[{"{", 
     RowBox[{"locs", "=", 
      RowBox[{"RandomWalk", "[", "t", "]"}]}], "}"}], ",", 
    "\[IndentingNewLine]", 
    FractionBox[
     RowBox[{"Total", "[", 
      RowBox[{"Map", "[", 
       RowBox[{
        RowBox[{
         RowBox[{"SquaredEuclideanDistance", "[", 
          RowBox[{"#", ",", 
           RowBox[{"N", "[", 
            RowBox[{"Mean", "[", "locs", "]"}], "]"}]}], "]"}], "&"}], ",", 
        "locs"}], "]"}], "]"}], 
     RowBox[{"t", "+", "1"}]]}], "]"}]}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{"MeanSquareRadiusGyration", "[", 
   RowBox[{"t_Integer", ",", "trials_Integer"}], "]"}], ":=", 
  RowBox[{"Mean", "[", 
   RowBox[{"Table", "[", 
    RowBox[{
     RowBox[{"squareRadiusGyration", "[", "t", "]"}], ",", 
     RowBox[{"{", "trials", "}"}]}], "]"}], "]"}]}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{"RadiusOfGyrationTensor", "[", "lis_", "]"}], ":=", 
  RowBox[{"Module", "[", 
   RowBox[{
    RowBox[{"{", 
     RowBox[{"cmx", ",", "cmy", ",", "xcoords", ",", "ycoords", ",", "xy"}], 
     "}"}], ",", "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{
      RowBox[{"{", 
       RowBox[{"cmx", ",", "cmy"}], "}"}], "=", 
      RowBox[{"Mean", "[", "lis", "]"}]}], ";", "\[IndentingNewLine]", 
     RowBox[{
      RowBox[{"{", 
       RowBox[{"xcoords", ",", "ycoords"}], "}"}], "=", 
      RowBox[{"Transpose", "[", "lis", "]"}]}], ";", "\[IndentingNewLine]", 
     RowBox[{"xy", "=", 
      RowBox[{
       RowBox[{
        RowBox[{"(", 
         RowBox[{"xcoords", "-", "cmx"}], ")"}], ".", 
        RowBox[{"(", 
         RowBox[{"ycoords", "-", "cmy"}], ")"}]}], "/", 
       RowBox[{"Length", "[", "lis", "]"}]}]}], ";", "\[IndentingNewLine]", 
     RowBox[{"{", 
      RowBox[{
       RowBox[{"{", 
        RowBox[{
         RowBox[{"Mean", "[", 
          SuperscriptBox[
           RowBox[{"(", 
            RowBox[{"xcoords", "-", "cmx"}], ")"}], "2"], "]"}], ",", "xy"}], 
        "}"}], ",", 
       RowBox[{"{", 
        RowBox[{"xy", ",", 
         RowBox[{"Mean", "[", 
          SuperscriptBox[
           RowBox[{"(", 
            RowBox[{"ycoords", "-", "cmy"}], ")"}], "2"], "]"}]}], "}"}]}], 
      "}"}]}]}], "\[IndentingNewLine]", "]"}]}]], "Input"]
}, Open  ]],

Cell[CellGroupData[{

Cell["Visualization functions", "Subsection"],

Cell[BoxData[
 RowBox[{
  RowBox[{"ShowWalk", "[", 
   RowBox[{
    RowBox[{"coords_", "?", "VectorQ"}], ",", 
    RowBox[{"opts", ":", 
     RowBox[{"OptionsPattern", "[", "]"}]}]}], "]"}], " ", ":=", 
  "\[IndentingNewLine]", "\t", 
  RowBox[{"ListLinePlot", "[", 
   RowBox[{"coords", ",", " ", 
    RowBox[{"FilterRules", "[", 
     RowBox[{
      RowBox[{"{", "opts", "}"}], ",", 
      RowBox[{"Options", "[", "ListLinePlot", "]"}]}], "]"}]}], 
   "]"}]}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{"ShowWalk", "[", 
   RowBox[{
    RowBox[{"coords", ":", 
     RowBox[{"{", 
      RowBox[{
       RowBox[{"{", 
        RowBox[{"_", ",", "_"}], "}"}], ".."}], "}"}]}], ",", 
    RowBox[{"opts", ":", 
     RowBox[{"OptionsPattern", "[", "]"}]}]}], "]"}], " ", ":=", 
  "\[IndentingNewLine]", "\t", 
  RowBox[{"ListLinePlot", "[", 
   RowBox[{"coords", ",", " ", 
    RowBox[{"Append", "[", 
     RowBox[{
      RowBox[{"FilterRules", "[", 
       RowBox[{
        RowBox[{"{", "opts", "}"}], ",", 
        RowBox[{"Options", "[", "ListLinePlot", "]"}]}], "]"}], ",", " ", 
      RowBox[{"AspectRatio", "\[Rule]", "Automatic"}]}], "]"}]}], 
   "]"}]}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{"ShowWalk", "[", 
   RowBox[{
    RowBox[{"coords", ":", 
     RowBox[{"{", 
      RowBox[{
       RowBox[{"{", 
        RowBox[{"_", ",", "_", ",", "_"}], "}"}], ".."}], "}"}]}], ",", 
    RowBox[{"opts", ":", 
     RowBox[{"OptionsPattern", "[", "]"}]}]}], "]"}], " ", ":=", 
  "\[IndentingNewLine]", "\t", 
  RowBox[{"Graphics3D", "[", 
   RowBox[{
    RowBox[{"Line", "[", "coords", "]"}], ",", " ", 
    RowBox[{"FilterRules", "[", 
     RowBox[{
      RowBox[{"{", "opts", "}"}], ",", 
      RowBox[{"Options", "[", "Graphics3D", "]"}]}], "]"}]}], 
   "]"}]}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{"AnimateWalk", "[", 
   RowBox[{"rw_", ",", 
    RowBox[{"opts", ":", 
     RowBox[{"OptionsPattern", "[", "]"}]}]}], "]"}], ":=", 
  RowBox[{"Module", "[", 
   RowBox[{
    RowBox[{"{", 
     RowBox[{"range", ",", 
      RowBox[{"len", "=", 
       RowBox[{"Length", "[", "rw", "]"}]}], ",", "steps", ",", "gr"}], "}"}],
     ",", "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{"range", "=", 
      RowBox[{"Map", "[", 
       RowBox[{
        RowBox[{
         RowBox[{"{", 
          RowBox[{
           RowBox[{"Min", "[", "#1", "]"}], ",", 
           RowBox[{"Max", "[", "#1", "]"}]}], "}"}], "&"}], ",", 
        RowBox[{"Transpose", "[", "rw", "]"}]}], "]"}]}], ";", 
     "\[IndentingNewLine]", 
     RowBox[{"gr", "=", 
      RowBox[{"If", "[", 
       RowBox[{
        RowBox[{
         RowBox[{
          RowBox[{"Dimensions", "[", "rw", "]"}], "[", 
          RowBox[{"[", "2", "]"}], "]"}], "\[Equal]", "2"}], ",", "Graphics", 
        ",", "Graphics3D"}], "]"}]}], ";", "\[IndentingNewLine]", 
     RowBox[{"Animate", "[", 
      RowBox[{
       RowBox[{"gr", "[", 
        RowBox[{
         RowBox[{"Line", "[", 
          RowBox[{"Take", "[", 
           RowBox[{"rw", ",", "steps"}], "]"}], "]"}], ",", 
         RowBox[{"PlotRange", "\[Rule]", "range"}], ",", 
         RowBox[{"PlotLabel", "\[Rule]", 
          RowBox[{"StringForm", "[", 
           RowBox[{"\"\<Walk length: ``\>\"", ",", "steps"}], "]"}]}]}], 
        "]"}], ",", "\[IndentingNewLine]", 
       RowBox[{"{", 
        RowBox[{
         RowBox[{"{", 
          RowBox[{"steps", ",", "2", ",", "\"\<Steps\>\""}], "}"}], ",", "2", 
         ",", "len", ",", "1"}], "}"}], ",", "opts"}], "]"}]}]}], 
   "]"}]}]], "Input"]
}, Closed]],

Cell[CellGroupData[{

Cell["End private context", "Subsection"],

Cell[BoxData[
 RowBox[{"End", "[", "]"}]], "Input"]
}, Closed]],

Cell[CellGroupData[{

Cell["EndPackage", "Subsection"],

Cell[BoxData[
 RowBox[{"EndPackage", "[", "]"}]], "Input"]
}, Closed]]
}, Open  ]],

Cell[CellGroupData[{

Cell["Examples", "Section"],

Cell[CellGroupData[{

Cell["Load package", "Subsection"],

Cell[BoxData["Quit"], "Input"],

Cell[TextData[{
 "Load package (do ",
 StyleBox["not",
  FontSlant->"Italic"],
 " say \[OpenCurlyDoubleQuote]Yes\[CloseCurlyDoubleQuote] to evaluate init \
cells dialog)."
}], "Text"],

Cell[BoxData[
 RowBox[{"<<", "PWM`RandomWalks`"}]], "Input"]
}, Closed]],

Cell[CellGroupData[{

Cell["Test usage messages", "Subsection"],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"?", "AnimateWalk"}]], "Input"],

Cell[BoxData[
 StyleBox["\<\"AnimateWalk[\\!\\(\\*\\nStyleBox[\\\"walk\\\", \\\"TI\\\"]\\), \
\\!\\(\\*\\nStyleBox[\\\"opts\\\", \\\"TI\\\"]\\)] creates an animation of a \
two-dimensional random walk. A red ball will be seen to move to the current \
position in the walk to aid in visualizing the animation.\"\>", 
  "MSG"]], "Print", "PrintUsage"]
}, Closed]],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"?", "Dimension"}]], "Input"],

Cell[BoxData[
 StyleBox["\<\"Dimension is an option to RandomWalk that determines whether \
the random walk will be a one-, two-, or three-dimensional walk. Possible \
values are 1, 2, or 3.\"\>", "MSG"]], "Print", "PrintUsage"]
}, Closed]],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"?", "LatticeWalk"}]], "Input"],

Cell[BoxData[
 StyleBox["\<\"LatticeWalk is an option to RandomWalk that determines whether \
the random walk will be a lattice walk or an off-lattice walk. Possible \
values are True and False.\"\>", "MSG"]], "Print", "PrintUsage"]
}, Closed]],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"?", "MeanSquareDistance"}]], "Input"],

Cell[BoxData[
 StyleBox["\<\"MeanSquareDistance[\\!\\(\\*\\nStyleBox[\\\"t\\\", \\\"TI\\\"]\
\\), \\!\\(\\*\\nStyleBox[\\\"m\\\", \\\"TI\\\"]\\)] computes the mean square \
end-to-end distance of \\!\\(\\*\\nStyleBox[\\\"m\\\", \\\"TI\\\"]\\) \
\\!\\(\\*\\nStyleBox[\\\"t\\\", \\\"TI\\\"]\\)-step lattice walks.\"\>", 
  "MSG"]], "Print", "PrintUsage"]
}, Closed]],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"?", "MeanSquareRadiusGyration"}]], "Input"],

Cell[BoxData[
 StyleBox["\<\"MeanSquareRadiusGyration[\\!\\(\\*\\nStyleBox[\\\"t\\\", \
\\\"TI\\\"]\\), \\!\\(\\*\\nStyleBox[\\\"m\\\", \\\"TI\\\"]\\)] computes the \
mean square radius of gyration of a random walk. This is the sum of the \
squares of the distances of the step locations from the center of mass, \
divided by the number of step locations, where the center of mass is the sum \
of the step locations divided by the number of step locations.\"\>", 
  "MSG"]], "Print", "PrintUsage"]
}, Closed]],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"?", "RadiusOfGyrationTensor"}]], "Input"],

Cell[BoxData[
 StyleBox["\<\"RadiusOfGyrationTensor[\\!\\(\\*\\nStyleBox[\\\"walk\\\", \
\\\"TI\\\"]\\)] computes the radius of gyration tensor for the random walk \
\\!\\(\\*\\nStyleBox[\\\"walk\\\", \\\"TI\\\"]\\).\"\>", "MSG"]], "Print", \
"PrintUsage"]
}, Closed]],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"?", "RandomWalk"}]], "Input"],

Cell[BoxData[
 StyleBox["\<\"RandomWalk[\\!\\(\\*\\nStyleBox[\\\"t\\\", \\\"TI\\\"]\\)] \
generates a \\!\\(\\*\\nStyleBox[\\\"t\\\", \\\"TI\\\"]\\)-step random walk. \
The default behavior gives a two-dimensional lattice walk with steps in one \
of the four compass directions. The option LatticeWalk takes values True or \
False. The value of the option Dimension can be any of 1, 2, or 3.\"\>", 
  "MSG"]], "Print", "PrintUsage"]
}, Closed]],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"?", "ShowWalk"}]], "Input"],

Cell[BoxData[
 StyleBox["\<\"ShowWalk[\\!\\(\\*\\nStyleBox[\\\"walk\\\", \\\"TI\\\"]\\)] \
displays a one, two, or three-dimensional random walk connecting each site \
with a line. Graphics options can be passed to ShowWalk. E.g., \
ShowWalk[\\!\\(\\*\\nStyleBox[\\\"walk\\\", \\\"TI\\\"]\\), \
Background\[Rule]GrayLevel[0]] to produce a black background.\"\>", 
  "MSG"]], "Print", "PrintUsage"]
}, Closed]]
}, Closed]],

Cell[CellGroupData[{

Cell["Exercise the functions and options", "Subsection"],

Cell[BoxData[
 RowBox[{"ShowWalk", "[", 
  RowBox[{"RandomWalk", "[", 
   RowBox[{
    SuperscriptBox["10", "5"], ",", 
    RowBox[{"Dimension", "\[Rule]", "1"}]}], "]"}], "]"}]], "Input"],

Cell[BoxData[
 RowBox[{"ShowWalk", "[", 
  RowBox[{"RandomWalk", "[", 
   RowBox[{
    SuperscriptBox["10", "5"], ",", 
    RowBox[{"Dimension", "\[Rule]", "2"}], ",", 
    RowBox[{"LatticeWalk", "\[Rule]", "False"}]}], "]"}], "]"}]], "Input"],

Cell[BoxData[
 RowBox[{"ShowWalk", "[", 
  RowBox[{"RandomWalk", "[", 
   RowBox[{
    SuperscriptBox["10", "4"], ",", 
    RowBox[{"Dimension", "\[Rule]", "3"}], ",", 
    RowBox[{"LatticeWalk", "\[Rule]", "True"}]}], "]"}], "]"}]], "Input"],

Cell[BoxData[{
 RowBox[{
  RowBox[{"rw", "=", 
   RowBox[{"RandomWalk", "[", 
    RowBox[{"500", ",", 
     RowBox[{"Dimension", "\[Rule]", "3"}], ",", 
     RowBox[{"LatticeWalk", "\[Rule]", "False"}]}], "]"}]}], 
  ";"}], "\[IndentingNewLine]", 
 RowBox[{"AnimateWalk", "[", 
  RowBox[{"rw", ",", 
   RowBox[{"DisplayAllSteps", "\[Rule]", "True"}]}], "]"}]}], "Input"]
}, Closed]]
}, Open  ]]
},
AutoGeneratedPackage->Automatic,
ScreenStyleEnvironment->"Working",
WindowSize->{865, 838},
WindowMargins->{{Automatic, 472}, {Automatic, 33}},
ShowSelection->True,
Magnification:>FEPrivate`If[
  FEPrivate`Equal[FEPrivate`$VersionNumber, 6.], 1.25, 1.25 Inherited],
FrontEndVersion->"8.0 for Mac OS X x86 (32-bit, 64-bit Kernel) (October 5, \
2011)",
StyleDefinitions->"Default.nb"
]
(* End of Notebook Content *)

(* Internal cache information *)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[CellGroupData[{
Cell[567, 22, 102, 2, 83, "Section",
 InitializationGroup->True,
 CounterAssignments->{{"Chapter", 0}}],
Cell[672, 26, 398, 13, 34, "Text"],
Cell[CellGroupData[{
Cell[1095, 43, 30, 0, 42, "Subsection"],
Cell[1128, 45, 126, 3, 51, "Input"],
Cell[1257, 50, 239, 6, 51, "Input"],
Cell[1499, 58, 146, 4, 51, "Input"],
Cell[1648, 64, 486, 11, 112, "Input"],
Cell[2137, 77, 129, 3, 51, "Input"],
Cell[2269, 82, 147, 4, 51, "Input"],
Cell[2419, 88, 241, 7, 51, "Input"],
Cell[2663, 97, 256, 8, 51, "Input"],
Cell[2922, 107, 431, 11, 112, "Input"],
Cell[3356, 120, 149, 4, 51, "Input"],
Cell[3508, 126, 173, 5, 51, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[3718, 136, 34, 0, 31, "Subsection"],
Cell[3755, 138, 132, 3, 33, "Input"],
Cell[3890, 143, 88, 1, 33, "Input"]
}, Open  ]],
Cell[CellGroupData[{
Cell[4015, 149, 38, 0, 42, "Subsection"],
Cell[4056, 151, 362, 7, 141, "Input"],
Cell[4421, 160, 276, 6, 112, "Input"],
Cell[4700, 168, 282, 6, 112, "Input"],
Cell[4985, 176, 346, 9, 112, "Input"],
Cell[5334, 187, 527, 10, 201, "Input"],
Cell[5864, 199, 285, 7, 82, "Input"],
Cell[6152, 208, 444, 8, 171, "Input"],
Cell[6599, 218, 407, 8, 141, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[7043, 231, 38, 0, 31, "Subsection"],
Cell[7084, 233, 153, 4, 97, "Input"],
Cell[7240, 239, 191, 5, 158, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[7468, 249, 29, 0, 31, "Subsection"],
Cell[7500, 251, 245, 7, 97, "Input"],
Cell[7748, 260, 260, 7, 97, "Input"],
Cell[8011, 269, 153, 4, 97, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[8201, 278, 43, 0, 31, "Subsection"],
Cell[8247, 280, 74, 1, 97, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[8358, 286, 46, 0, 31, "Subsection"],
Cell[8407, 288, 805, 22, 110, "Input"],
Cell[9215, 312, 2560, 71, 205, "Input"],
Cell[11778, 385, 1626, 44, 167, "Input"],
Cell[13407, 431, 458, 15, 53, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[13902, 451, 50, 0, 31, "Subsection"],
Cell[13955, 453, 552, 15, 72, "Input"],
Cell[14510, 470, 637, 19, 88, "Input"],
Cell[15150, 491, 316, 8, 53, "Input"],
Cell[15469, 501, 1407, 40, 147, "Input"]
}, Open  ]],
Cell[CellGroupData[{
Cell[16913, 546, 45, 0, 42, "Subsection"],
Cell[16961, 548, 472, 14, 158, "Input"],
Cell[17436, 564, 696, 21, 218, "Input"],
Cell[18135, 587, 610, 19, 158, "Input"],
Cell[18748, 608, 1743, 49, 450, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[20528, 662, 41, 0, 31, "Subsection"],
Cell[20572, 664, 51, 1, 97, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[20660, 670, 32, 0, 31, "Subsection"],
Cell[20695, 672, 58, 1, 97, "Input"]
}, Closed]]
}, Open  ]],
Cell[CellGroupData[{
Cell[20802, 679, 27, 0, 83, "Section"],
Cell[CellGroupData[{
Cell[20854, 683, 34, 0, 42, "Subsection"],
Cell[20891, 685, 30, 0, 97, "Input"],
Cell[20924, 687, 183, 6, 96, "Text"],
Cell[21110, 695, 60, 1, 97, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[21207, 701, 41, 0, 31, "Subsection"],
Cell[CellGroupData[{
Cell[21273, 705, 54, 1, 97, "Input"],
Cell[21330, 708, 349, 5, 210, "Print"]
}, Closed]],
Cell[CellGroupData[{
Cell[21716, 718, 52, 1, 97, "Input"],
Cell[21771, 721, 228, 3, 210, "Print"]
}, Closed]],
Cell[CellGroupData[{
Cell[22036, 729, 54, 1, 97, "Input"],
Cell[22093, 732, 232, 3, 210, "Print"]
}, Closed]],
Cell[CellGroupData[{
Cell[22362, 740, 61, 1, 97, "Input"],
Cell[22426, 743, 352, 5, 147, "Print"]
}, Closed]],
Cell[CellGroupData[{
Cell[22815, 753, 67, 1, 97, "Input"],
Cell[22885, 756, 497, 7, 332, "Print"]
}, Closed]],
Cell[CellGroupData[{
Cell[23419, 768, 65, 1, 97, "Input"],
Cell[23487, 771, 256, 4, 147, "Print"]
}, Closed]],
Cell[CellGroupData[{
Cell[23780, 780, 53, 1, 97, "Input"],
Cell[23836, 783, 432, 6, 272, "Print"]
}, Closed]],
Cell[CellGroupData[{
Cell[24305, 794, 51, 1, 97, "Input"],
Cell[24359, 797, 397, 6, 272, "Print"]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell[24805, 809, 56, 0, 31, "Subsection"],
Cell[24864, 811, 188, 5, 63, "Input"],
Cell[25055, 818, 243, 6, 63, "Input"],
Cell[25301, 826, 242, 6, 63, "Input"],
Cell[25546, 834, 370, 10, 82, "Input"]
}, Closed]]
}, Open  ]]
}
]
*)

(* End of internal cache information *)
