(* 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[ 16673, 526] NotebookOptionsPosition[ 14503, 451] NotebookOutlinePosition[ 15095, 471] CellTagsIndexPosition[ 15052, 468] WindowFrame->Normal ContainsDynamic->False*) (* Beginning of Notebook Content *) Notebook[{ Cell["\<\ Here I demonstrate how to find the polar and singular value decompositions of \ a matrix A. I take as my example\ \>", "Text", CellChangeTimes->{{3.442161908955469*^9, 3.442161956227299*^9}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"MatrixForm", "[", RowBox[{"A", "=", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"1.", ",", "1."}], "}"}], ",", RowBox[{"{", RowBox[{"0", ",", "1."}], "}"}]}], "}"}]}], "]"}]], "Input", CellChangeTimes->{{3.4421382388839846`*^9, 3.4421382955246096`*^9}, { 3.442159757030126*^9, 3.442159761574669*^9}}], Cell[BoxData[ TagBox[ RowBox[{"(", "\[NoBreak]", GridBox[{ {"1.`", "1.`"}, {"0", "1.`"} }, GridBoxAlignment->{ "Columns" -> {{Left}}, "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", CellChangeTimes->{{3.4421382773996096`*^9, 3.4421382959152346`*^9}, 3.442161898603633*^9}] }, Open ]], Cell["First I compute A* A:", "Text", CellChangeTimes->{{3.442161962999009*^9, 3.442161981360892*^9}, 3.442162020996947*^9}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"MatrixForm", "[", RowBox[{"Asqr", " ", "=", " ", RowBox[{ RowBox[{"Transpose", "[", "A", "]"}], ".", "A"}]}], "]"}]], "Input", CellChangeTimes->{{3.4421383179933596`*^9, 3.4421383347277346`*^9}}], Cell[BoxData[ TagBox[ RowBox[{"(", "\[NoBreak]", GridBox[{ {"1.`", "1.`"}, {"1.`", "2.`"} }, GridBoxAlignment->{ "Columns" -> {{Left}}, "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", CellChangeTimes->{3.4421383352589846`*^9, 3.442159821753464*^9, 3.44216066409461*^9, 3.442161140228299*^9, 3.442161903421985*^9, 3.442162132724829*^9}] }, Open ]], Cell["\<\ Then I get the eigenvalues and corresponding eigenvectors of this. The \ square roots of the eigenvalues will be my singular values.\ \>", "Text", CellChangeTimes->{{3.442162001822913*^9, 3.442162053647622*^9}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{ RowBox[{"{", RowBox[{"svs", ",", "svecs"}], "}"}], "=", RowBox[{"Eigensystem", "[", "Asqr", "]"}]}]], "Input", CellChangeTimes->{{3.4421383604308596`*^9, 3.4421384064777346`*^9}}], Cell[BoxData[ RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"2.618033988749895`", ",", "0.3819660112501051`"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"0.5257311121191336`", ",", "0.8506508083520399`"}], "}"}], ",", RowBox[{"{", RowBox[{"0.85065080835204`", ",", RowBox[{"-", "0.5257311121191336`"}]}], "}"}]}], "}"}]}], "}"}]], "Output", CellChangeTimes->{3.4421383719933596`*^9, 3.4421384086808596`*^9, 3.442159824472736*^9, 3.442160665481808*^9, 3.442161141315499*^9, 3.442162134925713*^9}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"svs", " ", "=", RowBox[{"Sqrt", "[", "svs", "]"}]}]], "Input", CellChangeTimes->{{3.4421384392277346`*^9, 3.4421384545402346`*^9}}], Cell[BoxData[ RowBox[{"{", RowBox[{"1.618033988749895`", ",", "0.6180339887498948`"}], "}"}]], "Output",\ CellChangeTimes->{ 3.4421384556027346`*^9, 3.442159828592101*^9, 3.442160672229872*^9, 3.442161142973524*^9, {3.442162128282126*^9, 3.442162136552204*^9}}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"MatrixForm", "[", RowBox[{"svecs", " ", "=", RowBox[{"Transpose", "[", "svecs", "]"}]}], "]"}]], "Input", CellChangeTimes->{{3.4421385343996096`*^9, 3.4421385733214846`*^9}}], Cell[BoxData[ TagBox[ RowBox[{"(", "\[NoBreak]", GridBox[{ {"0.5257311121191336`", "0.85065080835204`"}, {"0.8506508083520399`", RowBox[{"-", "0.5257311121191336`"}]} }, GridBoxAlignment->{ "Columns" -> {{Left}}, "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", CellChangeTimes->{{3.442162129451332*^9, 3.442162137829095*^9}}] }, Open ]], Cell["\<\ Hence the singular values are 1.62 and .62 with corresponding (normalized) \ eigenvectors (.53,.85) and (.85,-.53).\ \>", "Text", CellChangeTimes->{{3.44216205700208*^9, 3.44216210897429*^9}, { 3.442162143614118*^9, 3.442162191891575*^9}}], Cell[BoxData[ TagBox[ RowBox[{"(", "\[NoBreak]", GridBox[{ {"1", RowBox[{"-", "2"}]}, {"2", "1"} }, GridBoxAlignment->{ "Columns" -> {{Left}}, "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", CellChangeTimes->{3.4421385739621096`*^9, 3.44215991531035*^9, 3.442160686149266*^9, 3.442161144424124*^9}], Cell["\<\ This allows me to compute | A | (i.e. the square root of A*A):\ \>", "Text", CellChangeTimes->{{3.442162201188757*^9, 3.442162222969838*^9}, { 3.442162264110229*^9, 3.44216227740315*^9}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{ RowBox[{"MatrixForm", "[", RowBox[{"absA", " ", "=", " ", RowBox[{"svecs", ".", RowBox[{"DiagonalMatrix", "[", "svs", "]"}], ".", RowBox[{"Transpose", "[", "svecs", "]"}]}]}], "]"}]}]], "Input", CellChangeTimes->{{3.442162279567854*^9, 3.442162307504109*^9}}], Cell[BoxData[ TagBox[ RowBox[{"(", "\[NoBreak]", GridBox[{ {"0.894427190999916`", "0.4472135954999579`"}, {"0.4472135954999579`", "1.3416407864998736`"} }, GridBoxAlignment->{ "Columns" -> {{Left}}, "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", CellChangeTimes->{{3.442162292730099*^9, 3.442162308366188*^9}}] }, Open ]], Cell["\<\ As this is invertible, I get the isometry U in the polar decomposition by \ multiplying A (on the right) by the inverse of absA:\ \>", "Text", CellChangeTimes->{{3.442162313517576*^9, 3.442162377495066*^9}, { 3.442162413607033*^9, 3.442162446368579*^9}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"MatrixForm", "[", RowBox[{"U", " ", "=", " ", RowBox[{"A", ".", RowBox[{"Inverse", "[", "absA", "]"}]}]}], "]"}]], "Input", CellChangeTimes->{{3.442162448198809*^9, 3.44216246656718*^9}}], Cell[BoxData[ TagBox[ RowBox[{"(", "\[NoBreak]", GridBox[{ {"0.8944271909999157`", "0.4472135954999581`"}, { RowBox[{"-", "0.44721359549995787`"}], "0.894427190999916`"} }, GridBoxAlignment->{ "Columns" -> {{Left}}, "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", CellChangeTimes->{3.44216246716844*^9}] }, Open ]], Cell["\<\ Thus the polar decomposition is A = U.absA, where U and absA are as just \ computed. Now for the singular value decomposition, I also need to know the \ normalized images of the eigenvectors of A*A under A:\ \>", "Text", CellChangeTimes->{{3.442162473103545*^9, 3.442162586484696*^9}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"MatrixForm", "[", RowBox[{"W", " ", "=", " ", RowBox[{"A", ".", "svecs"}]}], "]"}]], "Input", CellChangeTimes->{{3.442162567932975*^9, 3.442162578789801*^9}, { 3.442162803191708*^9, 3.44216280633168*^9}}], Cell[BoxData[ TagBox[ RowBox[{"(", "\[NoBreak]", GridBox[{ {"1.3763819204711734`", "0.3249196962329064`"}, {"0.8506508083520399`", RowBox[{"-", "0.5257311121191336`"}]} }, GridBoxAlignment->{ "Columns" -> {{Left}}, "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", CellChangeTimes->{3.442162589991436*^9, 3.442162806912965*^9}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"MatrixForm", "[", RowBox[{"W", " ", "=", " ", RowBox[{"Transpose", "[", RowBox[{"Map", "[", RowBox[{"Normalize", ",", RowBox[{"Transpose", "[", "W", "]"}]}], "]"}], "]"}]}], "]"}]], "Input",\ CellChangeTimes->{{3.442162594524223*^9, 3.442162623701532*^9}}], Cell[BoxData[ TagBox[ RowBox[{"(", "\[NoBreak]", GridBox[{ {"0.8506508083520399`", "0.5257311121191337`"}, {"0.5257311121191336`", RowBox[{"-", "0.8506508083520398`"}]} }, GridBoxAlignment->{ "Columns" -> {{Left}}, "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", CellChangeTimes->{{3.442162613459513*^9, 3.442162624141239*^9}}] }, Open ]], Cell["\<\ Thus the singular value decomposition is W.Sig.V*, where W is as above and\ \>", "Text", CellChangeTimes->{{3.442162642328911*^9, 3.442162698259115*^9}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"MatrixForm", "[", RowBox[{"Sig", " ", "=", " ", RowBox[{"DiagonalMatrix", "[", "svs", "]"}]}], "]"}]], "Input", CellChangeTimes->{{3.442162700428893*^9, 3.442162716635728*^9}}], Cell[BoxData[ TagBox[ RowBox[{"(", "\[NoBreak]", GridBox[{ {"1.618033988749895`", "0.`"}, {"0.`", "0.6180339887498948`"} }, GridBoxAlignment->{ "Columns" -> {{Left}}, "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", CellChangeTimes->{3.442162717343942*^9}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"MatrixForm", "[", RowBox[{"V", " ", "=", " ", "svecs"}], "]"}]], "Input", CellChangeTimes->{{3.442162721299211*^9, 3.442162729973032*^9}}], Cell[BoxData[ TagBox[ RowBox[{"(", "\[NoBreak]", GridBox[{ {"0.5257311121191336`", "0.85065080835204`"}, {"0.8506508083520399`", RowBox[{"-", "0.5257311121191336`"}]} }, GridBoxAlignment->{ "Columns" -> {{Left}}, "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", CellChangeTimes->{3.442162731006565*^9}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"MatrixForm", "[", RowBox[{"W", ".", "Sig", ".", RowBox[{"Transpose", "[", "V", "]"}]}], " ", "]"}]], "Input", CellChangeTimes->{{3.442162737575729*^9, 3.442162751305863*^9}}], Cell[BoxData[ TagBox[ RowBox[{"(", "\[NoBreak]", GridBox[{ {"1.`", "0.9999999999999999`"}, {"1.1102230246251565`*^-16", "0.9999999999999999`"} }, GridBoxAlignment->{ "Columns" -> {{Left}}, "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", CellChangeTimes->{{3.442162745684364*^9, 3.442162751776667*^9}}] }, Open ]], Cell["which is (almost) right.", "Text", CellChangeTimes->{{3.442162755120749*^9, 3.442162760070076*^9}}] }, WindowSize->{1008, 647}, WindowMargins->{{0, Automatic}, {Automatic, 0}}, FrontEndVersion->"6.0 for Linux x86 (32-bit) (April 20, 2007)", StyleDefinitions->Notebook[{ Cell[ StyleData[StyleDefinitions -> "Default.nb"]]}, WindowMargins -> {{Automatic, 184}, {50, Automatic}}, Visible -> False, FrontEndVersion -> "6.0 for Linux x86 (32-bit) (April 20, 2007)", StyleDefinitions -> "PrivateStylesheetFormatting.nb"] ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[568, 21, 203, 4, 31, "Text"], Cell[CellGroupData[{ Cell[796, 29, 363, 10, 32, "Input"], Cell[1162, 41, 685, 19, 57, "Output"] }, Open ]], Cell[1862, 63, 129, 2, 31, "Text"], Cell[CellGroupData[{ Cell[2016, 69, 231, 5, 32, "Input"], Cell[2250, 76, 750, 20, 57, "Output"] }, Open ]], Cell[3015, 99, 223, 4, 31, "Text"], Cell[CellGroupData[{ Cell[3263, 107, 213, 5, 32, "Input"], Cell[3479, 114, 576, 16, 31, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[4092, 135, 159, 3, 32, "Input"], Cell[4254, 140, 273, 6, 31, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[4564, 151, 206, 4, 32, "Input"], Cell[4773, 157, 741, 19, 57, "Output"] }, Open ]], Cell[5529, 179, 252, 5, 31, "Text"], Cell[5784, 186, 717, 20, 57, "Output"], Cell[6504, 208, 200, 4, 31, "Text"], Cell[CellGroupData[{ Cell[6729, 216, 307, 7, 32, "Input"], Cell[7039, 225, 720, 18, 57, "Output"] }, Open ]], Cell[7774, 246, 267, 5, 31, "Text"], Cell[CellGroupData[{ Cell[8066, 255, 224, 5, 32, "Input"], Cell[8293, 262, 718, 19, 57, "Output"] }, Open ]], Cell[9026, 284, 297, 5, 51, "Text"], Cell[CellGroupData[{ Cell[9348, 293, 238, 5, 32, "Input"], Cell[9589, 300, 741, 19, 57, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[10367, 324, 307, 8, 32, "Input"], Cell[10677, 334, 743, 19, 57, "Output"] }, Open ]], Cell[11435, 356, 164, 3, 31, "Text"], Cell[CellGroupData[{ Cell[11624, 363, 208, 4, 32, "Input"], Cell[11835, 369, 664, 18, 57, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[12536, 392, 166, 3, 32, "Input"], Cell[12705, 397, 717, 19, 57, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[13459, 421, 206, 4, 32, "Input"], Cell[13668, 427, 710, 18, 61, "Output"] }, Open ]], Cell[14393, 448, 106, 1, 31, "Text"] } ] *) (* End of internal cache information *)