(* Content-type: application/vnd.wolfram.mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 10.4' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 158, 7] NotebookDataLength[ 34538, 912] NotebookOptionsPosition[ 28378, 813] NotebookOutlinePosition[ 28990, 835] CellTagsIndexPosition[ 28947, 832] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["Pure functions. LinearModelFit", "Title", CellChangeTimes->{{3.668251272826833*^9, 3.6682513045541053`*^9}, { 3.6682516559473243`*^9, 3.66825166290457*^9}, {3.682842826258929*^9, 3.682842848254422*^9}, 3.7005577919607916`*^9},ExpressionUUID->"0ddb3880-f1a2-4aa2-a8a4-\ 0c43e7ee2514"], Cell[CellGroupData[{ Cell["\<\ Pure functions: when a function is needed in a very limited scope.\ \>", "Section", CellChangeTimes->{{3.5914514831933737`*^9, 3.5914514870374446`*^9}, { 3.591458753632032*^9, 3.5914588062071047`*^9}, {3.6828428573982954`*^9, 3.682842885014832*^9}},ExpressionUUID->"e5b6a752-5d42-40a5-85fb-\ fd3f89dcb3ba"], Cell[BoxData[ RowBox[{ RowBox[{"Function", "[", RowBox[{"x", ",", RowBox[{"x", "^", "2"}]}], "]"}], " ", RowBox[{"(*", " ", RowBox[{ RowBox[{ "First", " ", "parameter", " ", "is", " ", "the", " ", "anonymous", " ", "variable"}], ",", " ", RowBox[{ "which", " ", "is", " ", "transformed", " ", "according", " ", "the", " ", "second"}]}], " ", "*)"}]}]], "Input", CellChangeTimes->{{3.5914514915846996`*^9, 3.5914514996166196`*^9}, { 3.5914516931015205`*^9, 3.591451721572647*^9}, {3.6198066124890056`*^9, 3.6198066166924314`*^9}, {3.682842894484006*^9, 3.682842942337006*^9}}, CellLabel->"In[1]:=",ExpressionUUID->"ce078457-c90d-43e9-90c7-e516881e85d9"], Cell[BoxData[ RowBox[{"%", "[", RowBox[{"a", "+", "b"}], "]"}]], "Input", CellChangeTimes->{{3.5914515361821685`*^9, 3.591451544292222*^9}}, CellLabel->"In[2]:=",ExpressionUUID->"738af68a-924b-49ac-89a2-f0c53d8efaeb"], Cell[CellGroupData[{ Cell["Now, with runes", "Subsection", CellChangeTimes->{{3.6682513891725593`*^9, 3.668251392417314*^9}, { 3.668362436417982*^9, 3.6683624399810266`*^9}, {3.6828430397705708`*^9, 3.682843044189286*^9}},ExpressionUUID->"4d62ab23-2e60-4e45-8bbd-\ ee8d99a21740"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"#", "^", "2"}], "&"}], " ", RowBox[{"(*", " ", RowBox[{"#", ",", " ", RowBox[{"equivalent", " ", "to", " ", "#1"}], ",", " ", RowBox[{"is", " ", "the", " ", "parameter"}], ",", " ", RowBox[{ RowBox[{ RowBox[{ RowBox[{ "therefore", " ", "it", " ", "is", " ", "already", " ", "in", " ", "the", " ", "place", " ", "of", " ", "the", " ", "argument"}], " ", "-", " ", RowBox[{"the", " ", "ampersand"}]}], " ", "&"}], " ", "tells", " ", "the", " ", "program", " ", "that", " ", "it", " ", "is", " ", "a", " ", "pure", " ", "function"}]}], " ", "*)"}]}]], "Input", CellChangeTimes->{{3.5914516440661745`*^9, 3.5914516479258747`*^9}, { 3.5914517393553815`*^9, 3.5914518172212563`*^9}, {3.6828430488911467`*^9, 3.682843120064143*^9}},ExpressionUUID->"acf5daff-3c58-4241-b076-\ 17988ceb471c"], Cell[BoxData[ RowBox[{"%", "[", RowBox[{"a", "+", "b"}], "]"}]], "Input", CellChangeTimes->{{3.59145165533274*^9, 3.591451658176731*^9}}, CellLabel->"In[3]:=",ExpressionUUID->"6a3fee61-db94-43f7-9d74-8a93c9025cd0"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["Selecting values of a list", "Section", CellChangeTimes->{{3.591451876460576*^9, 3.591451888914741*^9}, { 3.6682515333142056`*^9, 3.668251535131667*^9}, {3.6828431344951887`*^9, 3.682843140643964*^9}},ExpressionUUID->"d20e2f11-ca12-43a3-9d2e-\ 155c3c54ac11"], Cell["a bigger test list for this function", "Text", CellChangeTimes->{{3.5914518958684464`*^9, 3.5914518975560875`*^9}, { 3.682843144314788*^9, 3.6828431460301332`*^9}, {3.6828452103367157`*^9, 3.682845211690592*^9}, {3.682845301018221*^9, 3.682845315340974*^9}},ExpressionUUID->"4176e2d0-eb26-4401-9909-\ aa4da3afc086"], Cell[BoxData[ RowBox[{ RowBox[{"testList", "=", RowBox[{"RandomVariate", "[", RowBox[{ RowBox[{"NormalDistribution", "[", RowBox[{"10", ",", "4"}], "]"}], ",", "1000"}], "]"}]}], ";"}]], "Input", CellLabel->"In[4]:=",ExpressionUUID->"7091c003-5944-4aff-b52c-908297b874fb"], Cell[BoxData[ RowBox[{"Select", "[", RowBox[{"testList", ",", RowBox[{ RowBox[{"#", "<", "0"}], "&"}]}], "]"}]], "Input", CellChangeTimes->{{3.591451920604883*^9, 3.591451961155146*^9}, { 3.668251477873813*^9, 3.6682514829462233`*^9}}, CellLabel->"In[5]:=",ExpressionUUID->"df09fabf-d812-43c9-8e60-14f6c6781879"], Cell[BoxData[ RowBox[{"Select", "[", RowBox[{"testList", ",", " ", RowBox[{ RowBox[{"0.5", "<", "#", "<", "1"}], "&"}]}], "]"}]], "Input", CellChangeTimes->{{3.5914519676088066`*^9, 3.5914519828288307`*^9}}, CellLabel->"In[6]:=",ExpressionUUID->"f0ac0ca4-1f80-48c0-9c5f-74f4f9a07fc2"] }, Open ]], Cell[CellGroupData[{ Cell["LinearModelFit", "Section", CellChangeTimes->{{3.7005530024233317`*^9, 3.700553005536691*^9}},ExpressionUUID->"7dd8c06d-e584-4ae9-9798-\ e4c2fe455b3a"], Cell["An example with Angular Distribution", "Text", CellChangeTimes->{{3.6822243689328966`*^9, 3.682224377904173*^9}, { 3.700552987945752*^9, 3.7005529916585455`*^9}},ExpressionUUID->"96a803df-a9ae-4fed-9d0e-\ 682ee95bedec"], Cell[CellGroupData[{ Cell["Experimental data", "Subsection", CellChangeTimes->{{3.6822255722801604`*^9, 3.6822255747428355`*^9}},ExpressionUUID->"e27eb51f-b529-408c-a777-\ 17da0c92bece"], Cell[BoxData[ RowBox[{"xws", "=", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"0", ",", "1.17", ",", "0.12"}], "}"}], ",", RowBox[{"{", RowBox[{"0.5236", ",", "1.43", ",", "0.11"}], "}"}], ",", RowBox[{"{", RowBox[{"1.0472", ",", "1.16", ",", "0.09"}], "}"}], ",", RowBox[{"{", RowBox[{"1.5708", ",", "0.5", ",", "0.07"}], "}"}], ",", RowBox[{"{", RowBox[{"2.0944", ",", "0.95", ",", "0.09"}], "}"}], ",", RowBox[{"{", RowBox[{"2.6180", ",", "1.38", ",", "0.11"}], "}"}], ",", RowBox[{"{", RowBox[{"3.1416", ",", "0.96", ",", "0.12"}], "}"}]}], "}"}]}]], "Input", CellChangeTimes->{{3.6822248534514904`*^9, 3.6822249524825835`*^9}, { 3.682227694716255*^9, 3.68222769536155*^9}, 3.890763383538672*^9}, CellLabel->"In[10]:=",ExpressionUUID->"d62e98b5-7d5b-4635-9a4d-e4b1c710366f"], Cell["\<\ dealing with error bars is somewhat tricky, but has side benefits\ \>", "Text", CellChangeTimes->{{3.8907634185450325`*^9, 3.890763438824785*^9}, { 3.8907640293037987`*^9, 3.890764034799099*^9}},ExpressionUUID->"2d8a0e1e-7c68-4a87-a5cc-\ d8caf52c6d3e"], Cell[BoxData[ RowBox[{"n1", "=", RowBox[{"Around", "[", RowBox[{"1.17", ",", "0.12"}], "]"}]}]], "Input", CellChangeTimes->{{3.8907634421468987`*^9, 3.890763474408601*^9}}, CellLabel->"In[12]:=",ExpressionUUID->"f580807c-883f-439f-84b0-ad72f617a336"], Cell[BoxData[ RowBox[{"n2", "=", RowBox[{"Around", "[", RowBox[{"2.33", ",", "0.20"}], "]"}]}]], "Input", CellChangeTimes->{{3.8907634779950075`*^9, 3.890763494528781*^9}}, CellLabel->"In[13]:=",ExpressionUUID->"71a8d850-cd57-4ce9-bfd4-f5a67c12ff58"], Cell[BoxData[ RowBox[{"n1", "*", "n2"}]], "Input", CellChangeTimes->{{3.890763496930357*^9, 3.890763498840248*^9}}, CellLabel->"In[14]:=",ExpressionUUID->"c54fac4e-7ba6-4412-b8ce-f97f1227c0a8"], Cell[BoxData[ RowBox[{"n1", "/", "n2"}]], "Input", CellChangeTimes->{{3.890763502026724*^9, 3.890763503712216*^9}}, CellLabel->"In[15]:=",ExpressionUUID->"11f4d358-1733-46ee-aed8-94a7ed74643b"], Cell[BoxData[ RowBox[{"n1", "/", RowBox[{"n2", "^", "2"}]}]], "Input", CellChangeTimes->{{3.890763505674966*^9, 3.8907635095446143`*^9}}, CellLabel->"In[16]:=",ExpressionUUID->"a8b6a138-2ab3-4582-93ec-f7c442eed418"], Cell[BoxData[ RowBox[{"xw", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"xws", "[", RowBox[{"[", RowBox[{"i", ",", "1"}], "]"}], "]"}], ",", RowBox[{"Around", "[", RowBox[{ RowBox[{"xws", "[", RowBox[{"[", RowBox[{"i", ",", "2"}], "]"}], "]"}], ",", RowBox[{"xws", "[", RowBox[{"[", RowBox[{"i", ",", "3"}], "]"}], "]"}]}], " ", "]"}]}], "}"}], ",", RowBox[{"{", RowBox[{"i", ",", RowBox[{"Length", "[", "xws", "]"}]}], "}"}]}], "]"}]}]], "Input", CellChangeTimes->{{3.6822246231512203`*^9, 3.6822246366555614`*^9}, { 3.6822276982142553`*^9, 3.682227702232012*^9}, {3.890763523424487*^9, 3.8907636090644054`*^9}}, CellLabel->"In[18]:=",ExpressionUUID->"c24e0d0b-352f-4fec-85c4-3adbb8f1743c"], Cell[BoxData[ RowBox[{"wDataPlot", "=", RowBox[{"ListPlot", "[", RowBox[{"xw", ",", RowBox[{"AxesLabel", "\[Rule]", RowBox[{"{", RowBox[{"\"\<\[Theta] (rd)\>\"", ",", "\"\\""}], "}"}]}], ",", RowBox[{"BaseStyle", "\[Rule]", RowBox[{"FontSize", "->", "14"}]}]}], "]"}]}]], "Input", CellChangeTimes->{{3.682224767626813*^9, 3.6822248076915226`*^9}, { 3.6822251233150535`*^9, 3.6822251315832396`*^9}, {3.6822277139147635`*^9, 3.682227714437364*^9}, {3.8907636236085014`*^9, 3.890763630400334*^9}, { 3.890763694065035*^9, 3.890763705776707*^9}}, CellLabel->"In[26]:=",ExpressionUUID->"591bf157-e6b4-4eb3-8679-9c6344519e60"] }, Open ]], Cell[CellGroupData[{ Cell["Fit: first unweighted, then using the variances", "Subsection", CellChangeTimes->{{3.6822255891074524`*^9, 3.6822256339312444`*^9}},ExpressionUUID->"27751d0b-e8cc-48c7-b31d-\ 628405ffd076"], Cell[BoxData[ RowBox[{"aUnweightedFit", "=", RowBox[{"LinearModelFit", "[", RowBox[{ RowBox[{"xws", "[", RowBox[{"[", RowBox[{"All", ",", RowBox[{"{", RowBox[{"1", ",", "2"}], "}"}]}], "]"}], "]"}], ",", RowBox[{"{", RowBox[{ RowBox[{"LegendreP", "[", RowBox[{"2", ",", RowBox[{"Cos", "[", "\[Theta]", "]"}]}], "]"}], ",", RowBox[{"LegendreP", "[", RowBox[{"4", ",", RowBox[{"Cos", "[", "\[Theta]", "]"}]}], "]"}]}], "}"}], ",", RowBox[{"{", "\[Theta]", "}"}]}], "]"}]}]], "Input", CellChangeTimes->{{3.682225046365136*^9, 3.682225096885393*^9}, { 3.682227722690777*^9, 3.6822277232275505`*^9}, {3.8907636712331085`*^9, 3.8907636751197124`*^9}}, CellLabel->"In[22]:=",ExpressionUUID->"a811f683-bb16-42d3-b09b-44e1ff4bb2ac"], Cell[BoxData[ RowBox[{"aUnweightedFit", "[", "\"\\"", "]"}]], "Input", CellChangeTimes->{{3.682225119459906*^9, 3.6822251494493504`*^9}}, CellLabel->"In[23]:=",ExpressionUUID->"231afd99-f1a3-4d5b-bf2b-ec07004a896e"], Cell[BoxData[ RowBox[{"aUwFitPlot", "=", RowBox[{"Plot", "[", RowBox[{ RowBox[{"aUnweightedFit", "[", "x", "]"}], ",", RowBox[{"{", RowBox[{"x", ",", "0", ",", "Pi"}], "}"}]}], "]"}]}]], "Input", CellChangeTimes->{{3.682225204779869*^9, 3.6822252379322968`*^9}}, CellLabel->"In[24]:=",ExpressionUUID->"fe5a99f3-7b25-40c5-ae93-a85ecc2a6a0f"], Cell[BoxData[ RowBox[{"Show", "[", RowBox[{"wDataPlot", ",", "aUwFitPlot"}], "]"}]], "Input", CellChangeTimes->{{3.6822252508221006`*^9, 3.682225263528223*^9}}, CellLabel->"In[27]:=",ExpressionUUID->"294c03fb-857a-4587-8376-9acdbdcb498d"], Cell[BoxData[ RowBox[{"\[Sigma]", "=", RowBox[{"xws", "[", RowBox[{"[", RowBox[{"All", ",", "3"}], "]"}], "]"}]}]], "Input", CellChangeTimes->{{3.682224646475955*^9, 3.682224659236464*^9}, { 3.6822277096240125`*^9, 3.682227710141057*^9}}, CellLabel->"In[20]:=",ExpressionUUID->"f13772ee-e607-4063-98b1-a05e980cb05f"], Cell[BoxData[ RowBox[{"aFit", "=", RowBox[{"LinearModelFit", "[", RowBox[{ RowBox[{"xws", "[", RowBox[{"[", RowBox[{"All", ",", RowBox[{"{", RowBox[{"1", ",", "2"}], "}"}]}], "]"}], "]"}], ",", RowBox[{"{", RowBox[{ RowBox[{"LegendreP", "[", RowBox[{"2", ",", RowBox[{"Cos", "[", "\[Theta]", "]"}]}], "]"}], ",", RowBox[{"LegendreP", "[", RowBox[{"4", ",", RowBox[{"Cos", "[", "\[Theta]", "]"}]}], "]"}]}], "}"}], ",", RowBox[{"{", "\[Theta]", "}"}], ",", RowBox[{"Weights", "\[Rule]", RowBox[{"1", "/", RowBox[{"\[Sigma]", "^", "2"}]}]}], ",", RowBox[{"VarianceEstimatorFunction", "\[Rule]", RowBox[{"(", RowBox[{"1", "&"}], ")"}]}]}], "]"}]}]], "Input", CellChangeTimes->{{3.682225283221429*^9, 3.6822253186977196`*^9}, { 3.6822277353582864`*^9, 3.682227735999838*^9}, {3.8907637269051895`*^9, 3.890763731647504*^9}}, CellLabel->"In[29]:=",ExpressionUUID->"3bb6b9aa-7d1e-4def-9934-3030c246d5e9"] }, Open ]], Cell[CellGroupData[{ Cell["Comparing weighted and unweighted parameter fits", "Subsection", CellChangeTimes->{{3.6822256594305396`*^9, 3.682225689903594*^9}},ExpressionUUID->"bd32f195-c0c0-4951-9359-\ 987ee1d559c9"], Cell[BoxData[ RowBox[{"aFit", "[", "\"\\"", "]"}]], "Input", CellChangeTimes->{{3.682225327240012*^9, 3.6822253395098667`*^9}}, CellLabel->"In[30]:=",ExpressionUUID->"2f4289d0-44b1-4526-aef8-64e0eb175cf3"], Cell[BoxData[ RowBox[{"aUnweightedFit", "[", "\"\\"", "]"}]], "Input", CellChangeTimes->{{3.6822253525528154`*^9, 3.6822253552861633`*^9}}, CellLabel->"In[31]:=",ExpressionUUID->"9224bc83-6757-45a5-bce9-8c8b3149f9ba"], Cell[BoxData[ RowBox[{"Show", "[", RowBox[{"wDataPlot", ",", RowBox[{"Plot", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"aUnweightedFit", "[", "x", "]"}], ",", RowBox[{"aFit", "[", "x", "]"}]}], "}"}], ",", RowBox[{"{", RowBox[{"x", ",", "0", ",", "Pi"}], "}"}], ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"{", RowBox[{"Blue", ",", "Red"}], "}"}]}]}], "]"}]}], "]"}]], "Input", CellChangeTimes->{{3.6822253884497333`*^9, 3.682225427803136*^9}}, CellLabel->"In[32]:=",ExpressionUUID->"cd59da80-0ee9-45dc-a58b-8cd588eb4954"] }, Open ]], Cell[CellGroupData[{ Cell["\<\ Mandatory tests - ALWAYS look at these graphics and numbers when using linear \ models\ \>", "Subsection", CellChangeTimes->{{3.6822261232024226`*^9, 3.682226197715024*^9}, { 3.6822263336366067`*^9, 3.6822263398684473`*^9}},ExpressionUUID->"782f625c-ba8a-430f-b5b6-\ 0ffa0f6c30d6"], Cell[BoxData[ RowBox[{"residuals", "=", RowBox[{"Table", "[", " ", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"xws", "[", RowBox[{"[", RowBox[{"i", ",", "1"}], "]"}], "]"}], ",", RowBox[{ RowBox[{"aFit", "[", "\"\\"", "]"}], "[", RowBox[{"[", "i", "]"}], "]"}]}], " ", "}"}], ",", RowBox[{"{", RowBox[{"i", ",", "7"}], "}"}]}], "]"}]}]], "Input", CellChangeTimes->{{3.682225698243644*^9, 3.6822257026090965`*^9}, { 3.6822257382983055`*^9, 3.682225811499585*^9}, {3.6822277475280733`*^9, 3.6822277481408567`*^9}, 3.890763833169445*^9}, CellLabel->"In[37]:=",ExpressionUUID->"24acd601-e21a-478f-840a-66550c3f7471"], Cell[BoxData[ RowBox[{"ListPlot", "[", RowBox[{"residuals", ",", RowBox[{"AxesLabel", "\[Rule]", RowBox[{"{", RowBox[{"\"\<\[Theta] (rd)\>\"", ",", "\"\\""}], "}"}]}], ",", RowBox[{"BaseStyle", "\[Rule]", RowBox[{"FontSize", "->", "14"}]}]}], "]"}]], "Input", CellChangeTimes->{{3.6822258197328253`*^9, 3.6822258966964617`*^9}, 3.8907638058963985`*^9}, CellLabel->"In[35]:=",ExpressionUUID->"53246b0b-6a76-4cd2-b2e6-823a831d9849"], Cell[BoxData[ RowBox[{"residualsW", "=", RowBox[{"Table", "[", " ", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"xws", "[", RowBox[{"[", RowBox[{"i", ",", "2"}], "]"}], "]"}], ",", RowBox[{ RowBox[{"aFit", "[", "\"\\"", "]"}], "[", RowBox[{"[", "i", "]"}], "]"}]}], " ", "}"}], ",", RowBox[{"{", RowBox[{"i", ",", "7"}], "}"}]}], "]"}]}]], "Input", CellChangeTimes->{{3.6822259360361433`*^9, 3.6822259397220383`*^9}, { 3.682225989862965*^9, 3.682225996926787*^9}, {3.682228085269411*^9, 3.6822280854321613`*^9}, 3.8907638372644916`*^9}, CellLabel->"In[38]:=",ExpressionUUID->"608df3e0-7fab-47ca-8ac1-9a89deb3d6b4"], Cell[BoxData[ RowBox[{"ListPlot", "[", RowBox[{"residualsW", ",", RowBox[{"AxesLabel", "\[Rule]", RowBox[{"{", RowBox[{"\"\\"", ",", "\"\\""}], "}"}]}], ",", RowBox[{"BaseStyle", "\[Rule]", RowBox[{"FontSize", "->", "14"}]}]}], "]"}]], "Input", CellChangeTimes->{{3.6822258197328253`*^9, 3.6822258966964617`*^9}, { 3.6822259686820793`*^9, 3.6822259941095467`*^9}, 3.8907637993997765`*^9}, CellLabel->"In[39]:=",ExpressionUUID->"81293ca8-9079-4abd-9bbf-8210643028ff"], Cell[BoxData[ RowBox[{"chiSquare", "=", RowBox[{"Total", "[", " ", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"aFit", "[", "\"\\"", "]"}], "/", "\[Sigma]"}], ")"}], "^", "2"}], "]"}]}]], "Input", CellChangeTimes->{{3.6822260165366745`*^9, 3.68222603414252*^9}, { 3.682226067513317*^9, 3.682226085412595*^9}}, CellLabel->"In[40]:=",ExpressionUUID->"61d4746d-c979-43a6-92ac-78d5d9cc84e3"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["NonlinearModelFit", "Section", CellChangeTimes->{{3.68284329339003*^9, 3.68284329874432*^9}},ExpressionUUID->"79da2749-de3b-4b34-9d86-\ 4cedbf58bd6b"], Cell["an example with a simple sinus function", "Text", CellChangeTimes->{{3.7005531136839504`*^9, 3.700553157332909*^9}, { 3.7005532074573474`*^9, 3.700553208160711*^9}},ExpressionUUID->"dfcf01a1-3148-44d3-aa35-\ 2da597ce0f8a"], Cell[BoxData[ RowBox[{"data", "=", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"0.00", ",", RowBox[{"-", "0.8"}], ",", "0.5"}], "}"}], ",", RowBox[{"{", RowBox[{"0.25", ",", "9.5", ",", "0.8"}], "}"}], ",", RowBox[{"{", RowBox[{"0.5", ",", RowBox[{"-", "7.3"}], ",", "0.7"}], "}"}], ",", RowBox[{"{", RowBox[{"0.75", ",", RowBox[{"-", "2.3"}], ",", "0.5"}], "}"}], ",", RowBox[{"{", RowBox[{"1.00", ",", "11.0", ",", "0.9"}], "}"}], ",", RowBox[{"{", RowBox[{"1.25", ",", RowBox[{"-", "5.5"}], ",", "0.6"}], "}"}], ",", RowBox[{"{", RowBox[{"1.5", ",", RowBox[{"-", "5.7"}], ",", "0.6"}], "}"}], ",", RowBox[{"{", RowBox[{"1.75", ",", "10.4", ",", "0.9"}], "}"}], ",", RowBox[{"{", RowBox[{"2.00", ",", RowBox[{"-", "2.3"}], ",", "0.5"}], "}"}]}], "}"}]}]], "Input", CellChangeTimes->{{3.6828443365478234`*^9, 3.682844409107017*^9}}, CellLabel->"In[41]:=",ExpressionUUID->"fd04c708-e7b4-47dd-a32f-6c34d097fe08"], Cell[BoxData[ RowBox[{"fit", "=", RowBox[{"NonlinearModelFit", "[", RowBox[{ RowBox[{"data", "[", RowBox[{"[", RowBox[{"All", ",", RowBox[{"{", RowBox[{"1", ",", "2"}], "}"}]}], "]"}], "]"}], ",", RowBox[{"{", RowBox[{"a", " ", RowBox[{"Sin", "[", RowBox[{"w", " ", "t"}], "]"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"a", ",", "10"}], "}"}], ",", RowBox[{"{", RowBox[{"w", ",", "8"}], "}"}]}], "}"}], ",", RowBox[{"{", "t", "}"}], ",", RowBox[{"Weights", "\[Rule]", RowBox[{"1", "/", RowBox[{ RowBox[{"data", "[", RowBox[{"[", RowBox[{"All", ",", "3"}], "]"}], "]"}], "^", "2"}]}]}], ",", RowBox[{"VarianceEstimatorFunction", "\[Rule]", RowBox[{"(", RowBox[{"1", "&"}], ")"}]}]}], "]"}]}]], "Input", CellChangeTimes->{{3.682844414078909*^9, 3.6828445128216915`*^9}, { 3.682844732526126*^9, 3.6828447828130245`*^9}}, CellLabel->"In[42]:=",ExpressionUUID->"2cbf2a53-171c-4546-a591-ed9b016d0da5"], Cell[BoxData[ RowBox[{"fit", "[", "\"\\"", "]"}]], "Input", CellChangeTimes->{{3.6828447134528666`*^9, 3.682844727024871*^9}}, CellLabel->"In[43]:=",ExpressionUUID->"fdf96141-746d-4269-953e-ddea30d52f94"], Cell[BoxData[ RowBox[{"\[Chi]2", "=", RowBox[{"Total", "[", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"fit", "[", "\"\\"", "]"}], "/", RowBox[{"data", "[", RowBox[{"[", RowBox[{"All", ",", "3"}], "]"}], "]"}]}], ")"}], "^", "2"}], "]"}]}]], "Input", CellChangeTimes->{{3.6828449106866007`*^9, 3.6828449510604887`*^9}}, CellLabel->"In[44]:=",ExpressionUUID->"efc0e317-1f06-46b9-b50e-61de1d936197"], Cell[BoxData[ RowBox[{"p\[Chi]2", "=", RowBox[{"100", RowBox[{"(", RowBox[{"1", "-", RowBox[{"CDF", "[", RowBox[{ RowBox[{"ChiSquareDistribution", "[", RowBox[{ RowBox[{"Length", "[", "data", "]"}], "-", "2"}], "]"}], ",", "\[Chi]2"}], "]"}]}], ")"}]}]}]], "Input", CellChangeTimes->{{3.682844954892821*^9, 3.68284499317365*^9}}, CellLabel->"In[45]:=",ExpressionUUID->"2165f8a3-c941-4661-bb39-dab73fc9aaa6"], Cell[BoxData[ RowBox[{"ListPlot", "[", RowBox[{ RowBox[{"Transpose", "[", RowBox[{"{", " ", RowBox[{ RowBox[{"data", "[", RowBox[{"[", RowBox[{"All", ",", "1"}], "]"}], "]"}], ",", RowBox[{"fit", "[", "\"\\"", "]"}]}], "}"}], "]"}], ",", RowBox[{"BaseStyle", "\[Rule]", RowBox[{"FontSize", "->", "14"}]}]}], "]"}]], "Input", CellChangeTimes->{{3.682845004131*^9, 3.6828450640035625`*^9}, { 3.6828451027077007`*^9, 3.682845111078694*^9}, 3.89076388266405*^9}, CellLabel->"In[47]:=",ExpressionUUID->"715c17c3-e737-4e08-8943-5e80f8aaf2a4"], Cell[BoxData[ RowBox[{"ListPlot", "[", RowBox[{ RowBox[{"Transpose", "[", RowBox[{"{", " ", RowBox[{ RowBox[{"data", "[", RowBox[{"[", RowBox[{"All", ",", "2"}], "]"}], "]"}], ",", RowBox[{"fit", "[", "\"\\"", "]"}]}], "}"}], "]"}], ",", RowBox[{"BaseStyle", "\[Rule]", RowBox[{"FontSize", "->", "14"}]}]}], "]"}]], "Input", CellChangeTimes->{{3.6828451256169167`*^9, 3.68284512583237*^9}, 3.8907638990322666`*^9}, CellLabel->"In[49]:=",ExpressionUUID->"4f654850-7c29-4459-a5f4-30ca43be1979"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"dataBar", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"data", "[", RowBox[{"[", RowBox[{"i", ",", "1"}], "]"}], "]"}], ",", RowBox[{"Around", "[", RowBox[{ RowBox[{"data", "[", RowBox[{"[", RowBox[{"i", ",", "2"}], "]"}], "]"}], ",", RowBox[{"data", "[", RowBox[{"[", RowBox[{"i", ",", "3"}], "]"}], "]"}]}], " ", "]"}]}], "}"}], ",", RowBox[{"{", RowBox[{"i", ",", RowBox[{"Length", "[", "data", "]"}]}], "}"}]}], "]"}]}]], "Input", CellChangeTimes->{{3.6822246231512203`*^9, 3.6822246366555614`*^9}, { 3.6822276982142553`*^9, 3.682227702232012*^9}, {3.890763523424487*^9, 3.8907636090644054`*^9}, {3.8907639296164556`*^9, 3.89076395012759*^9}}, CellLabel->"In[50]:=",ExpressionUUID->"c4ceb40a-f9ec-4cff-9670-b7a778b0b697"], Cell[BoxData[ RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"0.`", ",", InterpretationBox[ TemplateBox[{"-0.8", "0.5"}, "Around"], Around[-0.8, 0.5]]}], "}"}], ",", RowBox[{"{", RowBox[{"0.25`", ",", InterpretationBox[ TemplateBox[{"9.5", "0.8"}, "Around"], Around[9.5, 0.8]]}], "}"}], ",", RowBox[{"{", RowBox[{"0.5`", ",", InterpretationBox[ TemplateBox[{"-7.3", "0.7"}, "Around"], Around[-7.3, 0.7]]}], "}"}], ",", RowBox[{"{", RowBox[{"0.75`", ",", InterpretationBox[ TemplateBox[{"-2.3", "0.5"}, "Around"], Around[-2.3, 0.5]]}], "}"}], ",", RowBox[{"{", RowBox[{"1.`", ",", InterpretationBox[ TemplateBox[{"11.0", "0.9"}, "Around"], Around[11., 0.9]]}], "}"}], ",", RowBox[{"{", RowBox[{"1.25`", ",", InterpretationBox[ TemplateBox[{"-5.5", "0.6"}, "Around"], Around[-5.5, 0.6]]}], "}"}], ",", RowBox[{"{", RowBox[{"1.5`", ",", InterpretationBox[ TemplateBox[{"-5.7", "0.6"}, "Around"], Around[-5.7, 0.6]]}], "}"}], ",", RowBox[{"{", RowBox[{"1.75`", ",", InterpretationBox[ TemplateBox[{"10.4", "0.9"}, "Around"], Around[10.4, 0.9]]}], "}"}], ",", RowBox[{"{", RowBox[{"2.`", ",", InterpretationBox[ TemplateBox[{"-2.3", "0.5"}, "Around"], Around[-2.3, 0.5]]}], "}"}]}], "}"}]], "Output", CellChangeTimes->{3.8907639532911277`*^9}, CellLabel->"Out[50]=",ExpressionUUID->"39e8dca0-28d6-4674-8a38-87d4f1a225aa"] }, Open ]], Cell[BoxData[ RowBox[{"Show", "[", RowBox[{ RowBox[{"ListPlot", "[", RowBox[{"dataBar", ",", RowBox[{"PlotRange", "\[Rule]", RowBox[{"{", RowBox[{ RowBox[{"-", "12"}], ",", "12"}], "}"}]}]}], "]"}], ",", RowBox[{"Plot", "[", RowBox[{ RowBox[{"fit", "[", "x", "]"}], ",", RowBox[{"{", RowBox[{"x", ",", "0", ",", "2"}], "}"}]}], "]"}], ",", RowBox[{"BaseStyle", "\[Rule]", RowBox[{"FontSize", "->", "14"}]}]}], "]"}]], "Input", CellChangeTimes->{{3.68284508676406*^9, 3.6828450936666965`*^9}, { 3.682845129319728*^9, 3.6828451961435003`*^9}, {3.890763961199972*^9, 3.890763974752719*^9}}, CellLabel->"In[52]:=",ExpressionUUID->"78f600e6-1cbf-4c87-8eea-2be2a471d10a"] }, Open ]], Cell[CellGroupData[{ Cell["Exercise", "Section", CellChangeTimes->{{3.6828445553919277`*^9, 3.6828445572606373`*^9}},ExpressionUUID->"85a1c3ed-3996-43f0-b80e-\ f6fae54051b6"], Cell[TextData[{ "Ajuste os par\[AHat]metros do polin\[OHat]mio ", Cell[BoxData[ FormBox[ RowBox[{"y", "=", RowBox[{"a", "+", RowBox[{"b", " ", "x"}], " ", "+", " ", RowBox[{"c", " ", SuperscriptBox["x", "3"], " "}]}]}], TraditionalForm]],ExpressionUUID-> "c48a5fa6-47d4-4aaf-9f9f-30d0ae66fbf6"], "ao conjunto de dados z= {x,y} abaixo. Os desvios-padr\[OTilde]es \ s\[ATilde]o todos iguais a 0.5. Calcule ", Cell[BoxData[ FormBox[ RowBox[{ SuperscriptBox["\[Chi]", "2"], " "}], TraditionalForm]],ExpressionUUID-> "ed2f26a9-bf5a-4637-b723-ed9ad0b63025"], "e fa\[CCedilla]a os gr\[AAcute]ficos necess\[AAcute]rios \[AGrave] avalia\ \[CCedilla]\[ATilde]o da qualidade do ajuste." }], "Text", CellChangeTimes->{{3.682844566459696*^9, 3.6828446106409965`*^9}, { 3.7005532917722836`*^9, 3.7005533625321827`*^9}, {3.7005567960877156`*^9, 3.700556809192773*^9}, {3.7005571832984114`*^9, 3.700557255166252*^9}, { 3.8907639829837027`*^9, 3.890763990375928*^9}},ExpressionUUID->"25d66400-7711-4ea5-959a-\ ca3dbb410b3d"], Cell[BoxData[ RowBox[{"z", "=", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"-", "3.0"}], ",", "8.7"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "2.5"}], ",", "5.6"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "2.0"}], ",", "4.6"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "1.5"}], ",", "4.4"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "1.0"}], ",", "3.3"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "0.5"}], ",", "2.8"}], "}"}], ",", RowBox[{"{", RowBox[{"0", ",", "1.7"}], "}"}], ",", RowBox[{"{", RowBox[{"0.5", ",", "2.8"}], "}"}], ",", RowBox[{"{", RowBox[{"1.0", ",", "1.8"}], "}"}], ",", RowBox[{"{", RowBox[{"1.5", ",", "0.9"}], "}"}], ",", RowBox[{"{", RowBox[{"2.0", ",", "0.8"}], "}"}], ",", RowBox[{"{", RowBox[{"2.5", ",", RowBox[{"-", "0.4"}]}], "}"}], ",", RowBox[{"{", RowBox[{"3.0", ",", RowBox[{"-", "2.7"}]}], "}"}], ",", RowBox[{"{", RowBox[{"3.5", ",", RowBox[{"-", "5.3"}]}], "}"}], ",", RowBox[{"{", RowBox[{"4.0", ",", RowBox[{"-", "6.4"}]}], "}"}]}], "}"}]}]], "Input",ExpressionUUID->\ "18740fb8-91ec-4246-abd8-7551a715286b"] }, Open ]] }, Open ]] }, WindowSize->{1040.25, 709.5}, WindowMargins->{{Automatic, 162.75}, {-43.5, Automatic}}, PrintingCopies->1, PrintingPageRange->{32000, 32000}, PrintingOptions->{"Magnification"->1., "PaperOrientation"->"Portrait", "PaperSize"->{595.1999999999999, 841.68}}, Magnification:>1.3 Inherited, FrontEndVersion->"13.0 for Microsoft Windows (64-bit) (February 4, 2022)", StyleDefinitions->"Default.nb", ExpressionUUID->"f3de6545-7eb0-486d-9833-41b06af2961f" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[580, 22, 301, 5, 126, "Title",ExpressionUUID->"0ddb3880-f1a2-4aa2-a8a4-0c43e7ee2514"], Cell[CellGroupData[{ Cell[906, 31, 322, 6, 134, "Section",ExpressionUUID->"e5b6a752-5d42-40a5-85fb-fd3f89dcb3ba"], Cell[1231, 39, 707, 16, 62, "Input",ExpressionUUID->"ce078457-c90d-43e9-90c7-e516881e85d9"], Cell[1941, 57, 223, 4, 36, "Input",ExpressionUUID->"738af68a-924b-49ac-89a2-f0c53d8efaeb"], Cell[CellGroupData[{ Cell[2189, 65, 264, 4, 70, "Subsection",ExpressionUUID->"4d62ab23-2e60-4e45-8bbd-ee8d99a21740"], Cell[2456, 71, 920, 21, 87, "Input",ExpressionUUID->"acf5daff-3c58-4241-b076-17988ceb471c"], Cell[3379, 94, 220, 4, 36, "Input",ExpressionUUID->"6a3fee61-db94-43f7-9d74-8a93c9025cd0"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[3648, 104, 270, 4, 86, "Section",ExpressionUUID->"d20e2f11-ca12-43a3-9d2e-155c3c54ac11"], Cell[3921, 110, 330, 5, 45, "Text",ExpressionUUID->"4176e2d0-eb26-4401-9909-aa4da3afc086"], Cell[4254, 117, 297, 7, 36, "Input",ExpressionUUID->"7091c003-5944-4aff-b52c-908297b874fb"], Cell[4554, 126, 328, 7, 36, "Input",ExpressionUUID->"df09fabf-d812-43c9-8e60-14f6c6781879"], Cell[4885, 135, 298, 6, 36, "Input",ExpressionUUID->"f0ac0ca4-1f80-48c0-9c5f-74f4f9a07fc2"] }, Open ]], Cell[CellGroupData[{ Cell[5220, 146, 161, 3, 86, "Section",ExpressionUUID->"7dd8c06d-e584-4ae9-9798-e4c2fe455b3a"], Cell[5384, 151, 231, 4, 45, "Text",ExpressionUUID->"96a803df-a9ae-4fed-9d0e-682ee95bedec"], Cell[CellGroupData[{ Cell[5640, 159, 169, 3, 70, "Subsection",ExpressionUUID->"e27eb51f-b529-408c-a777-17da0c92bece"], Cell[5812, 164, 866, 20, 62, "Input",ExpressionUUID->"d62e98b5-7d5b-4635-9a4d-e4b1c710366f"], Cell[6681, 186, 268, 6, 45, "Text",ExpressionUUID->"2d8a0e1e-7c68-4a87-a5cc-d8caf52c6d3e"], Cell[6952, 194, 260, 5, 36, "Input",ExpressionUUID->"f580807c-883f-439f-84b0-ad72f617a336"], Cell[7215, 201, 260, 5, 36, "Input",ExpressionUUID->"71a8d850-cd57-4ce9-bfd4-f5a67c12ff58"], Cell[7478, 208, 196, 3, 36, "Input",ExpressionUUID->"c54fac4e-7ba6-4412-b8ce-f97f1227c0a8"], Cell[7677, 213, 196, 3, 36, "Input",ExpressionUUID->"11f4d358-1733-46ee-aed8-94a7ed74643b"], Cell[7876, 218, 221, 4, 36, "Input",ExpressionUUID->"a8b6a138-2ab3-4582-93ec-f7c442eed418"], Cell[8100, 224, 853, 23, 36, "Input",ExpressionUUID->"c24e0d0b-352f-4fec-85c4-3adbb8f1743c"], Cell[8956, 249, 669, 13, 36, "Input",ExpressionUUID->"591bf157-e6b4-4eb3-8679-9c6344519e60"] }, Open ]], Cell[CellGroupData[{ Cell[9662, 267, 199, 3, 70, "Subsection",ExpressionUUID->"27751d0b-e8cc-48c7-b31d-628405ffd076"], Cell[9864, 272, 835, 21, 62, "Input",ExpressionUUID->"a811f683-bb16-42d3-b09b-44e1ff4bb2ac"], Cell[10702, 295, 235, 3, 36, "Input",ExpressionUUID->"231afd99-f1a3-4d5b-bf2b-ec07004a896e"], Cell[10940, 300, 365, 8, 36, "Input",ExpressionUUID->"fe5a99f3-7b25-40c5-ae93-a85ecc2a6a0f"], Cell[11308, 310, 244, 4, 36, "Input",ExpressionUUID->"294c03fb-857a-4587-8376-9acdbdcb498d"], Cell[11555, 316, 333, 7, 36, "Input",ExpressionUUID->"f13772ee-e607-4063-98b1-a05e980cb05f"], Cell[11891, 325, 1045, 27, 62, "Input",ExpressionUUID->"3bb6b9aa-7d1e-4def-9934-3030c246d5e9"] }, Open ]], Cell[CellGroupData[{ Cell[12973, 357, 198, 3, 70, "Subsection",ExpressionUUID->"bd32f195-c0c0-4951-9359-987ee1d559c9"], Cell[13174, 362, 225, 3, 36, "Input",ExpressionUUID->"2f4289d0-44b1-4526-aef8-64e0eb175cf3"], Cell[13402, 367, 237, 3, 36, "Input",ExpressionUUID->"9224bc83-6757-45a5-bce9-8c8b3149f9ba"], Cell[13642, 372, 601, 15, 36, "Input",ExpressionUUID->"cd59da80-0ee9-45dc-a58b-8cd588eb4954"] }, Open ]], Cell[CellGroupData[{ Cell[14280, 392, 297, 7, 105, "Subsection",ExpressionUUID->"782f625c-ba8a-430f-b5b6-0ffa0f6c30d6"], Cell[14580, 401, 715, 17, 36, "Input",ExpressionUUID->"24acd601-e21a-478f-840a-66550c3f7471"], Cell[15298, 420, 492, 11, 36, "Input",ExpressionUUID->"53246b0b-6a76-4cd2-b2e6-823a831d9849"], Cell[15793, 433, 716, 17, 36, "Input",ExpressionUUID->"608df3e0-7fab-47ca-8ac1-9a89deb3d6b4"], Cell[16512, 452, 533, 11, 36, "Input",ExpressionUUID->"81293ca8-9079-4abd-9bbf-8210643028ff"], Cell[17048, 465, 431, 10, 36, "Input",ExpressionUUID->"61d4746d-c979-43a6-92ac-78d5d9cc84e3"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[17528, 481, 160, 3, 86, "Section",ExpressionUUID->"79da2749-de3b-4b34-9d86-4cedbf58bd6b"], Cell[17691, 486, 234, 4, 45, "Text",ExpressionUUID->"dfcf01a1-3148-44d3-aa35-2da597ce0f8a"], Cell[17928, 492, 1060, 29, 62, "Input",ExpressionUUID->"fd04c708-e7b4-47dd-a32f-6c34d097fe08"], Cell[18991, 523, 1092, 31, 62, "Input",ExpressionUUID->"2cbf2a53-171c-4546-a591-ed9b016d0da5"], Cell[20086, 556, 224, 3, 36, "Input",ExpressionUUID->"fdf96141-746d-4269-953e-ddea30d52f94"], Cell[20313, 561, 462, 12, 36, "Input",ExpressionUUID->"efc0e317-1f06-46b9-b50e-61de1d936197"], Cell[20778, 575, 468, 12, 36, "Input",ExpressionUUID->"2165f8a3-c941-4661-bb39-dab73fc9aaa6"], Cell[21249, 589, 613, 14, 36, "Input",ExpressionUUID->"715c17c3-e737-4e08-8943-5e80f8aaf2a4"], Cell[21865, 605, 570, 14, 36, "Input",ExpressionUUID->"4f654850-7c29-4459-a5f4-30ca43be1979"], Cell[CellGroupData[{ Cell[22460, 623, 909, 23, 36, "Input",ExpressionUUID->"c4ceb40a-f9ec-4cff-9670-b7a778b0b697"], Cell[23372, 648, 1623, 58, 67, "Output",ExpressionUUID->"39e8dca0-28d6-4674-8a38-87d4f1a225aa"] }, Open ]], Cell[25010, 709, 749, 19, 36, "Input",ExpressionUUID->"78f600e6-1cbf-4c87-8eea-2be2a471d10a"] }, Open ]], Cell[CellGroupData[{ Cell[25796, 733, 157, 3, 86, "Section",ExpressionUUID->"85a1c3ed-3996-43f0-b80e-f6fae54051b6"], Cell[25956, 738, 1065, 25, 75, "Text",ExpressionUUID->"25d66400-7711-4ea5-959a-ca3dbb410b3d"], Cell[27024, 765, 1326, 44, 87, "Input",ExpressionUUID->"18740fb8-91ec-4246-abd8-7551a715286b"] }, Open ]] }, Open ]] } ] *)