(* 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[ 5640, 164] NotebookOptionsPosition[ 5142, 142] NotebookOutlinePosition[ 5480, 157] CellTagsIndexPosition[ 5437, 154] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["M\[EAcute]todo de Newton", "Subsection", CellChangeTimes->{{3.528101081959917*^9, 3.528101090933237*^9}}], Cell["\<\ Implementa\[CCedilla]\[ATilde]o do m\[EAcute]todo de Newton para equa\ \[CCedilla]\[OTilde]es do tipo f (x) = 0. A converg\[EHat]ncia do \ m\[EAcute]todo \[EAcute] condicional mas , quando converge, \[EAcute] \ normalmente um m\[EAcute]todo de segunda ordem. Par\[AHat]metros de entrada: * f, x : Fun\[CCedilla]\[ATilde]o f e sua varia\[AAcute]vel * x0 : Aproxima\[CCedilla]\[ATilde]o inicial * tol : Erro m\[AAcute]ximo desejado, medido com base na diferen\[CCedilla]a \ entre iteradas. * nmax : N\[UAcute]mero m\[AAcute]ximo de itera\[CCedilla]\[OTilde]es a \ realizar Par\[AHat]metros de sa\[IAcute]da: * valor num\[EAcute]rico da solu\[CCedilla]\[ATilde]o, correspondente \ \[AGrave] \[UAcute]ltima itera\[CCedilla]\[ATilde]o realizada. Se o \ n\[UAcute]mero m\[AAcute]ximo de itera\[CCedilla]\[OTilde]es for atingido \ \[EAcute] emitida uma mensagem de erro. \ \>", "Text", CellChangeTimes->{{3.528101098718102*^9, 3.528101326053837*^9}, 3.528101399790421*^9}], Cell[BoxData[ RowBox[{"\[IndentingNewLine]", RowBox[{ RowBox[{"Newton", "[", RowBox[{"fs_", ",", "x_", ",", "x0_", ",", "tol_", ",", "nmax_"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"f", ",", "s", ",", "sol", ",", "oldsol", ",", "iter"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"f", "[", "s_", "]"}], ":=", RowBox[{"fs", "/.", RowBox[{"x", "\[Rule]", "s"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"sol", " ", "=", " ", "x0"}], ";", "\[IndentingNewLine]", RowBox[{"oldsol", " ", "=", " ", RowBox[{"x0", "+", RowBox[{"2", "*", "tol"}]}]}], ";", " ", RowBox[{"(*", " ", RowBox[{ "para", " ", "assegurar", " ", "a", " ", "entrada", " ", "no", " ", "ciclo"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"iter", " ", "=", " ", "0"}], ";", "\[IndentingNewLine]", RowBox[{"While", "[", RowBox[{ RowBox[{"And", "[", RowBox[{ RowBox[{"iter", "\[LessEqual]", "nmax"}], ",", " ", RowBox[{ RowBox[{"Abs", "[", RowBox[{"sol", "-", "oldsol"}], "]"}], ">", "tol"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"oldsol", " ", "=", " ", "sol"}], ";", "\[IndentingNewLine]", RowBox[{"sol", " ", "=", " ", RowBox[{"sol", "-", RowBox[{ RowBox[{"f", "[", "sol", "]"}], "/", RowBox[{ RowBox[{"f", "'"}], "[", "sol", "]"}]}]}]}], ";", "\[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.5281013290021057`*^9, 3.528101576664452*^9}, { 3.528101617206092*^9, 3.528101643871674*^9}, {3.528102376937668*^9, 3.5281023880123453`*^9}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"Newton", "[", RowBox[{ RowBox[{ RowBox[{"Cos", "[", RowBox[{"x", "^", "2"}], "]"}], "-", "x"}], ",", "x", ",", "0.5", ",", RowBox[{"10", "^", RowBox[{"(", RowBox[{"-", "12"}], ")"}]}], ",", "100"}], "]"}]], "Input", CellChangeTimes->{{3.528101581440012*^9, 3.528101608532662*^9}, { 3.528101666445722*^9, 3.5281016757655907`*^9}}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"Foram realizadas \"\>", "\[InvisibleSpace]", "6", "\[InvisibleSpace]", "\<\" itera\[CCedilla]\[OTilde]es\"\>"}], SequenceForm["Foram realizadas ", 6, " itera\[CCedilla]\[OTilde]es"], Editable->False]], "Print", CellChangeTimes->{{3.5281016470360727`*^9, 3.528101676210898*^9}}], Cell[BoxData["0.8010707652092184`"], "Output", CellChangeTimes->{ 3.528101609830955*^9, {3.528101647045341*^9, 3.528101676217815*^9}}] }, Open ]] }, Open ]] }, WindowSize->{740, 599}, WindowMargins->{{216, Automatic}, {37, 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, 112, 1, 39, "Subsection"], Cell[694, 25, 987, 24, 296, "Text"], Cell[1684, 51, 2540, 61, 354, "Input"], Cell[CellGroupData[{ Cell[4249, 116, 387, 10, 30, "Input"], Cell[4639, 128, 335, 6, 23, "Print"], Cell[4977, 136, 137, 2, 30, "Output"] }, Open ]] }, Open ]] } ] *) (* End of internal cache information *)