(* 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[ 12090, 387] NotebookOptionsPosition[ 10718, 335] NotebookOutlinePosition[ 11144, 352] CellTagsIndexPosition[ 11101, 349] WindowFrame->Normal ContainsDynamic->False*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["\<\ Math 481A California State University, Northridge Steffensen-Aitken Method\ \>", "Section"], Cell["\[Copyright]2007 BE Shapiro", "Subsection", CellChangeTimes->{{3.398601344393422*^9, 3.398601344518352*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["Implementation of Steffensen's Method", "Section"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"Steffensen", "[", RowBox[{"g_", ",", " ", "p0input_", ",", " ", RowBox[{"\[Epsilon]_:", ".001"}], ",", " ", RowBox[{"Nmax_:", "100"}]}], "]"}], ":=", " ", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"\[CapitalDelta]", ",", RowBox[{"i", "=", "0"}], ",", RowBox[{"\[Delta]", "=", "\[Infinity]"}], ",", "x", ",", "u"}], "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"\[CapitalDelta]", "[", RowBox[{"p_", ",", "q_", ",", "r_"}], "]"}], ":=", " ", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"\[CapitalDelta]p", ",", "\[CapitalDelta]2p"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"\[CapitalDelta]p", "=", RowBox[{"q", "-", "p"}]}], ";", "\[IndentingNewLine]", RowBox[{"\[CapitalDelta]2p", "=", RowBox[{"r", "-", RowBox[{"2", "q"}], "+", "p"}]}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"\[CapitalDelta]2p", "\[NotEqual]", " ", "0"}], ",", "\[IndentingNewLine]", RowBox[{"Return", "[", RowBox[{"p", "-", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"(", "\[CapitalDelta]p", ")"}], "^", "2"}], ")"}], " ", "/", "\[CapitalDelta]2p"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Return", "[", "p", "]"}]}], "\[IndentingNewLine]", "]"}], ";"}]}], "\[IndentingNewLine]", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"x", "=", RowBox[{"p0", "=", "p0input"}]}], ";", "\[IndentingNewLine]", RowBox[{"While", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"(", RowBox[{"\[Delta]", ">", "\[Epsilon]"}], ")"}], "\[And]", " ", RowBox[{"(", RowBox[{ RowBox[{"i", "++"}], "\[LessEqual]", "Nmax"}], ")"}]}], ")"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"p1", "=", " ", RowBox[{ RowBox[{"g", "[", "u", "]"}], "/.", RowBox[{"{", RowBox[{"u", "\[Rule]", " ", "x"}], "}"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"p2", "=", RowBox[{ RowBox[{"g", "[", "u", "]"}], "/.", RowBox[{"{", RowBox[{"u", "\[Rule]", " ", "p1"}], "}"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"x", "=", RowBox[{"\[CapitalDelta]", "[", RowBox[{"p0", ",", "p1", ",", "p2"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\<{i,p0,p1,p2}=\>\"", ",", RowBox[{"{", RowBox[{"i", ",", "p0", ",", "p1", ",", "p2"}], "}"}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"\[Delta]", "=", RowBox[{"Abs", "[", RowBox[{"x", "-", "p0"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"p0", "=", "x"}], ";"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"i", "\[GreaterEqual]", "Nmax"}], ",", " ", RowBox[{ "Print", "[", "\"\\"", "]"}]}], "]"}], ";", " ", "\[IndentingNewLine]", RowBox[{"Return", "[", "x", "]"}], ";"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["\<\ Application of Steffensen's method to Newton's Fixed Point iteration formula:\ \ \>", "Section"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"NewtonSteffensen", "[", RowBox[{"f_", ",", " ", "p0_", ",", " ", RowBox[{"\[Epsilon]_:", "0.001"}], ",", " ", RowBox[{"Nmax_:", "100"}]}], "]"}], ":=", " ", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"g", ",", "p"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"g", "[", "z_", "]"}], ":=", " ", RowBox[{"z", "-", RowBox[{ RowBox[{"f", "[", "z", "]"}], "/", RowBox[{ RowBox[{"f", "'"}], "[", "z", "]"}]}]}]}], ";", "\[IndentingNewLine]", RowBox[{"p", "=", RowBox[{"Steffensen", "[", RowBox[{"g", ",", "p0", ",", "\[Epsilon]", ",", "Nmax"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"Return", "[", "p", "]"}], ";"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "Fine the root of ", Cell[BoxData[ FormBox[ SuperscriptBox[ RowBox[{"(", RowBox[{"x", "-", "2"}], ")"}], "2"], TraditionalForm]]] }], "Section", CellChangeTimes->{{3.398601306946319*^9, 3.3986013084960546`*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"f", "[", "x_", "]"}], ":=", " ", RowBox[{ RowBox[{"(", RowBox[{"x", "-", "2"}], ")"}], "^", "2"}]}]], "Input"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"NewtonSteffensen", "[", RowBox[{"f", ",", "1."}], "]"}]], "Input"], Cell[CellGroupData[{ Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"{i,p0,p1,p2}=\"\>", "\[InvisibleSpace]", RowBox[{"{", RowBox[{"1", ",", "1.`", ",", "1.5`", ",", "1.4166666666666667`"}], "}"}]}], SequenceForm["{i,p0,p1,p2}=", {1, 1., 1.5, 1.4166666666666667`}], Editable->False]], "Print", CellChangeTimes->{3.398601310950337*^9}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"{i,p0,p1,p2}=\"\>", "\[InvisibleSpace]", RowBox[{"{", RowBox[{ "2", ",", "1.4285714285714286`", ",", "1.4142857142857144`", ",", "1.4142135642135643`"}], "}"}]}], SequenceForm[ "{i,p0,p1,p2}=", { 2, 1.4285714285714286`, 1.4142857142857144`, 1.4142135642135643`}], Editable->False]], "Print", CellChangeTimes->{3.398601310953908*^9}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"{i,p0,p1,p2}=\"\>", "\[InvisibleSpace]", RowBox[{"{", RowBox[{ "3", ",", "1.4142131979695431`", ",", "1.414213562373142`", ",", "1.4142135623730951`"}], "}"}]}], SequenceForm[ "{i,p0,p1,p2}=", { 3, 1.4142131979695431`, 1.414213562373142, 1.4142135623730951`}], Editable->False]], "Print", CellChangeTimes->{3.398601310957745*^9}] }, Open ]], Cell[BoxData["1.4142135623730951`"], "Output", CellChangeTimes->{3.398601310960881*^9}] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "Newton's method takes 9 iterations to solve the roots of ", Cell[BoxData[ FormBox[ SuperscriptBox[ RowBox[{"(", RowBox[{"x", "-", "2"}], ")"}], "2"], TraditionalForm]]] }], "Section"], Cell[BoxData[ RowBox[{ RowBox[{"NewtonsMethod", "[", RowBox[{"f_", ",", " ", "p0_", ",", RowBox[{"\[Epsilon]_:", "0.001"}], ",", RowBox[{"Nmax_:", "10"}]}], "]"}], ":=", "\[IndentingNewLine]", " ", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"\[Delta]", ",", " ", "\[CapitalDelta]", ",", "i", ",", "p"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"\[CapitalDelta]", "[", "x_", "]"}], ":=", RowBox[{ RowBox[{"f", "[", "x", "]"}], "/", RowBox[{ RowBox[{"f", "'"}], "[", "x", "]"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"p", "=", "p0"}], ";", " ", RowBox[{"\[Delta]", "=", RowBox[{"\[CapitalDelta]", "[", "p", "]"}]}], ";", " ", RowBox[{"i", "=", "0"}], ";", "\[IndentingNewLine]", RowBox[{"While", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"Abs", "[", "\[Delta]", "]"}], ">", "\[Epsilon]"}], " ", "\[And]", " ", RowBox[{"(", RowBox[{ RowBox[{"i", "++"}], "<", "Nmax"}], ")"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"p", "=", RowBox[{"p", "-", "\[Delta]"}]}], ";", "\[IndentingNewLine]", RowBox[{"\[Delta]", "=", RowBox[{"\[CapitalDelta]", "[", "p", "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{ "\"\\"", ",", "i", ",", " ", "\"\< p=\>\"", ",", "p"}], "]"}], ";"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"Return", "[", RowBox[{"{", RowBox[{"i", ",", "p"}], "}"}], "]"}], ";"}]}], " ", "\[IndentingNewLine]", "]"}]}]], "Input"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"NewtonsMethod", "[", RowBox[{"f", ",", "1."}], "]"}]], "Input"], Cell[CellGroupData[{ Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"iteration:\"\>", "\[InvisibleSpace]", "1", "\[InvisibleSpace]", "\<\" p=\"\>", "\[InvisibleSpace]", "1.5`"}], SequenceForm["iteration:", 1, " p=", 1.5], Editable->False]], "Print", CellChangeTimes->{3.39860133027931*^9}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"iteration:\"\>", "\[InvisibleSpace]", "2", "\[InvisibleSpace]", "\<\" p=\"\>", "\[InvisibleSpace]", "1.4166666666666667`"}], SequenceForm["iteration:", 2, " p=", 1.4166666666666667`], Editable->False]], "Print", CellChangeTimes->{3.3986013302811737`*^9}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"iteration:\"\>", "\[InvisibleSpace]", "3", "\[InvisibleSpace]", "\<\" p=\"\>", "\[InvisibleSpace]", "1.4142156862745099`"}], SequenceForm["iteration:", 3, " p=", 1.4142156862745099`], Editable->False]], "Print", CellChangeTimes->{3.398601330287828*^9}] }, Open ]], Cell[BoxData[ RowBox[{"{", RowBox[{"3", ",", "1.4142156862745099`"}], "}"}]], "Output", CellChangeTimes->{{3.398601317484363*^9, 3.398601330289516*^9}}] }, Open ]] }, Open ]] }, WindowSize->{1122, 1017}, WindowMargins->{{Automatic, 247}, {0, Automatic}}, Magnification->1, FrontEndVersion->"6.0 for Mac OS X x86 (32-bit) (June 19, 2007)", StyleDefinitions->FrontEnd`FileName[{"Creative"}, "PastelColor.nb", CharacterEncoding -> "UTF-8"] ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[590, 23, 101, 4, 112, "Section"], Cell[694, 29, 115, 1, 34, "Subsection"] }, Open ]], Cell[CellGroupData[{ Cell[846, 35, 56, 0, 72, "Section"], Cell[905, 37, 3662, 90, 383, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[4604, 132, 106, 3, 72, "Section"], Cell[4713, 137, 896, 25, 98, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[5646, 167, 245, 8, 77, "Section"], Cell[5894, 177, 156, 5, 37, "Input"], Cell[CellGroupData[{ Cell[6075, 186, 93, 2, 37, "Input"], Cell[CellGroupData[{ Cell[6193, 192, 333, 8, 20, "Print"], Cell[6529, 202, 410, 11, 20, "Print"], Cell[6942, 215, 407, 11, 20, "Print"] }, Open ]], Cell[7364, 229, 88, 1, 37, "Output"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[7501, 236, 217, 7, 77, "Section"], Cell[7721, 245, 1743, 46, 188, "Input"], Cell[CellGroupData[{ Cell[9489, 295, 90, 2, 37, "Input"], Cell[CellGroupData[{ Cell[9604, 301, 278, 6, 20, "Print"], Cell[9885, 309, 316, 7, 20, "Print"], Cell[10204, 318, 314, 7, 20, "Print"] }, Open ]], Cell[10533, 328, 157, 3, 37, "Output"] }, Open ]] }, Open ]] } ] *) (* End of internal cache information *)