(* Content-type: application/vnd.wolfram.mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 12.0' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 158, 7] NotebookDataLength[ 8138, 237] NotebookOptionsPosition[ 7773, 220] NotebookOutlinePosition[ 8121, 235] CellTagsIndexPosition[ 8078, 232] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell[TextData[{ " ", StyleBox["Determining the best total least squares normalized line \ \[Alpha]x + \[Beta]y + \[Gamma] = 0, ", FontColor->RGBColor[1, 0, 0]], Cell[BoxData[ FormBox[ RowBox[{" ", SuperscriptBox["\[Alpha]", "2"]}], TraditionalForm]], FontColor->RGBColor[1, 0, 0], ExpressionUUID -> "f3495c42-2a51-4a44-a23f-21597677735d"], StyleBox[" +", FontColor->RGBColor[1, 0, 0]], Cell[BoxData[ FormBox[ SuperscriptBox["\[Beta]", "2"], TraditionalForm]], FontColor->RGBColor[1, 0, 0], ExpressionUUID -> "93aef178-e21c-4e94-b98c-6dab85816acd"], StyleBox[" = 1, in the plane", FontColor->RGBColor[1, 0, 0]] }], "Subsubsection", CellChangeTimes->{{3.7417476975226808`*^9, 3.7417477040219555`*^9}, { 3.8106224504387655`*^9, 3.8106224509069543`*^9}, {3.8106224815699863`*^9, 3.8106225674217453`*^9}, {3.820897286810254*^9, 3.820897349920377*^9}, { 3.820897429342143*^9, 3.820897434655204*^9}, 3.822317137733991*^9}, ExpressionUUID -> "1fe9e84a-0cd5-4b40-80d3-40bfd4109e85"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{ RowBox[{ StyleBox["Input", FontColor->RGBColor[1, 0, 0]], StyleBox[":", FontColor->RGBColor[1, 0, 0]], StyleBox[" ", FontColor->RGBColor[0, 0, 1]], StyleBox[ RowBox[{"data", " ", "set", " ", "\[ScriptCapitalA]"}], FontColor->RGBColor[0, 0, 1]]}], StyleBox[" ", FontColor->RGBColor[0, 0, 1]], StyleBox["=", FontColor->RGBColor[0, 0, 1]], StyleBox[" ", FontColor->RGBColor[0, 0, 1]], StyleBox[ RowBox[{ RowBox[{ StyleBox[ RowBox[{"{", RowBox[{ RowBox[{ SubscriptBox["a", "i"], "=", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{ SubscriptBox["x", "i"], ",", SubscriptBox["y", "i"]}], ")"}], "\[Element]", " ", RowBox[{ SuperscriptBox["\[DoubleStruckCapitalR]", "2"], " ", ":", " ", "i"}]}], "=", "1"}]}], ",", "\[TripleDot]", ",", "m"}], "}"}], FontSlant->"Italic"], " ", "with", " ", "weights", " ", StyleBox["w", FontSlant->"Italic"]}], StyleBox["=", FontSlant->"Italic"], StyleBox[ RowBox[{"(", RowBox[{ SubscriptBox["w", "1"], ",", "\[TripleDot]", ",", SubscriptBox["w", "m"]}], ")"}], FontSlant->"Italic"]}], FontColor->RGBColor[0, 0, 1]]}], StyleBox[";", FontColor->RGBColor[0, 0, 1]]}], StyleBox[" ", FontColor->RGBColor[0, 0, 1]]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ StyleBox["Output", FontColor->RGBColor[1, 0, 0]], StyleBox[":", FontColor->RGBColor[1, 0, 0]], StyleBox[" ", FontColor->RGBColor[0, 0, 1]], StyleBox[ RowBox[{"parameters", " ", RowBox[{"(", RowBox[{"\[Alpha]", ",", "\[Beta]", ",", "\[Gamma]"}], ")"}]}], FontColor->RGBColor[0, 0, 1]]}], StyleBox[";", FontColor->RGBColor[0, 0, 1]]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ StyleBox["Submodules", FontColor->RGBColor[1, 0, 0]], StyleBox[":", FontColor->RGBColor[1, 0, 0]], StyleBox[" ", FontColor->RGBColor[0, 0, 1]], StyleBox[ RowBox[{"none", " ", "needed"}], FontColor->RGBColor[0, 0, 1]]}], StyleBox[" ", FontColor->RGBColor[0, 0, 1]]}], "\[IndentingNewLine]"}], "Text", CellChangeTimes->{{3.741744454525729*^9, 3.741744612624956*^9}, { 3.741875468180262*^9, 3.74187547776055*^9}, {3.7575971765697803`*^9, 3.7575971771781645`*^9}, {3.804599911100227*^9, 3.804599961870618*^9}, { 3.8046002006905537`*^9, 3.8046002211210814`*^9}, {3.8046757878495226`*^9, 3.804675878377494*^9}, {3.8046759111572285`*^9, 3.804675939613826*^9}, 3.804676672308709*^9, {3.8046843818141475`*^9, 3.804684435797735*^9}, { 3.804684587686577*^9, 3.804684590538593*^9}, {3.810622582154603*^9, 3.810622781020996*^9}, {3.8106228199911127`*^9, 3.8106229726917267`*^9}, { 3.820897368682186*^9, 3.8208973705430717`*^9}, {3.8223171467124925`*^9, 3.822317168029858*^9}}, FontSize->12, ExpressionUUID -> "287347bb-69b6-4778-8a88-ff36a5202b54"], Cell[BoxData[ RowBox[{"\[IndentingNewLine]", RowBox[{ RowBox[{"TLSline", "[", RowBox[{"w_", ",", "A_"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"m", "=", RowBox[{"Length", "[", "A", "]"}]}], ",", "BTB", ",", "eigv", ",", "x0", ",", "y0"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"{", RowBox[{"x0", ",", "y0"}], "}"}], "=", RowBox[{"Mean", "[", RowBox[{"WeightedData", "[", RowBox[{"A", ",", "w"}], "]"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"BTB", "=", RowBox[{ RowBox[{"Sum", "[", RowBox[{ RowBox[{ RowBox[{"w", "[", RowBox[{"[", "s", "]"}], "]"}], "*", RowBox[{"KroneckerProduct", "[", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"A", "[", RowBox[{"[", "s", "]"}], "]"}], "-", RowBox[{"{", RowBox[{"x0", ",", "y0"}], "}"}]}], ")"}], ",", RowBox[{"(", RowBox[{ RowBox[{"A", "[", RowBox[{"[", "s", "]"}], "]"}], "-", RowBox[{"{", RowBox[{"x0", ",", "y0"}], "}"}]}], ")"}]}], "]"}]}], ",", RowBox[{"{", RowBox[{"s", ",", "m"}], "}"}]}], "]"}], "//", "N"}]}], ";", "\[IndentingNewLine]", RowBox[{"eigv", "=", RowBox[{ RowBox[{"Eigenvectors", "[", "BTB", "]"}], "[", RowBox[{"[", "2", "]"}], "]"}]}], ";", " ", RowBox[{"eigv", "=", RowBox[{"eigv", "/", RowBox[{"Norm", "[", "eigv", "]"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"{", RowBox[{ RowBox[{"eigv", "[", RowBox[{"[", "1", "]"}], "]"}], ",", RowBox[{"eigv", "[", RowBox[{"[", "2", "]"}], "]"}], ",", RowBox[{ RowBox[{ RowBox[{"-", "x0"}], " ", RowBox[{"eigv", "[", RowBox[{"[", "1", "]"}], "]"}]}], "-", RowBox[{"y0", " ", RowBox[{"eigv", "[", RowBox[{"[", "2", "]"}], "]"}]}]}]}], "}"}]}]}], "\[IndentingNewLine]", "]"}]}]}]], "Input", CellChangeTimes->{{3.741744454525729*^9, 3.741744612624956*^9}, { 3.741875468180262*^9, 3.74187547776055*^9}, {3.7575971765697803`*^9, 3.7575971771781645`*^9}, {3.804599911100227*^9, 3.804599961870618*^9}, { 3.8046002006905537`*^9, 3.8046002211210814`*^9}, {3.8046757878495226`*^9, 3.804675878377494*^9}, {3.8046759111572285`*^9, 3.804675939613826*^9}, 3.804676672308709*^9, {3.8046843818141475`*^9, 3.804684435797735*^9}, { 3.804684587686577*^9, 3.804684590538593*^9}, {3.810622582154603*^9, 3.810622781020996*^9}, {3.8106228199911127`*^9, 3.8106229726917267`*^9}, { 3.820897368682186*^9, 3.8208973705430717`*^9}, 3.8223171467124925`*^9}, ExpressionUUID -> "287347bb-69b6-4778-8a88-ff36a5202b54"] }, Open ]] }, WindowSize->{1536, 779}, WindowMargins->{{-8, Automatic}, {Automatic, -8}}, FrontEndVersion->"11.0 for Microsoft Windows (64-bit) (September 21, 2016)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[580, 22, 1021, 25, 39, "Subsubsection"], Cell[1604, 49, 3150, 92, 87, "Text"], Cell[4757, 143, 3000, 74, 145, "Input"] }, Open ]] } ] *)