(* 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[ 8962, 256] NotebookOptionsPosition[ 8385, 231] NotebookOutlinePosition[ 8722, 246] CellTagsIndexPosition[ 8679, 243] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["\<\ M\[EAcute]todo de Newton para Sistemas de Equa\[CCedilla]\[OTilde]es n\ \[ATilde]o Lineares\ \>", "Subsection", CellChangeTimes->{{3.528103633966742*^9, 3.528103670012824*^9}}], Cell["\<\ Implementa\[CCedilla]\[ATilde]o do m\[EAcute]todo de Newton em Rn, para \ resolu\[CCedilla]\[ATilde]o de sistemas de equa\[CCedilla]\[OTilde]es n\ \[ATilde]o lineares da forma F(X) = 0, em que X = (x_ 1, ... , x_n) e F = (f_ \ 1, ... , f_n). A converg\[EHat]ncia do m\[EAcute]todo \[EAcute] condicional e \ tipicamente de ordem 2. Par\[AHat]metros de entrada : * F, X : a fun\[CCedilla]\[ATilde]o vectorial F e o seu argumento X * X0 : vector que d\[AAcute] a aproxima\[CCedilla]\[ATilde]o inicial * tol : erro maximo desejado, medido com base da dist\[AHat]ncia entre \ as duas \[UAcute]ltimas iteradas. * nmax : n\[UAcute]mero m\[AAcute]ximo de itera\[CCedilla]\[OTilde]es Par\[AHat]metros de sa\[IAcute]da : * vector num\[EAcute]rico com a solu\[CCedilla]\[ATilde]o do problema, \ correspondendo \[AGrave] \[UAcute]ltima itera\[CCedilla]\[ATilde]o calculada. \ Se o n\[UAcute]mero m\[AAcute]ximo de itera\[CCedilla]\[OTilde]es for \ atingido \[EAcute] emitida mensagem de erro. \ \>", "Text", CellChangeTimes->{{3.5281036240397778`*^9, 3.528103630783663*^9}, { 3.528103676744212*^9, 3.52810372342762*^9}}], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"Newton", "[", RowBox[{"Fs_", ",", "X_", ",", "X0_", ",", " ", "tol_", ",", "nmax_"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ "JF", ",", "DF", ",", "NormaInf", ",", "F", ",", "oldsol", ",", "sol", ",", "iter", ",", "s", ",", "n", ",", "y"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"n", "=", RowBox[{"Length", "[", "X", "]"}]}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"F", "[", "s_", "]"}], ":=", RowBox[{"Fs", "/.", RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{"X", "[", RowBox[{"[", "i", "]"}], "]"}], "\[Rule]", RowBox[{"s", "[", RowBox[{"[", "i", "]"}], "]"}]}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "n"}], "}"}]}], "]"}]}]}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"DF", "[", RowBox[{"s_", ",", "i_", ",", "j_"}], "]"}], ":=", RowBox[{ RowBox[{"D", "[", RowBox[{ RowBox[{"Fs", "[", RowBox[{"[", "i", "]"}], "]"}], ",", RowBox[{"X", "[", RowBox[{"[", "j", "]"}], "]"}]}], "]"}], "/.", RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{"X", "[", RowBox[{"[", "k", "]"}], "]"}], "\[Rule]", RowBox[{"s", "[", RowBox[{"[", "k", "]"}], "]"}]}], ",", RowBox[{"{", RowBox[{"k", ",", "1", ",", "n"}], "}"}]}], "]"}]}]}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"JF", "[", "s_", "]"}], ":=", RowBox[{"Table", "[", RowBox[{ RowBox[{"DF", "[", RowBox[{"s", ",", "i", ",", "j"}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "n"}], "}"}], ",", RowBox[{"{", RowBox[{"j", ",", "1", ",", "n"}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"NormaInf", "[", "s_", "]"}], ":=", RowBox[{"Max", "[", RowBox[{"Abs", "[", "s", "]"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"sol", "=", "X0"}], ";", "\[IndentingNewLine]", RowBox[{"oldsol", " ", "=", " ", RowBox[{"X0", "+", RowBox[{"2", "*", "tol"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"iter", " ", "=", " ", "0"}], ";", "\[IndentingNewLine]", RowBox[{"While", "[", RowBox[{ RowBox[{"And", "[", RowBox[{ RowBox[{"iter", "\[LessEqual]", "nmax"}], ",", RowBox[{ RowBox[{"NormaInf", "[", RowBox[{"sol", "-", "oldsol"}], "]"}], ">", "tol"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"oldsol", "=", "sol"}], ";", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"determinar", " ", "y"}], ",", " ", RowBox[{ RowBox[{"solu\[CCedilla]\[ATilde]o", " ", "de", " ", RowBox[{"JF", ".", "y"}]}], " ", "=", " ", RowBox[{"-", "F"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"y", "=", RowBox[{"LinearSolve", "[", RowBox[{ RowBox[{"JF", "[", "oldsol", "]"}], ",", RowBox[{"-", RowBox[{"F", "[", "oldsol", "]"}]}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"sol", " ", "=", " ", RowBox[{"sol", "+", "y"}]}], ";", "\[IndentingNewLine]", RowBox[{"iter", "++"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{ "\"\\"", ",", "iter", ",", "\"\< itera\[CCedilla]\[OTilde]es\>\""}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"iter", "\[GreaterEqual]", "nmax"}], ",", RowBox[{ "Print", "[", "\"\\"", "]"}]}], "]"}], ";", "\[IndentingNewLine]", "sol"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellChangeTimes->{{3.5281037920078897`*^9, 3.528103963941216*^9}, { 3.528104048621786*^9, 3.528104048701984*^9}, {3.5281040802351217`*^9, 3.5281043948042393`*^9}, {3.52810443993581*^9, 3.528104459128364*^9}, { 3.528104491438592*^9, 3.528104646601981*^9}, {3.528104678003899*^9, 3.528104778714795*^9}, {3.528104825705468*^9, 3.528104829060851*^9}, { 3.5281049680133333`*^9, 3.528104968386464*^9}, {3.528105004122909*^9, 3.528105004429843*^9}}], Cell[CellGroupData[{ Cell["Exemplo :", "Subsubsection", CellChangeTimes->{3.528105033281377*^9}], Cell[CellGroupData[{ Cell[BoxData[{ RowBox[{ RowBox[{"F", "=", RowBox[{"{", RowBox[{ RowBox[{"x", "-", RowBox[{"Cos", "[", RowBox[{"0.5", "*", "y"}], "]"}]}], ",", RowBox[{"y", "-", RowBox[{"Sin", "[", RowBox[{"0.3", "*", "x"}], "]"}]}]}], "}"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"X", "=", RowBox[{"{", RowBox[{"x", ",", "y"}], "}"}]}], ";", " ", RowBox[{"X0", "=", RowBox[{"{", RowBox[{"0", ",", "0"}], "}"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"tol", "=", RowBox[{"10", "^", RowBox[{"(", RowBox[{"-", "12"}], ")"}]}]}], ";", " ", RowBox[{"nmax", "=", "1000"}], ";"}], "\[IndentingNewLine]", RowBox[{"Newton", "[", RowBox[{"F", ",", "X", ",", "X0", ",", "tol", ",", "nmax"}], "]"}]}], "Input", CellChangeTimes->{{3.528103969067273*^9, 3.5281040346347027`*^9}, { 3.528104572419063*^9, 3.528104572618142*^9}, {3.528105017347547*^9, 3.52810503682933*^9}}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"Foram realizadas \"\>", "\[InvisibleSpace]", "5", "\[InvisibleSpace]", "\<\" itera\[CCedilla]\[OTilde]es\"\>"}], SequenceForm["Foram realizadas ", 5, " itera\[CCedilla]\[OTilde]es"], Editable->False]], "Print", CellChangeTimes->{{3.528104849115808*^9, 3.528104853308506*^9}, { 3.528104979682473*^9, 3.5281050078374033`*^9}}], Cell[BoxData[ RowBox[{"{", RowBox[{"0.9893274367854787`", ",", "0.29245993043053214`"}], "}"}]], "Output", CellChangeTimes->{{3.528104849394188*^9, 3.5281048533295317`*^9}, { 3.528104979700087*^9, 3.5281050078446074`*^9}}] }, Open ]] }, Open ]] }, Open ]] }, WindowSize->{795, 599}, WindowMargins->{{Automatic, 265}, {6, Automatic}}, FrontEndVersion->"8.0 for Linux x86 (64-bit) (February 23, 2011)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[579, 22, 187, 4, 39, "Subsection"], Cell[769, 28, 1148, 24, 296, "Text"], Cell[1920, 54, 4698, 117, 411, "Input"], Cell[CellGroupData[{ Cell[6643, 175, 76, 1, 28, "Subsubsection"], Cell[CellGroupData[{ Cell[6744, 180, 979, 30, 88, "Input"], Cell[7726, 212, 384, 7, 23, "Print"], Cell[8113, 221, 232, 5, 30, "Output"] }, Open ]] }, Open ]] }, Open ]] } ] *) (* End of internal cache information *)