(* Content-type: application/vnd.wolfram.mathematica *)

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

(* CreatedBy='Mathematica 8.0' *)

(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[       157,          7]
NotebookDataLength[     47663,       1561]
NotebookOptionsPosition[     40937,       1332]
NotebookOutlinePosition[     41404,       1353]
CellTagsIndexPosition[     41361,       1350]
WindowFrame->Normal*)

(* Beginning of Notebook Content *)
Notebook[{

Cell[CellGroupData[{
Cell["PwM`Chap08Numerics`", "Section",
 InitializationGroup->True],

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`Chap08Numerics`"}]}], " ", "*)"}]], "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", " ", "functions", 
      " ", "defined", " ", "in", " ", "Chapter", " ", "8"}]}]}], ",", " ", 
   RowBox[{"Numerics", "."}]}], " ", "*)"}]], "Input"],

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

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

Cell[BoxData[
 RowBox[{"(*", " ", 
  RowBox[{
   RowBox[{":", "Copyright", ":", " ", 
    RowBox[{"Copyright", " ", "2012"}]}], ",", " ", 
   RowBox[{"Paul", " ", 
    RowBox[{"R", ".", " ", "Wellin"}]}]}], " ", "*)"}]], "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", ":", " ", "autocorrelation"}]}], ",", " ", 
   RowBox[{"condition", " ", "number"}], ",", " ", "correlogram", ",", " ", 
   RowBox[{"digit", " ", "sum"}], ",", " ", "eigenvector", ",", " ", 
   RowBox[{"root", " ", "finding"}], ",", " ", 
   RowBox[{"lag", " ", "plot"}], ",", " ", 
   RowBox[{"radius", " ", "of", " ", "gyration"}], ",", " ", 
   RowBox[{"sparse", " ", "array"}], ",", " ", 
   RowBox[{"tridiagonal", " ", "matrix"}]}], " ", "*)"}]], "Input"],

Cell[BoxData[
 RowBox[{"(*", " ", 
  RowBox[{":", 
   RowBox[{"Source", ":", " ", 
    RowBox[{"Chap08Numerics", ".", "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", "[", "RadiusOfGyrationTensor", "]"}]], "Input"],

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

Cell[CellGroupData[{

Cell["Usage messages for public functions", "Subsection"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"AutoCorrelation", "::", "usage"}], "=", 
   "\"\<AutoCorrelation[data, lag] returns the auto-correlation statistic of \
data with time lag, lag.\>\""}], ";"}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"ConditionNumber", "::", "usage"}], "=", 
   "\"\<ConditionNumber[mat] computes the condition number of the matrix mat.\
\>\""}], ";"}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"Correlogram", "::", "usage"}], "=", 
   "\"\<Correlogram[data, {lagmin, lagmax, incr}] displays a correlogram of \
data with time lags running from lagmin to lagmax in increments of \
incr.\>\""}], ";"}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"DigitSum", "::", "usage"}], "=", 
   "\"\<DigitSum[n, b] returns the digit sum of the number n in base \
b.\>\""}], ";"}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"EigenvectorPlot", "::", "usage"}], "=", 
   "\"\<EigenvectorPlot[data] displays an eigenvector plot of data.\>\""}], 
  ";"}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"findRoot", "::", "usage"}], "=", 
   "\"\<findRoot[fun, {var, init}] implements Newton's root-finding method to \
find a zero of the function fun[var] starting with an initial estimate of \
init.\>\""}], ";"}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"LagPlot", "::", "usage"}], "=", 
   "\"\<LagPlot[data, lag] returns a lag plot of data.\>\""}], ";"}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"MiddleSquareGenerator", "::", "usage"}], "=", 
   "\"\<MiddleSquareGenerator[n, seed] generates n + 1 random numbers \
starting with the seed and using von Neumann's middle square \
algorithm.\>\""}], ";"}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"RadiusOfGyrationTensor", "::", "usage"}], "=", 
   "\"\<RadiusOfGyrationTensor[lis] computes the radius of gyration tensor of \
the numerical list lis.\>\""}], ";"}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"RandomSparseArray", "::", "usage"}], "=", 
   "\"\<RandomSparseArray[n] returns an n \[Cross] n sparse array with random \
numbers between 0 and 1 on the diagonal and zeros everywhere else.\>\""}], 
  ";"}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"TridiagonalMatrix", "::", "usage"}], "=", 
   "\"\<TridiagonalMatrix[n, p, q] returns an n \[Cross] n tridiagonal matrix \
with element p on the diagonal and q on the off-diagonal.\>\""}], 
  ";"}]], "Input"]
}, Closed]],

Cell[CellGroupData[{

Cell["Options", "Subsection"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"Options", "[", "Correlogram", "]"}], "=", 
   RowBox[{"Join", "[", 
    RowBox[{
     RowBox[{"{", 
      RowBox[{"Coefficient", "\[Rule]", "0.05"}], "}"}], ",", 
     RowBox[{"Options", "[", "ListPlot", "]"}]}], "]"}]}], ";"}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"Options", "[", "findRoot", "]"}], "=", 
   RowBox[{"{", "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{"MaxIterations", "\[RuleDelayed]", "$IterationLimit"}], ",", 
     "\[IndentingNewLine]", 
     RowBox[{"PrecisionGoal", "\[Rule]", "Automatic"}], ",", 
     "\[IndentingNewLine]", 
     RowBox[{"WorkingPrecision", "\[Rule]", "Automatic"}]}], 
    "\[IndentingNewLine]", "}"}]}], ";"}]], "Input"]
}, Closed]],

Cell[CellGroupData[{

Cell["Private context", "Subsection"],

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

Cell[CellGroupData[{

Cell["Function definitions (public and private)", "Subsection"],

Cell[BoxData[
 RowBox[{
  RowBox[{"AutoCorrelation", "[", 
   RowBox[{"data_", ",", 
    RowBox[{"lag_:", "1"}]}], "]"}], ":=", 
  RowBox[{"Correlation", "[", 
   RowBox[{
    RowBox[{"Drop", "[", 
     RowBox[{"data", ",", "lag"}], "]"}], ",", 
    RowBox[{"Drop", "[", 
     RowBox[{"data", ",", 
      RowBox[{"-", "lag"}]}], "]"}]}], "]"}]}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{"ConditionNumber", "[", 
   RowBox[{"mat_", "?", "MatrixQ"}], "]"}], ":=", 
  RowBox[{"Module", "[", 
   RowBox[{
    RowBox[{"{", 
     RowBox[{"sv", "=", 
      RowBox[{"SingularValueList", "[", "mat", "]"}]}], "}"}], ",", 
    "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{"First", "[", "sv", "]"}], "/", 
     RowBox[{"Last", "[", "sv", "]"}]}]}], "]"}]}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{"Correlogram", "[", 
   RowBox[{"data_", ",", 
    RowBox[{"{", 
     RowBox[{"lagmin_", ",", "lagmax_", ",", 
      RowBox[{"incr_:", "1"}]}], "}"}], ",", 
    RowBox[{"opts", ":", 
     RowBox[{"OptionsPattern", "[", "]"}]}]}], "]"}], ":=", 
  "\[IndentingNewLine]", 
  RowBox[{"Module", "[", 
   RowBox[{
    RowBox[{"{", 
     RowBox[{"rh", ",", "corrs"}], "}"}], ",", "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{"rh", "=", 
      RowBox[{"OptionValue", "[", "Coefficient", "]"}]}], ";", 
     "\[IndentingNewLine]", 
     RowBox[{"corrs", "=", 
      RowBox[{"Table", "[", 
       RowBox[{
        RowBox[{"{", 
         RowBox[{"lag", ",", 
          RowBox[{"AutoCorrelation", "[", 
           RowBox[{"data", ",", "lag"}], "]"}]}], "}"}], ",", 
        RowBox[{"{", 
         RowBox[{"lag", ",", "lagmin", ",", "lagmax", ",", "incr"}], "}"}]}], 
       "]"}]}], ";", "\[IndentingNewLine]", 
     RowBox[{"ListPlot", "[", 
      RowBox[{"corrs", ",", "\[IndentingNewLine]", 
       RowBox[{"FilterRules", "[", 
        RowBox[{
         RowBox[{"{", "opts", "}"}], ",", 
         RowBox[{"Options", "[", "ListPlot", "]"}]}], "]"}], ",", 
       RowBox[{"AspectRatio", "\[Rule]", ".4"}], ",", 
       RowBox[{"Frame", "\[Rule]", "True"}], ",", 
       RowBox[{"Axes", "\[Rule]", "False"}], ",", 
       RowBox[{"PlotRange", "\[Rule]", "Automatic"}], ",", 
       RowBox[{"FrameTicks", "\[Rule]", 
        RowBox[{"{", 
         RowBox[{
          RowBox[{"{", 
           RowBox[{"Automatic", ",", "False"}], "}"}], ",", 
          RowBox[{"{", 
           RowBox[{"Automatic", ",", "False"}], "}"}]}], "}"}]}], ",", 
       "\[IndentingNewLine]", 
       RowBox[{"Epilog", "\[Rule]", 
        RowBox[{"{", 
         RowBox[{"Thin", ",", "Dashed", ",", 
          RowBox[{"Line", "[", 
           RowBox[{"{", 
            RowBox[{
             RowBox[{"{", 
              RowBox[{"0", ",", "rh"}], "}"}], ",", 
             RowBox[{"{", 
              RowBox[{
               RowBox[{
                RowBox[{"(", 
                 RowBox[{"lagmax", "-", "lagmin", "+", "1"}], ")"}], "/", 
                "incr"}], ",", "rh"}], "}"}]}], "}"}], "]"}], ",", 
          RowBox[{"Line", "[", 
           RowBox[{"{", 
            RowBox[{
             RowBox[{"{", 
              RowBox[{"0", ",", 
               RowBox[{"-", "rh"}]}], "}"}], ",", 
             RowBox[{"{", 
              RowBox[{
               RowBox[{
                RowBox[{"(", 
                 RowBox[{"lagmax", "-", "lagmin", "+", "1"}], ")"}], "/", 
                "incr"}], ",", 
               RowBox[{"-", "rh"}]}], "}"}]}], "}"}], "]"}]}], "}"}]}]}], 
      "]"}]}]}], "\[IndentingNewLine]", "]"}]}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{"DigitSum", "[", 
   RowBox[{"n_", ",", 
    RowBox[{"base_:", "10"}]}], "]"}], ":=", 
  RowBox[{"Total", "[", 
   RowBox[{"IntegerDigits", "[", 
    RowBox[{"n", ",", "base"}], "]"}], "]"}]}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{"EigenvectorPlot", "[", 
   RowBox[{
    RowBox[{"data", ":", 
     RowBox[{"{", 
      RowBox[{
       RowBox[{"{", 
        RowBox[{"_", ",", "_"}], "}"}], ".."}], "}"}]}], ",", "tensor_"}], 
   "]"}], ":=", 
  RowBox[{"Module", "[", 
   RowBox[{
    RowBox[{"{", 
     RowBox[{
      RowBox[{"T", "=", "tensor"}], ",", "cmx", ",", "cmy", ",", "x", ",", 
      "\[Lambda]1", ",", "\[Lambda]2", ",", "v1x", ",", "v1y", ",", "v2x", 
      ",", "v2y", ",", "l1", ",", "l2"}], "}"}], ",", "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{
      RowBox[{"{", 
       RowBox[{"\[Lambda]1", ",", "\[Lambda]2"}], "}"}], "=", 
      RowBox[{"Eigenvalues", "[", "T", "]"}]}], ";", "\[IndentingNewLine]", 
     RowBox[{
      RowBox[{"{", 
       RowBox[{"cmx", ",", "cmy"}], "}"}], "=", 
      RowBox[{"Mean", "[", "data", "]"}]}], ";", "\[IndentingNewLine]", 
     RowBox[{
      RowBox[{"{", 
       RowBox[{
        RowBox[{"{", 
         RowBox[{"v1x", ",", "v1y"}], "}"}], ",", 
        RowBox[{"{", 
         RowBox[{"v2x", ",", "v2y"}], "}"}]}], "}"}], "=", 
      RowBox[{"Eigenvectors", "[", "T", "]"}]}], ";", "\[IndentingNewLine]", 
     RowBox[{"l1", "=", 
      RowBox[{
       RowBox[{
        FractionBox["v1y", "v1x"], 
        RowBox[{"(", 
         RowBox[{"x", "-", "cmx"}], ")"}]}], "+", "cmy"}]}], ";", 
     "\[IndentingNewLine]", 
     RowBox[{"l2", "=", 
      RowBox[{
       RowBox[{
        FractionBox["v2y", "v2x"], 
        RowBox[{"(", 
         RowBox[{"x", "-", "cmx"}], ")"}]}], "+", "cmy"}]}], ";", 
     "\[IndentingNewLine]", 
     RowBox[{"Show", "[", 
      RowBox[{
       RowBox[{"{", "\[IndentingNewLine]", 
        RowBox[{
         RowBox[{"ListLinePlot", "[", 
          RowBox[{"data", ",", 
           RowBox[{"PlotStyle", "\[Rule]", "LightGray"}]}], "]"}], ",", 
         "\[IndentingNewLine]", 
         RowBox[{"Plot", "[", 
          RowBox[{"l1", ",", 
           RowBox[{"{", 
            RowBox[{"x", ",", 
             RowBox[{"cmx", "-", "\[Lambda]1"}], ",", 
             RowBox[{"cmx", "+", "\[Lambda]1"}]}], "}"}], ",", 
           RowBox[{"PlotStyle", "\[Rule]", 
            RowBox[{"{", 
             RowBox[{"Gray", ",", "Thick"}], "}"}]}]}], "]"}], ",", 
         "\[IndentingNewLine]", 
         RowBox[{"Plot", "[", 
          RowBox[{"l2", ",", 
           RowBox[{"{", 
            RowBox[{"x", ",", 
             RowBox[{"cmx", "-", "\[Lambda]2"}], ",", 
             RowBox[{"cmx", "+", "\[Lambda]2"}]}], "}"}], ",", 
           RowBox[{"PlotStyle", "\[Rule]", 
            RowBox[{"{", 
             RowBox[{"Gray", ",", "Thick"}], "}"}]}]}], "]"}], ",", 
         "\[IndentingNewLine]", 
         RowBox[{"Graphics", "[", 
          RowBox[{"{", 
           RowBox[{
            RowBox[{"PointSize", "[", "Large", "]"}], ",", "Red", ",", 
            RowBox[{"Point", "[", 
             RowBox[{"Mean", "[", "data", "]"}], "]"}]}], "}"}], "]"}]}], 
        "\[IndentingNewLine]", "}"}], ",", 
       RowBox[{"AspectRatio", "\[Rule]", "Automatic"}]}], "]"}]}]}], 
   "]"}]}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{"findRoot", "[", 
   RowBox[{"fun_", ",", 
    RowBox[{"{", 
     RowBox[{"var_", ",", 
      RowBox[{"init_", "?", "NumericQ"}]}], "}"}], ",", 
    RowBox[{"opts", ":", 
     RowBox[{"OptionsPattern", "[", "]"}]}]}], "]"}], ":=", 
  RowBox[{"Module", "[", 
   RowBox[{
    RowBox[{"{", 
     RowBox[{
     "maxIterations", ",", "precisionGoal", ",", "workingPrecision", ",", 
      "initx", ",", 
      RowBox[{"df", "=", 
       SuperscriptBox["fun", "\[Prime]",
        MultilineFunction->None]}], ",", "result"}], "}"}], ",", 
    "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{
      RowBox[{"{", 
       RowBox[{
       "maxIterations", ",", "precisionGoal", ",", "workingPrecision"}], 
       "}"}], "=", 
      RowBox[{"OptionValue", "[", 
       RowBox[{"{", 
        RowBox[{
        "MaxIterations", ",", "PrecisionGoal", ",", "WorkingPrecision"}], 
        "}"}], "]"}]}], ";", "\[IndentingNewLine]", 
     RowBox[{"If", "[", 
      RowBox[{
       RowBox[{"precisionGoal", "===", "Automatic"}], ",", 
       RowBox[{"precisionGoal", "=", 
        RowBox[{"Precision", "[", "init", "]"}]}]}], "]"}], ";", 
     RowBox[{"If", "[", 
      RowBox[{
       RowBox[{"workingPrecision", "===", "Automatic"}], ",", 
       RowBox[{"workingPrecision", "=", 
        RowBox[{"precisionGoal", "+", "10"}]}]}], "]"}], ";", 
     RowBox[{"initx", "=", 
      RowBox[{"SetPrecision", "[", 
       RowBox[{"init", ",", "workingPrecision"}], "]"}]}], ";", 
     RowBox[{"result", "=", 
      RowBox[{"SetPrecision", "[", 
       RowBox[{
        RowBox[{"FixedPoint", "[", 
         RowBox[{
          RowBox[{
           RowBox[{"#1", "-", 
            FractionBox[
             RowBox[{"fun", "[", "#1", "]"}], 
             RowBox[{"df", "[", "#1", "]"}]]}], "&"}], ",", "initx", ",", 
          "maxIterations"}], "]"}], ",", "precisionGoal"}], "]"}]}], ";", 
     "\[IndentingNewLine]", 
     RowBox[{"{", 
      RowBox[{"var", "\[Rule]", "result"}], "}"}]}]}], "]"}]}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{"LagPlot", "[", 
   RowBox[{"data_", ",", 
    RowBox[{"lag_", ":", "1"}], ",", 
    RowBox[{"opts", ":", 
     RowBox[{"OptionsPattern", "[", "ListPlot", "]"}]}]}], "]"}], ":=", 
  RowBox[{"ListPlot", "[", 
   RowBox[{
    RowBox[{"Transpose", "[", 
     RowBox[{"{", 
      RowBox[{
       RowBox[{"Drop", "[", 
        RowBox[{"data", ",", "lag"}], "]"}], ",", 
       RowBox[{"Drop", "[", 
        RowBox[{"data", ",", 
         RowBox[{"-", "lag"}]}], "]"}]}], "}"}], "]"}], ",", "opts"}], 
   "]"}]}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{"MiddleSquareGenerator", "[", 
   RowBox[{"n_", ",", 
    RowBox[{"seed_:", "1234567890"}]}], "]"}], ":=", 
  RowBox[{"Module", "[", 
   RowBox[{
    RowBox[{"{", 
     RowBox[{
      RowBox[{"tmp", "=", 
       RowBox[{"{", "seed", "}"}]}], ",", "s2", ",", "len", ",", 
      RowBox[{"s", "=", "seed"}]}], "}"}], ",", "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{"Do", "[", "\[IndentingNewLine]", 
      RowBox[{
       RowBox[{
        RowBox[{"s2", "=", 
         RowBox[{"IntegerDigits", "[", 
          RowBox[{"s", "^", "2"}], "]"}]}], ";", "\[IndentingNewLine]", 
        RowBox[{"len", "=", 
         RowBox[{"Length", "[", "s2", "]"}]}], ";", "\[IndentingNewLine]", 
        RowBox[{"s", "=", 
         RowBox[{"FromDigits", "[", 
          RowBox[{
           RowBox[{"If", "[", 
            RowBox[{
             RowBox[{"len", "<", "20"}], ",", 
             RowBox[{"PadLeft", "[", 
              RowBox[{"s2", ",", "20", ",", "0"}], "]"}], ",", "s2"}], "]"}], 
           "[", 
           RowBox[{"[", 
            RowBox[{"6", ";;", "15"}], "]"}], "]"}], "]"}]}], ";", 
        "\[IndentingNewLine]", 
        RowBox[{"AppendTo", "[", 
         RowBox[{"tmp", ",", "s"}], "]"}]}], ",", "\[IndentingNewLine]", 
       RowBox[{"{", "n", "}"}]}], "]"}], ";", "\[IndentingNewLine]", 
     "tmp"}]}], "\[IndentingNewLine]", "]"}]}]], "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"], "]"}]}], "}"}]}], 
      "}"}]}]}], "]"}]}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{"RandomSparseArray", "[", "n_Integer", "]"}], ":=", 
  RowBox[{"SparseArray", "[", 
   RowBox[{
    RowBox[{"{", 
     RowBox[{
      RowBox[{"Band", "[", 
       RowBox[{"{", 
        RowBox[{"1", ",", "1"}], "}"}], "]"}], "\[RuleDelayed]", 
      RowBox[{"RandomReal", "[", "]"}]}], "}"}], ",", 
    RowBox[{"{", 
     RowBox[{"n", ",", "n"}], "}"}]}], "]"}]}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{"TridiagonalMatrix", "[", 
   RowBox[{"n_", ",", "p_", ",", "q_"}], "]"}], ":=", 
  RowBox[{"SparseArray", "[", 
   RowBox[{
    RowBox[{"{", 
     RowBox[{
      RowBox[{
       RowBox[{"Band", "[", 
        RowBox[{"{", 
         RowBox[{"1", ",", "1"}], "}"}], "]"}], "\[Rule]", "p"}], ",", 
      RowBox[{
       RowBox[{"Band", "[", 
        RowBox[{"{", 
         RowBox[{"1", ",", "2"}], "}"}], "]"}], "\[Rule]", "q"}], ",", 
      RowBox[{
       RowBox[{"Band", "[", 
        RowBox[{"{", 
         RowBox[{"2", ",", "1"}], "}"}], "]"}], "\[Rule]", "q"}]}], "}"}], 
    ",", 
    RowBox[{"{", 
     RowBox[{"n", ",", "n"}], "}"}]}], "]"}]}]], "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[
 RowBox[{"Quit", "[", "]"}]], "Input"],

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

Cell[BoxData[
 RowBox[{"<<", "PWM`Chap08Numerics`"}]], "Input"]
}, Open  ]],

Cell[CellGroupData[{

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

Cell[CellGroupData[{

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

Cell[BoxData[
 StyleBox["\<\"AutoCorrelation[\\!\\(\\*\\nStyleBox[\\\"data\\\", \\\"TI\\\"]\
\\)\\!\\(\\*\\nStyleBox[\\\",\\\", \\\"TI\\\"]\\)\\!\\(\\*\\nStyleBox[\\\" \\\
\", \\\"TI\\\"]\\)\\!\\(\\*\\nStyleBox[\\\"lag\\\", \\\"TI\\\"]\\)] returns \
the auto-correlation statistic of \\!\\(\\*\\nStyleBox[\\\"data\\\", \\\"TI\\\
\"]\\) with time lag, \\!\\(\\*\\nStyleBox[\\\"lag\\\", \\\"TI\\\"]\\).\"\>", 
  "MSG"]], "Print", "PrintUsage"]
}, Closed]],

Cell[CellGroupData[{

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

Cell[BoxData[
 StyleBox["\<\"ConditionNumber[\\!\\(\\*\\nStyleBox[\\\"mat\\\", \
\\\"TI\\\"]\\)] computes the condition number of the matrix \
\\!\\(\\*\\nStyleBox[\\\"mat\\\", \\\"TI\\\"]\\).\"\>", "MSG"]], "Print", \
"PrintUsage"]
}, Closed]],

Cell[CellGroupData[{

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

Cell[BoxData[
 StyleBox["\<\"Correlogram[\\!\\(\\*\\nStyleBox[\\\"data\\\", \
\\\"TI\\\"]\\)\\!\\(\\*\\nStyleBox[\\\",\\\", \
\\\"TI\\\"]\\)\\!\\(\\*\\nStyleBox[\\\" \\\", \
\\\"TI\\\"]\\)\\!\\(\\*\\nStyleBox[\\\"{\\\", \
\\\"TI\\\"]\\)\\!\\(\\*\\nStyleBox[\\\"lagmin\\\", \
\\\"TI\\\"]\\)\\!\\(\\*\\nStyleBox[\\\",\\\", \
\\\"TI\\\"]\\)\\!\\(\\*\\nStyleBox[\\\" \\\", \
\\\"TI\\\"]\\)\\!\\(\\*\\nStyleBox[\\\"lagmax\\\", \
\\\"TI\\\"]\\)\\!\\(\\*\\nStyleBox[\\\",\\\", \
\\\"TI\\\"]\\)\\!\\(\\*\\nStyleBox[\\\" \\\", \
\\\"TI\\\"]\\)\\!\\(\\*\\nStyleBox[\\\"incr\\\", \
\\\"TI\\\"]\\)\\!\\(\\*\\nStyleBox[\\\"}\\\", \\\"TI\\\"]\\)] displays a \
correlogram of \\!\\(\\*\\nStyleBox[\\\"data\\\", \\\"TI\\\"]\\) with time \
lags running from \\!\\(\\*\\nStyleBox[\\\"lagmin\\\", \\\"TI\\\"]\\) to \
\\!\\(\\*\\nStyleBox[\\\"lagmax\\\", \\\"TI\\\"]\\) in increments of \
\\!\\(\\*\\nStyleBox[\\\"incr\\\", \\\"TI\\\"]\\).\"\>", "MSG"]], "Print", \
"PrintUsage"]
}, Closed]],

Cell[CellGroupData[{

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

Cell[BoxData[
 StyleBox["\<\"DigitSum[\\!\\(\\*\\nStyleBox[\\\"n\\\", \\\"TI\\\"]\\), \
\\!\\(\\*\\nStyleBox[\\\"b\\\", \\\"TI\\\"]\\)] returns the digit sum of the \
number \\!\\(\\*\\nStyleBox[\\\"n\\\", \\\"TI\\\"]\\) in base \
\\!\\(\\*\\nStyleBox[\\\"b\\\", \\\"TI\\\"]\\).\"\>", "MSG"]], "Print", \
"PrintUsage"]
}, Closed]],

Cell[CellGroupData[{

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

Cell[BoxData[
 StyleBox["\<\"EigenvectorPlot[\\!\\(\\*\\nStyleBox[\\\"data\\\", \\\"TI\\\"]\
\\)] displays an eigenvector plot of \\!\\(\\*\\nStyleBox[\\\"data\\\", \
\\\"TI\\\"]\\).\"\>", "MSG"]], "Print", "PrintUsage"]
}, Closed]],

Cell[CellGroupData[{

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

Cell[BoxData[
 StyleBox["\<\"findRoot[\\!\\(\\*\\nStyleBox[\\\"fun\\\", \
\\\"TI\\\"]\\)\\!\\(\\*\\nStyleBox[\\\",\\\", \
\\\"TI\\\"]\\)\\!\\(\\*\\nStyleBox[\\\" \\\", \
\\\"TI\\\"]\\)\\!\\(\\*\\nStyleBox[\\\"{\\\", \
\\\"TI\\\"]\\)\\!\\(\\*\\nStyleBox[\\\"var\\\", \
\\\"TI\\\"]\\)\\!\\(\\*\\nStyleBox[\\\",\\\", \
\\\"TI\\\"]\\)\\!\\(\\*\\nStyleBox[\\\" \\\", \
\\\"TI\\\"]\\)\\!\\(\\*\\nStyleBox[\\\"init\\\", \
\\\"TI\\\"]\\)\\!\\(\\*\\nStyleBox[\\\"}\\\", \\\"TI\\\"]\\)] implements \
Newton's root-finding method to find a zero of the function \
\\!\\(\\*\\nStyleBox[\\\"fun\\\", \\\"TI\\\"]\\)[\\!\\(\\*\\nStyleBox[\\\"var\
\\\", \\\"TI\\\"]\\)] starting with an initial estimate of \
\\!\\(\\*\\nStyleBox[\\\"init\\\", \\\"TI\\\"]\\).\"\>", "MSG"]], "Print", \
"PrintUsage"]
}, Closed]],

Cell[CellGroupData[{

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

Cell[BoxData[
 StyleBox["\<\"LagPlot[\!\(\*\\nStyleBox[\\\"data\\\", \\\"TI\\\"]\), \
\!\(\*\\nStyleBox[\\\"lag\\\", \\\"TI\\\"]\)] returns a lag plot of \
\!\(\*\\nStyleBox[\\\"data\\\", \\\"TI\\\"]\).\"\>", "MSG"]], "Print", \
"PrintUsage"]
}, Closed]],

Cell[CellGroupData[{

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

Cell[BoxData[
 StyleBox["\<\"MiddleSquareGenerator[\\!\\(\\*\\nStyleBox[\\\"n\\\", \\\"TI\\\
\"]\\), \\!\\(\\*\\nStyleBox[\\\"seed\\\", \\\"TI\\\"]\\)] generates \
\\!\\(\\*\\nStyleBox[\\\"n\\\", \\\"TI\\\"]\\)+1 random numbers starting with \
the seed and using von Neumann's middle square algorithm.\"\>", 
  "MSG"]], "Print", "PrintUsage"]
}, Closed]],

Cell[CellGroupData[{

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

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

Cell[CellGroupData[{

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

Cell[BoxData[
 StyleBox["\<\"RandomSparseArray[\!\(\*\\nStyleBox[\\\"n\\\", \\\"TI\\\"]\)] \
returns an \!\(\*\\nStyleBox[\\\"n\\\", \\\"TI\\\"]\)\!\(\*\\nStyleBox[\\\" \
\\\", \\\"TI\\\"]\)\[Cross] \!\(\*\\nStyleBox[\\\"n\\\", \\\"TI\\\"]\) sparse \
array with random numbers between 0 and 1 on the diagonal and zeros \
everywhere else.\"\>", "MSG"]], "Print", "PrintUsage"]
}, Closed]],

Cell[CellGroupData[{

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

Cell[BoxData[
 StyleBox["\<\"TridiagonalMatrix[\\!\\(\\*\\nStyleBox[\\\"n\\\", \
\\\"TI\\\"]\\), \\!\\(\\*\\nStyleBox[\\\"p\\\", \\\"TI\\\"]\\), \
\\!\\(\\*\\nStyleBox[\\\"q\\\", \\\"TI\\\"]\\)] returns an \
\\!\\(\\*\\nStyleBox[\\\"n\\\", \\\"TI\\\"]\\)\\!\\(\\*\\nStyleBox[\\\" \\\", \
\\\"TI\\\"]\\)\[Cross] \\!\\(\\*\\nStyleBox[\\\"n\\\", \\\"TI\\\"]\\) \
tridiagonal matrix with element \\!\\(\\*\\nStyleBox[\\\"p\\\", \
\\\"TI\\\"]\\) on the diagonal and \\!\\(\\*\\nStyleBox[\\\"q\\\", \
\\\"TI\\\"]\\) on the off-diagonal.\"\>", "MSG"]], "Print", "PrintUsage"]
}, Closed]]
}, Closed]],

Cell[CellGroupData[{

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

Cell[CellGroupData[{

Cell["Autocorrelation", "Subsubsection"],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{
  RowBox[{"data", "=", 
   RowBox[{"RandomInteger", "[", 
    RowBox[{
     RowBox[{"{", 
      RowBox[{"1", ",", "100"}], "}"}], ",", 
     RowBox[{"{", "1000", "}"}]}], "]"}]}], ";", 
  RowBox[{"N", "@", 
   RowBox[{"Table", "[", 
    RowBox[{
     RowBox[{"AutoCorrelation", "[", 
      RowBox[{"data", ",", "lag"}], "]"}], ",", 
     RowBox[{"{", 
      RowBox[{"lag", ",", "1", ",", "10", ",", "1"}], "}"}]}], 
    "]"}]}]}]], "Input"],

Cell[BoxData[
 RowBox[{"{", 
  RowBox[{
   RowBox[{"-", "0.09037601583103948`"}], ",", 
   RowBox[{"-", "0.008775946526364284`"}], ",", 
   RowBox[{"-", "0.03475354568785669`"}], ",", 
   RowBox[{"-", "0.006307430562435758`"}], ",", "0.04911238878665233`", ",", 
   "0.011394631011723846`", ",", 
   RowBox[{"-", "0.015118214559945635`"}], ",", 
   RowBox[{"-", "0.051412290123943355`"}], ",", 
   RowBox[{"-", "0.04446265755633902`"}], ",", 
   RowBox[{"-", "0.004245912984380781`"}]}], "}"}]], "Output"]
}, Closed]]
}, Closed]],

Cell[CellGroupData[{

Cell["ConditionNumber", "Subsubsection"],

Cell["\<\
Conpute the condition number of the first 8 Hilbert matrices.\
\>", "Text"],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"Map", "[", 
    RowBox[{"ConditionNumber", ",", 
     RowBox[{"Table", "[", 
      RowBox[{
       RowBox[{"HilbertMatrix", "[", "n", "]"}], ",", 
       RowBox[{"{", 
        RowBox[{"n", ",", "1", ",", "12"}], "}"}]}], "]"}]}], "]"}], ";"}], "//",
   "Timing"}]], "Input"],

Cell[BoxData[
 RowBox[{"{", 
  RowBox[{"0.42445400000000433`", ",", "Null"}], "}"}]], "Output"]
}, Closed]]
}, Closed]],

Cell[CellGroupData[{

Cell["Correlogram", "Subsubsection"],

Cell[BoxData[
 RowBox[{"temps", "=", 
  RowBox[{"WeatherData", "[", 
   RowBox[{"\"\<Chicago\>\"", ",", "\"\<MeanTemperature\>\"", ",", 
    RowBox[{"{", 
     RowBox[{
      RowBox[{"{", 
       RowBox[{"1992", ",", "1"}], "}"}], ",", 
      RowBox[{"{", 
       RowBox[{"2012", ",", "1"}], "}"}], ",", "\"\<Month\>\""}], "}"}], ",", 
    "\"\<Value\>\""}], "]"}]}]], "Input"],

Cell[BoxData[
 RowBox[{"Correlogram", "[", 
  RowBox[{"temps", ",", 
   RowBox[{"{", 
    RowBox[{"1", ",", "40"}], "}"}], ",", "0.35"}], "]"}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{"data", "=", 
   RowBox[{"Table", "[", 
    RowBox[{
     RowBox[{
      RowBox[{"RandomReal", "[", 
       RowBox[{"{", 
        RowBox[{
         RowBox[{"-", "2"}], ",", "2"}], "}"}], "]"}], 
      RowBox[{"Sin", "[", 
       RowBox[{"x", "+", 
        RowBox[{"RandomReal", "[", 
         RowBox[{"{", 
          RowBox[{
           RowBox[{"-", ".25"}], ",", ".25"}], "}"}], "]"}]}], "]"}]}], ",", 
     RowBox[{"{", 
      RowBox[{"x", ",", "0", ",", 
       RowBox[{"10", "\[Pi]"}], ",", ".05"}], "}"}]}], "]"}]}], 
  ";"}]], "Input"],

Cell[BoxData[
 RowBox[{"Correlogram", "[", 
  RowBox[{"data", ",", 
   RowBox[{"{", 
    RowBox[{"1", ",", "100"}], "}"}], ",", 
   RowBox[{"Coefficient", "\[Rule]", "0.1"}], ",", 
   RowBox[{"Filling", "\[Rule]", "Axis"}], ",", 
   RowBox[{"PlotRange", "\[Rule]", 
    RowBox[{"{", 
     RowBox[{
      RowBox[{"-", "0.2"}], ",", "0.2"}], "}"}]}], ",", 
   RowBox[{"FrameLabel", "\[Rule]", 
    RowBox[{"{", 
     RowBox[{
      RowBox[{"{", 
       RowBox[{"\"\<Auto-correlation coeff.\>\"", ",", "None"}], "}"}], ",", 
      RowBox[{"{", 
       RowBox[{"\"\<Lags\>\"", ",", "None"}], "}"}]}], "}"}]}]}], 
  "]"}]], "Input"]
}, Closed]],

Cell[CellGroupData[{

Cell["DigitSum", "Subsubsection"],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"DigitSum", "[", 
  RowBox[{"10", "!"}], "]"}]], "Input"],

Cell[BoxData["27"], "Output"]
}, Closed]]
}, Closed]],

Cell[CellGroupData[{

Cell["EigenvectorPlot", "Subsubsection"],

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

Cell[BoxData[{
 RowBox[{
  RowBox[{"coords", "=", 
   RowBox[{"RandomWalk", "[", 
    RowBox[{"10000", ",", 
     RowBox[{"Dimension", "\[Rule]", "2"}], ",", 
     RowBox[{"LatticeWalk", "\[Rule]", "False"}]}], "]"}]}], 
  ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"\[ScriptCapitalT]", "=", 
   RowBox[{"RadiusOfGyrationTensor", "[", "coords", "]"}]}], ";"}]}], "Input"],

Cell[BoxData[
 RowBox[{"EigenvectorPlot", "[", 
  RowBox[{"coords", ",", "\[ScriptCapitalT]"}], "]"}]], "Input"]
}, Closed]],

Cell[CellGroupData[{

Cell["findRoot", "Subsubsection"],

Cell[BoxData[
 RowBox[{"findRoot", "[", 
  RowBox[{"Sin", ",", 
   RowBox[{"{", 
    RowBox[{"x", ",", 
     FractionBox["14", "10"]}], "}"}], ",", 
   RowBox[{"PrecisionGoal", "\[Rule]", "40"}]}], "]"}]], "Input"]
}, Closed]],

Cell[CellGroupData[{

Cell["LagPlot", "Subsubsection"],

Cell[BoxData[
 RowBox[{
  RowBox[{"data", "=", 
   RowBox[{"BlockRandom", "[", 
    RowBox[{
     RowBox[{"SeedRandom", "[", 
      RowBox[{"1", ",", 
       RowBox[{"Method", "\[Rule]", 
        RowBox[{"{", 
         RowBox[{"\"\<Congruential\>\"", ",", 
          RowBox[{"\"\<Multiplier\>\"", "\[Rule]", "11"}], ",", 
          RowBox[{"\"\<Increment\>\"", "\[Rule]", "0"}], ",", 
          RowBox[{"\"\<Modulus\>\"", "\[Rule]", "17"}]}], "}"}]}]}], "]"}], 
     ";", "\[IndentingNewLine]", 
     RowBox[{"RandomReal", "[", 
      RowBox[{"1", ",", 
       RowBox[{"{", "1000", "}"}]}], "]"}]}], "]"}]}], ";"}]], "Input"],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"Table", "[", 
  RowBox[{
   RowBox[{"LagPlot", "[", 
    RowBox[{"data", ",", "lag", ",", 
     RowBox[{"ImageSize", "\[Rule]", "Small"}]}], "]"}], ",", 
   RowBox[{"{", 
    RowBox[{"lag", ",", "1", ",", "4"}], "}"}]}], "]"}]], "Input"],

Cell[BoxData[
 RowBox[{"{", 
  RowBox[{
   GraphicsBox[{{}, 
     {Hue[0.67, 0.6, 0.6], PointBox[CompressedData["
1:eJztz7GJQlEQhtGL24dgH8LrwdBQMDa1EsvYSFNDQwMFAwMRWVYREe1A3h3e
NOGZ5IcvGc5gMhtNe6WU608p7fbrrZvVsr2/Zr+r13Q9dps99pI99pR9UW+T
PfaZPfaQfVjvkT32P/u83i37uN4x+/vV3jl77D17/PnN3jm7zs/Pz8/Pz8/P
z8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/P
z8/Pz8/P/63+D5LkJkg=
       "]]}, {}},
    AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948],
    Axes->True,
    AxesOrigin->{0, 0},
    ImageSize->Small,
    PlotRange->{{0., 0.9411764705882353}, {0., 0.9411764705882353}},
    PlotRangeClipping->True,
    PlotRangePadding->{
      Scaled[0.02], 
      Scaled[0.02]}], ",", 
   GraphicsBox[{{}, 
     {Hue[0.67, 0.6, 0.6], PointBox[CompressedData["
1:eJztz0EKgUEcxuGJeyj3UN8dLC2Vta2TOIYVW0tLC8rCQpIkSdxA34z5X8Lz
bqZmfk09/fF0OOmklG7dlNpzv8trVst216aXt/2d66a8X5ralftTdPO8TXTl
/hVdeT9EN8h7Rlfub9HN8u7RjfKO0X3e7c7RlfdHdOXfRXTVVbvqqh0/Pz8/
Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/
Pz8/Pz8/Pz8/P/+/+L+LTSAN
       "]]}, {}},
    AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948],
    Axes->True,
    AxesOrigin->{0, 0},
    ImageSize->Small,
    PlotRange->{{0., 0.9411764705882353}, {0., 0.9411764705882353}},
    PlotRangeClipping->True,
    PlotRangePadding->{
      Scaled[0.02], 
      Scaled[0.02]}], ",", 
   GraphicsBox[{{}, 
     {Hue[0.67, 0.6, 0.6], PointBox[CompressedData["
1:eJztz7GJQkEUhtFB+xDsQ5geDA2FjU2txDKMNDU0NFDYwEBEVBYR2e1A3oxz
i1jOn1x4w/fgDKez8VcvpXTrp9TdQdkur1fdrvmw73bJ9fvmc0+f7/u8KNvm
1tX7iq6+f0c3KntGV+89unnZT3STsmN0f7/dztHV90d09T/L6Jqjdc3RuuZo
HT8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/
Pz8/Pz8/Pz8/Pz8/Pz8//3/1vwGDrhg9
       "]]}, {}},
    AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948],
    Axes->True,
    AxesOrigin->{0, 0},
    ImageSize->Small,
    PlotRange->{{0., 0.9411764705882353}, {0., 0.9411764705882353}},
    PlotRangeClipping->True,
    PlotRangePadding->{
      Scaled[0.02], 
      Scaled[0.02]}], ",", 
   GraphicsBox[{{}, 
     {Hue[0.67, 0.6, 0.6], PointBox[CompressedData["
1:eJztzzFqQkEUBdBB9yG4D2H2YGkpWKd1JVmGlbYpU6ZQsLAIIhJCCKI7kD8z
bxYh5zYP/pt/eWe6fJuvRiml6zilYR72Qy55tx1yzZOS7zY/8nvJZ67v9u37
rc2vtj/m6JmV/Peeuv/pPeuS396zKDn1nsd9yLn31P1f76n/bXpP3B09cXf0
xN3RE3dHDz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/
Pz8/Pz8/Pz8/Pz8/Pz8/Pz8/Pz8//6v4n0OeEG0=
       "]]}, {}},
    AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948],
    Axes->True,
    AxesOrigin->{0, 0},
    ImageSize->Small,
    PlotRange->{{0., 0.9411764705882353}, {0., 0.9411764705882353}},
    PlotRangeClipping->True,
    PlotRangePadding->{
      Scaled[0.02], 
      Scaled[0.02]}]}], "}"}]], "Output"]
}, Closed]]
}, Closed]],

Cell[CellGroupData[{

Cell["MiddleSquareGenerator", "Subsubsection"],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"MiddleSquareGenerator", "[", "3", "]"}]], "Input"],

Cell[BoxData[
 RowBox[{"{", 
  RowBox[{
  "1234567890", ",", "1578750190", ",", "4521624250", ",", "858581880"}], 
  "}"}]], "Output"]
}, Closed]],

Cell[CellGroupData[{

Cell[BoxData[{
 RowBox[{
  RowBox[{"data", "=", 
   RowBox[{"MiddleSquareGenerator", "[", 
    RowBox[{"500", ",", "1234567890"}], "]"}]}], ";"}], "\[IndentingNewLine]", 
 RowBox[{"Take", "[", 
  RowBox[{"data", ",", "24"}], "]"}]}], "Input"],

Cell[BoxData[
 RowBox[{"{", 
  RowBox[{
  "1234567890", ",", "1578750190", ",", "4521624250", ",", "858581880", ",", 
   "1628446643", ",", "8384690979", ",", "428133239", ",", "2980703366", ",", 
   "5925560837", ",", "2712329881", ",", "7333833654", ",", "1160645429", ",",
    "978118585", ",", "7159663224", ",", "7774810980", ",", "6857747285", ",",
    "6978249248", ",", "9625672125", ",", "5638580020", ",", "5846419432", 
   ",", "6201748672", ",", "6865906537", ",", "6725748193", ",", 
   "6887556427"}], "}"}]], "Output"]
}, Closed]],

Cell[BoxData[
 RowBox[{"ListLinePlot", "[", 
  SuperscriptBox[
   RowBox[{"Abs", "[", 
    RowBox[{"Fourier", "[", "data", "]"}], "]"}], "2"], "]"}]], "Input"]
}, Closed]],

Cell[CellGroupData[{

Cell["RadiusOfGyrationTensor", "Subsubsection"],

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

Cell[BoxData[
 RowBox[{
  RowBox[{"coords", "=", 
   RowBox[{"RandomWalk", "[", 
    RowBox[{"10000", ",", 
     RowBox[{"Dimension", "\[Rule]", "2"}], ",", 
     RowBox[{"LatticeWalk", "\[Rule]", "False"}]}], "]"}]}], ";"}]], "Input"],

Cell[BoxData[{
 RowBox[{
  RowBox[{"walk", "=", 
   RowBox[{"RandomWalk", "[", 
    RowBox[{
     SuperscriptBox["10", "6"], ",", 
     RowBox[{"LatticeWalk", "\[Rule]", "False"}]}], "]"}]}], ";"}], "\n", 
 RowBox[{"\[ScriptCapitalT]", "=", 
  RowBox[{"RadiusOfGyrationTensor", "[", "walk", "]"}]}]}], "Input"]
}, Closed]],

Cell[CellGroupData[{

Cell["RandomSparseArray", "Subsubsection"],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{
  RowBox[{"Normal", "[", 
   RowBox[{"RandomSparseArray", "[", "5", "]"}], "]"}], "//", 
  "MatrixForm"}]], "Input"],

Cell[BoxData[
 TagBox[
  RowBox[{"(", "\[NoBreak]", GridBox[{
     {"0.9135786595761082`", "0", "0", "0", "0"},
     {"0", "0.7721068364341714`", "0", "0", "0"},
     {"0", "0", "0.2699423765192783`", "0", "0"},
     {"0", "0", "0", "0.034540878864362856`", "0"},
     {"0", "0", "0", "0", "0.02580354370980764`"}
    },
    GridBoxAlignment->{
     "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, "Rows" -> {{Baseline}}, 
      "RowsIndexed" -> {}},
    GridBoxSpacings->{"Columns" -> {
        Offset[0.27999999999999997`], {
         Offset[0.7]}, 
        Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
        Offset[0.2], {
         Offset[0.4]}, 
        Offset[0.2]}, "RowsIndexed" -> {}}], "\[NoBreak]", ")"}],
  Function[BoxForm`e$, 
   MatrixForm[BoxForm`e$]]]], "Output"]
}, Closed]]
}, Closed]],

Cell[CellGroupData[{

Cell["TridiagonalMatrix", "Subsubsection"],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"TridiagonalMatrix", "[", 
  RowBox[{"5", ",", "\[Alpha]", ",", "\[Beta]"}], "]"}]], "Input"],

Cell[BoxData[
 TagBox[
  RowBox[{"SparseArray", "[", 
   RowBox[{
    InterpretationBox[
     RowBox[{"\<\"<\"\>", "\[InvisibleSpace]", "13", 
      "\[InvisibleSpace]", "\<\">\"\>"}],
     SequenceForm["<", 13, ">"],
     Editable->False], ",", 
    RowBox[{"{", 
     RowBox[{"5", ",", "5"}], "}"}]}], "]"}],
  False,
  Editable->False]], "Output"]
}, Closed]],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"MatrixForm", "[", "%", "]"}]], "Input"],

Cell[BoxData[
 TagBox[
  RowBox[{"(", "\[NoBreak]", GridBox[{
     {"\[Alpha]", "\[Beta]", "0", "0", "0"},
     {"\[Beta]", "\[Alpha]", "\[Beta]", "0", "0"},
     {"0", "\[Beta]", "\[Alpha]", "\[Beta]", "0"},
     {"0", "0", "\[Beta]", "\[Alpha]", "\[Beta]"},
     {"0", "0", "0", "\[Beta]", "\[Alpha]"}
    },
    GridBoxAlignment->{
     "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, "Rows" -> {{Baseline}}, 
      "RowsIndexed" -> {}},
    GridBoxSpacings->{"Columns" -> {
        Offset[0.27999999999999997`], {
         Offset[0.7]}, 
        Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
        Offset[0.2], {
         Offset[0.4]}, 
        Offset[0.2]}, "RowsIndexed" -> {}}], "\[NoBreak]", ")"}],
  Function[BoxForm`e$, 
   MatrixForm[
   SparseArray[
    Automatic, {5, 5}, 0, {
     1, {{0, 2, 5, 8, 11, 13}, {{2}, {1}, {1}, {2}, {3}, {4}, {2}, {3}, {3}, {
       5}, {4}, {4}, {
       5}}}, {$CellContext`\[Beta], $CellContext`\[Alpha], $CellContext`\
\[Beta], $CellContext`\[Alpha], $CellContext`\[Beta], $CellContext`\[Beta], \
$CellContext`\[Beta], $CellContext`\[Alpha], $CellContext`\[Beta], \
$CellContext`\[Beta], $CellContext`\[Alpha], $CellContext`\[Beta], \
$CellContext`\[Alpha]}}]]]]], "Output"]
}, Closed]]
}, Closed]]
}, Closed]]
}, Open  ]]
},
AutoGeneratedPackage->Automatic,
ScreenStyleEnvironment->"Working",
WindowSize->{
  Scaled[0.5], 
  Scaled[0.75]},
WindowMargins->{{15, Automatic}, {Automatic, 15}},
ShowSelection->True,
FrontEndVersion->"10.1 for Mac OS X x86 (32-bit, 64-bit Kernel) (March 23, \
2015)",
StyleDefinitions->"Default.nb"
]
(* End of Notebook Content *)

(* Internal cache information *)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[CellGroupData[{
Cell[579, 22, 66, 1, 60, "Section",
 InitializationGroup->True],
Cell[648, 25, 398, 13, 29, "Text"],
Cell[CellGroupData[{
Cell[1071, 42, 30, 0, 41, "Subsection"],
Cell[1104, 44, 129, 3, 36, "Input"],
Cell[1236, 49, 239, 6, 36, "Input"],
Cell[1478, 57, 146, 4, 35, "Input"],
Cell[1627, 63, 318, 8, 78, "Input"],
Cell[1948, 73, 135, 4, 36, "Input"],
Cell[2086, 79, 147, 4, 36, "Input"],
Cell[2236, 85, 229, 6, 36, "Input"],
Cell[2468, 93, 256, 8, 57, "Input"],
Cell[2727, 103, 547, 11, 99, "Input"],
Cell[3277, 116, 152, 4, 36, "Input"],
Cell[3432, 122, 173, 5, 35, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[3642, 132, 34, 0, 33, "Subsection"],
Cell[3679, 134, 80, 1, 63, "Input"],
Cell[3762, 137, 91, 1, 63, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[3890, 143, 57, 0, 33, "Subsection"],
Cell[3950, 145, 216, 5, 63, "Input"],
Cell[4169, 152, 192, 5, 46, "Input"],
Cell[4364, 159, 261, 6, 80, "Input"],
Cell[4628, 167, 179, 5, 46, "Input"],
Cell[4810, 174, 183, 5, 46, "Input"],
Cell[4996, 181, 267, 6, 80, "Input"],
Cell[5266, 189, 159, 4, 28, "Input"],
Cell[5428, 195, 264, 6, 80, "Input"],
Cell[5695, 203, 223, 5, 63, "Input"],
Cell[5921, 210, 264, 6, 63, "Input"],
Cell[6188, 218, 255, 6, 63, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[6480, 229, 29, 0, 33, "Subsection"],
Cell[6512, 231, 285, 8, 63, "Input"],
Cell[6800, 241, 449, 11, 213, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[7286, 257, 37, 0, 33, "Subsection"],
Cell[7326, 259, 74, 1, 63, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[7437, 265, 63, 0, 33, "Subsection"],
Cell[7503, 267, 356, 11, 63, "Input"],
Cell[7862, 280, 408, 12, 102, "Input"],
Cell[8273, 294, 2738, 73, 437, "Input"],
Cell[11014, 369, 237, 7, 63, "Input"],
Cell[11254, 378, 3083, 84, 666, "Input"],
Cell[14340, 464, 2019, 56, 470, "Input"],
Cell[16362, 522, 551, 17, 102, "Input"],
Cell[16916, 541, 1391, 36, 362, "Input"],
Cell[18310, 579, 1384, 40, 238, "Input"],
Cell[19697, 621, 407, 12, 63, "Input"],
Cell[20107, 635, 694, 22, 102, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[20838, 662, 41, 0, 33, "Subsection"],
Cell[20882, 664, 51, 1, 63, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[20970, 670, 32, 0, 33, "Subsection"],
Cell[21005, 672, 58, 1, 63, "Input"]
}, Closed]]
}, Open  ]],
Cell[CellGroupData[{
Cell[21112, 679, 27, 0, 60, "Section"],
Cell[CellGroupData[{
Cell[21164, 683, 34, 0, 41, "Subsection"],
Cell[21201, 685, 52, 1, 28, "Input"],
Cell[21256, 688, 187, 6, 29, "Text"],
Cell[21446, 696, 63, 1, 28, "Input"]
}, Open  ]],
Cell[CellGroupData[{
Cell[21546, 702, 41, 0, 41, "Subsection"],
Cell[CellGroupData[{
Cell[21612, 706, 58, 1, 120, "Input"],
Cell[21673, 709, 441, 6, 181, "Print"]
}, Closed]],
Cell[CellGroupData[{
Cell[22151, 720, 58, 1, 120, "Input"],
Cell[22212, 723, 232, 4, 181, "Print"]
}, Closed]],
Cell[CellGroupData[{
Cell[22481, 732, 54, 1, 120, "Input"],
Cell[22538, 735, 959, 17, 253, "Print"]
}, Closed]],
Cell[CellGroupData[{
Cell[23534, 757, 51, 1, 120, "Input"],
Cell[23588, 760, 318, 5, 181, "Print"]
}, Closed]],
Cell[CellGroupData[{
Cell[23943, 770, 58, 1, 120, "Input"],
Cell[24004, 773, 220, 3, 181, "Print"]
}, Closed]],
Cell[CellGroupData[{
Cell[24261, 781, 51, 1, 120, "Input"],
Cell[24315, 784, 782, 14, 253, "Print"]
}, Closed]],
Cell[CellGroupData[{
Cell[25134, 803, 50, 1, 120, "Input"],
Cell[25187, 806, 242, 4, 181, "Print"]
}, Closed]],
Cell[CellGroupData[{
Cell[25466, 815, 64, 1, 120, "Input"],
Cell[25533, 818, 342, 5, 253, "Print"]
}, Closed]],
Cell[CellGroupData[{
Cell[25912, 828, 65, 1, 120, "Input"],
Cell[25980, 831, 248, 4, 181, "Print"]
}, Closed]],
Cell[CellGroupData[{
Cell[26265, 840, 60, 1, 120, "Input"],
Cell[26328, 843, 375, 5, 253, "Print"]
}, Closed]],
Cell[CellGroupData[{
Cell[26740, 853, 60, 1, 120, "Input"],
Cell[26803, 856, 568, 8, 253, "Print"]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell[27420, 870, 56, 0, 33, "Subsection"],
Cell[CellGroupData[{
Cell[27501, 874, 40, 0, 32, "Subsubsection"],
Cell[CellGroupData[{
Cell[27566, 878, 464, 15, 102, "Input"],
Cell[28033, 895, 505, 11, 102, "Output"]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell[28587, 912, 40, 0, 26, "Subsubsection"],
Cell[28630, 914, 85, 2, 62, "Text"],
Cell[CellGroupData[{
Cell[28740, 920, 321, 10, 63, "Input"],
Cell[29064, 932, 95, 2, 63, "Output"]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell[29208, 940, 36, 0, 26, "Subsubsection"],
Cell[29247, 942, 377, 10, 102, "Input"],
Cell[29627, 954, 154, 4, 63, "Input"],
Cell[29784, 960, 575, 19, 63, "Input"],
Cell[30362, 981, 627, 18, 102, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[31026, 1004, 33, 0, 26, "Subsubsection"],
Cell[CellGroupData[{
Cell[31084, 1008, 80, 2, 63, "Input"],
Cell[31167, 1012, 29, 0, 63, "Output"]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell[31245, 1018, 40, 0, 26, "Subsubsection"],
Cell[31288, 1020, 88, 1, 63, "Input"],
Cell[31379, 1023, 379, 10, 102, "Input"],
Cell[31761, 1035, 112, 2, 63, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[31910, 1042, 33, 0, 26, "Subsubsection"],
Cell[31946, 1044, 214, 6, 110, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[32197, 1055, 32, 0, 26, "Subsubsection"],
Cell[32232, 1057, 625, 16, 213, "Input"],
Cell[CellGroupData[{
Cell[32882, 1077, 261, 7, 63, "Input"],
Cell[33146, 1086, 2709, 70, 656, "Output"]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell[35904, 1162, 46, 0, 26, "Subsubsection"],
Cell[CellGroupData[{
Cell[35975, 1166, 74, 1, 63, "Input"],
Cell[36052, 1169, 134, 4, 63, "Output"]
}, Closed]],
Cell[CellGroupData[{
Cell[36223, 1178, 242, 6, 102, "Input"],
Cell[36468, 1186, 533, 9, 176, "Output"]
}, Closed]],
Cell[37016, 1198, 159, 4, 78, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[37212, 1207, 47, 0, 26, "Subsubsection"],
Cell[37262, 1209, 88, 1, 63, "Input"],
Cell[37353, 1212, 235, 6, 63, "Input"],
Cell[37591, 1220, 310, 8, 116, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[37938, 1233, 42, 0, 26, "Subsubsection"],
Cell[CellGroupData[{
Cell[38005, 1237, 140, 4, 63, "Input"],
Cell[38148, 1243, 804, 20, 212, "Output"]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell[39001, 1269, 42, 0, 26, "Subsubsection"],
Cell[CellGroupData[{
Cell[39068, 1273, 116, 2, 63, "Input"],
Cell[39187, 1277, 350, 12, 63, "Output"]
}, Closed]],
Cell[CellGroupData[{
Cell[39574, 1294, 63, 1, 63, "Input"],
Cell[39640, 1297, 1245, 29, 212, "Output"]
}, Closed]]
}, Closed]]
}, Closed]]
}, Open  ]]
}
]
*)

(* End of internal cache information *)
