(* Content-type: application/mathematica *)

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

(* CreatedBy='Mathematica 7.0' *)

(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[       145,          7]
NotebookDataLength[      9107,        244]
NotebookOptionsPosition[      8627,        224]
NotebookOutlinePosition[      8968,        239]
CellTagsIndexPosition[      8925,        236]
WindowFrame->Normal*)

(* Beginning of Notebook Content *)
Notebook[{
Cell[BoxData[
 RowBox[{"Clear", "[", "\"\<Global`*\>\"", "]"}]], "Input",
 CellChangeTimes->{{3.477141306479937*^9, 3.477141306951708*^9}}],

Cell[BoxData[{
 RowBox[{
  RowBox[{"n", "=", "100"}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"myM", "=", 
   RowBox[{"Table", "[", 
    RowBox[{
     RowBox[{"Random", "[", "]"}], ",", 
     RowBox[{"{", "n", "}"}], ",", 
     RowBox[{"{", "n", "}"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"iii", "=", "1"}], ";"}], "\[IndentingNewLine]", 
 RowBox[{"For", "[", 
  RowBox[{
   RowBox[{"r", "=", "1"}], ",", 
   RowBox[{"r", "\[LessEqual]", "n"}], ",", 
   RowBox[{"r", "+=", "1"}], ",", "\[IndentingNewLine]", 
   RowBox[{"For", "[", 
    RowBox[{
     RowBox[{"c", "=", "1"}], ",", 
     RowBox[{"c", "\[LessEqual]", "n"}], ",", 
     RowBox[{"c", "+=", "1"}], ",", "\[IndentingNewLine]", 
     RowBox[{
      RowBox[{
       RowBox[{"myM", "[", 
        RowBox[{"[", 
         RowBox[{"r", ",", "c"}], "]"}], "]"}], "=", "iii"}], ";", 
      RowBox[{"iii", "+=", "1"}]}]}], "\[IndentingNewLine]", "]"}]}], 
  "\[IndentingNewLine]", "]"}]}], "Input",
 CellChangeTimes->{{3.477140775941409*^9, 3.4771408067703447`*^9}, {
  3.4771417821510153`*^9, 3.4771417839485083`*^9}, {3.477142451473765*^9, 
  3.4771424516598177`*^9}, {3.477143032156043*^9, 3.4771430332432833`*^9}, {
  3.477144482918947*^9, 3.4771444831011057`*^9}, {3.477211051517705*^9, 
  3.4772111076810637`*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"arnoldi", "[", 
   RowBox[{"M_", ",", "m_"}], "]"}], ":=", 
  RowBox[{"(", "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{"vectors", "=", 
     RowBox[{"{", 
      RowBox[{"Table", "[", 
       RowBox[{
        RowBox[{"Random", "[", "]"}], ",", 
        RowBox[{"{", "n", "}"}]}], "]"}], "}"}]}], ";", "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{"vectors", "[", 
      RowBox[{"[", "1", "]"}], "]"}], "=", 
     RowBox[{
      RowBox[{"vectors", "[", 
       RowBox[{"[", "1", "]"}], "]"}], "/", 
      RowBox[{"Norm", "[", 
       RowBox[{"vectors", "[", 
        RowBox[{"[", "1", "]"}], "]"}], "]"}]}]}], ";", "\[IndentingNewLine]", 
    RowBox[{"h", "=", 
     RowBox[{"Table", "[", 
      RowBox[{"0", ",", 
       RowBox[{"{", "m", "}"}], ",", 
       RowBox[{"{", "m", "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", 
    RowBox[{"For", "[", 
     RowBox[{
      RowBox[{"j", "=", "1"}], ",", 
      RowBox[{"j", "\[LessEqual]", "m"}], ",", 
      RowBox[{"j", "=", 
       RowBox[{"j", "+", "1"}]}], ",", "\[IndentingNewLine]", 
      RowBox[{
       RowBox[{"w", "=", 
        RowBox[{"M", ".", 
         RowBox[{"vectors", "[", 
          RowBox[{"[", "j", "]"}], "]"}]}]}], ";", "\[IndentingNewLine]", 
       RowBox[{"For", "[", 
        RowBox[{
         RowBox[{"i", "=", "1"}], ",", 
         RowBox[{"i", "\[LessEqual]", "j"}], ",", 
         RowBox[{"i", "=", 
          RowBox[{"i", "+", "1"}]}], ",", "\[IndentingNewLine]", 
         RowBox[{
          RowBox[{
           RowBox[{"h", "[", 
            RowBox[{"[", 
             RowBox[{"i", ",", "j"}], "]"}], "]"}], "=", 
           RowBox[{"w", ".", 
            RowBox[{"vectors", "[", 
             RowBox[{"[", "i", "]"}], "]"}]}]}], ";", "\[IndentingNewLine]", 
          RowBox[{"w", "=", 
           RowBox[{"w", "-", 
            RowBox[{
             RowBox[{"h", "[", 
              RowBox[{"[", 
               RowBox[{"i", ",", "j"}], "]"}], "]"}], "*", 
             RowBox[{"vectors", "[", 
              RowBox[{"[", "i", "]"}], "]"}]}]}]}]}]}], "\[IndentingNewLine]",
         "]"}], ";", "\[IndentingNewLine]", 
       RowBox[{"normw", "=", 
        RowBox[{"Norm", "[", "w", "]"}]}], ";", "\[IndentingNewLine]", 
       RowBox[{"If", "[", 
        RowBox[{
         RowBox[{"j", "\[Equal]", "m"}], ",", 
         RowBox[{"Break", "[", "]"}]}], "]"}], ";", "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{"h", "[", 
         RowBox[{"[", 
          RowBox[{
           RowBox[{"j", "+", "1"}], ",", "j"}], "]"}], "]"}], "=", "normw"}], 
       ";", "\[IndentingNewLine]", 
       RowBox[{"If", "[", 
        RowBox[{
         RowBox[{
          RowBox[{"h", "[", 
           RowBox[{"[", 
            RowBox[{
             RowBox[{"j", "+", "1"}], ",", "j"}], "]"}], "]"}], "<", 
          RowBox[{"10", "^", 
           RowBox[{"-", "8"}]}]}], ",", 
         RowBox[{"Break", "[", "]"}]}], "]"}], ";", "\[IndentingNewLine]", 
       RowBox[{"vectors", "=", 
        RowBox[{"Append", "[", 
         RowBox[{"vectors", ",", 
          RowBox[{"w", "/", 
           RowBox[{"h", "[", 
            RowBox[{"[", 
             RowBox[{
              RowBox[{"j", "+", "1"}], ",", "j"}], "]"}], "]"}]}]}], "]"}]}], 
       ";"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{"{", 
      RowBox[{"evals", ",", "evecs"}], "}"}], "=", 
     RowBox[{"Eigensystem", "[", "h", "]"}]}], ";", "\[IndentingNewLine]", 
    RowBox[{"eps", "=", 
     RowBox[{"normw", "*", 
      RowBox[{"Abs", "[", 
       RowBox[{
        RowBox[{"evecs", "[", 
         RowBox[{"[", "2", "]"}], "]"}], "[", 
        RowBox[{"[", "m", "]"}], "]"}], "]"}]}]}], ";", "\[IndentingNewLine]", 
    RowBox[{"Return", "[", 
     RowBox[{"{", 
      RowBox[{"evals", ",", "eps"}], "}"}], "]"}], ";"}], 
   "\[IndentingNewLine]", ")"}]}]], "Input",
 CellChangeTimes->{{3.4771407941270313`*^9, 3.477140824249634*^9}, {
   3.4771408552124987`*^9, 3.477140869850316*^9}, {3.4771410917497683`*^9, 
   3.477141259033804*^9}, {3.477141290948194*^9, 3.477141576927731*^9}, {
   3.477141656561036*^9, 3.477141658105749*^9}, {3.477141690763707*^9, 
   3.4771417676087847`*^9}, {3.477141801565881*^9, 3.477141802208931*^9}, {
   3.477142118927433*^9, 3.477142144629559*^9}, {3.477142248456609*^9, 
   3.477142248566834*^9}, {3.477142428753771*^9, 3.47714246316154*^9}, 
   3.477142603627261*^9, {3.477142639484991*^9, 3.477142641075429*^9}, 
   3.477142762166617*^9, {3.477143335759709*^9, 3.477143417776946*^9}, {
   3.4771434595625753`*^9, 3.47714353489207*^9}, {3.47714356619485*^9, 
   3.477143602500429*^9}, {3.4771436747088127`*^9, 3.4771437242187843`*^9}, {
   3.477143759959845*^9, 3.477143823517612*^9}, {3.47714420445863*^9, 
   3.4771442067863913`*^9}}],

Cell[CellGroupData[{

Cell[BoxData[{
 RowBox[{"arnoldi", "[", 
  RowBox[{"myM", ",", "10"}], "]"}], "\[IndentingNewLine]", 
 RowBox[{"Eigenvalues", "[", "myM", "]"}]}], "Input",
 CellChangeTimes->{{3.477143704914015*^9, 3.47714370847528*^9}, {
  3.477143846095323*^9, 3.4771438477471037`*^9}, {3.477144170899226*^9, 
  3.47714419212838*^9}, {3.4801496884635983`*^9, 3.4801496914780293`*^9}}],

Cell[BoxData[
 RowBox[{"{", 
  RowBox[{
   RowBox[{"{", 
    RowBox[{"520.8398032346302`", ",", 
     RowBox[{"-", "15.839803234630153`"}], ",", "4.1428158198318985`*^-14", 
     ",", "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", "0.`", ",", "0.`", 
     ",", "0.`"}], "}"}], ",", "0.`"}], "}"}]], "Output",
 CellChangeTimes->{{3.477143708916666*^9, 3.4771437257619743`*^9}, {
   3.477143766888506*^9, 3.477143784217066*^9}, {3.477143826304212*^9, 
   3.477143848177682*^9}, {3.477144173572184*^9, 3.477144207809758*^9}, 
   3.477144250991787*^9, 3.477144386585198*^9, {3.477144472283332*^9, 
   3.477144483864811*^9}, 3.477211111205913*^9, 3.480149692039042*^9}],

Cell[BoxData[
 RowBox[{"{", 
  RowBox[{
   RowBox[{
    FractionBox["5", "2"], " ", 
    RowBox[{"(", 
     RowBox[{"101", "+", 
      SqrtBox["11521"]}], ")"}]}], ",", 
   RowBox[{
    FractionBox["5", "2"], " ", 
    RowBox[{"(", 
     RowBox[{"101", "-", 
      SqrtBox["11521"]}], ")"}]}], ",", "0", ",", "0", ",", "0", ",", "0", 
   ",", "0", ",", "0", ",", "0", ",", "0"}], "}"}]], "Output",
 CellChangeTimes->{{3.477143708916666*^9, 3.4771437257619743`*^9}, {
   3.477143766888506*^9, 3.477143784217066*^9}, {3.477143826304212*^9, 
   3.477143848177682*^9}, {3.477144173572184*^9, 3.477144207809758*^9}, 
   3.477144250991787*^9, 3.477144386585198*^9, {3.477144472283332*^9, 
   3.477144483864811*^9}, 3.477211111205913*^9, 3.480149692040935*^9}]
}, Open  ]]
},
WindowSize->{986, 1198},
WindowMargins->{{Automatic, 159}, {Automatic, 0}},
FrontEndVersion->"7.0 for Mac OS X x86 (32-bit) (February 18, 2009)",
StyleDefinitions->"Default.nb"
]
(* End of Notebook Content *)

(* Internal cache information *)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[545, 20, 139, 2, 27, "Input"],
Cell[687, 24, 1308, 33, 133, "Input"],
Cell[1998, 59, 4795, 118, 313, "Input"],
Cell[CellGroupData[{
Cell[6818, 181, 369, 6, 43, "Input"],
Cell[7190, 189, 665, 12, 33, "Output"],
Cell[7858, 203, 753, 18, 46, "Output"]
}, Open  ]]
}
]
*)

(* End of internal cache information *)
