(* 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[ 8120, 259] NotebookOptionsPosition[ 7132, 222] NotebookOutlinePosition[ 7539, 238] CellTagsIndexPosition[ 7496, 235] WindowFrame->Normal ContainsDynamic->False*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["\<\ Math 481A California State University, Northridge Secant Method Method\ \>", "Section"], Cell["\[Copyright]2007 BE Shapiro", "Subsection", CellChangeTimes->{3.398601269886832*^9}] }, Open ]], Cell[CellGroupData[{ Cell["Secant Method Algorithm", "Section"], Cell[BoxData[ RowBox[{ RowBox[{"SecantMethod", "[", RowBox[{"f_", ",", " ", "x0_", ",", "x1_", ",", " ", RowBox[{"\[Epsilon]_:", "0.001"}], ",", RowBox[{"Nmax_:", "10"}]}], "]"}], ":=", "\[IndentingNewLine]", " ", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ "\[Delta]", ",", "i", ",", "p0", ",", " ", "p1", ",", " ", "q0", ",", "q1"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"p0", "=", "x0"}], ";", RowBox[{"p1", "=", "x1"}], ";", " ", "\[IndentingNewLine]", RowBox[{"q0", "=", RowBox[{"f", "[", "p0", "]"}]}], ";", " ", RowBox[{"q1", "=", RowBox[{"f", "[", "p1", "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"\[Delta]", "=", RowBox[{"q1", "*", RowBox[{ RowBox[{"(", RowBox[{"p1", "-", "p0"}], ")"}], "/", RowBox[{"(", RowBox[{"q1", "-", "q0"}], ")"}]}]}]}], ";", " ", "\[IndentingNewLine]", RowBox[{"i", "=", "0"}], ";", "\[IndentingNewLine]", RowBox[{"While", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"Abs", "[", "\[Delta]", "]"}], ">", "\[Epsilon]"}], " ", "\[And]", " ", RowBox[{"(", RowBox[{ RowBox[{"i", "++"}], "<", "Nmax"}], ")"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"p0", "=", "p1"}], ";", " ", "\[IndentingNewLine]", RowBox[{"p1", "=", RowBox[{"p1", "-", "\[Delta]"}]}], ";", "\[IndentingNewLine]", RowBox[{"q0", "=", "q1"}], ";", " ", RowBox[{"q1", "=", RowBox[{"f", "[", "p1", "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"\[Delta]", "=", RowBox[{"q1", "*", RowBox[{ RowBox[{"(", RowBox[{"p1", "-", "p0"}], ")"}], "/", RowBox[{"(", RowBox[{"q1", "-", "q0"}], ")"}]}]}]}], ";", " ", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{ "\"\\"", ",", "i", ",", " ", "\"\< p=\>\"", ",", "p1"}], "]"}], ";"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"Return", "[", RowBox[{"{", RowBox[{"i", ",", "p1"}], "}"}], "]"}], ";"}]}], " ", "\[IndentingNewLine]", "]"}]}]], "Input"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "Use the Secant Method to find ", Cell[BoxData[ FormBox[ SqrtBox["2"], TraditionalForm]]], " to 50 significant figues" }], "Section"], Cell[CellGroupData[{ Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"f", "[", "x_", "]"}], ":=", RowBox[{ RowBox[{"x", "^", "2"}], "-", "2"}]}], ";"}], "\[IndentingNewLine]", RowBox[{"SecantMethod", "[", RowBox[{"f", ",", "1.4`53", ",", "1.5`53", ",", RowBox[{"10", "^", RowBox[{"-", "50"}]}], ",", "25"}], "]"}]}], "Input"], Cell[CellGroupData[{ Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"iteration:\"\>", "\[InvisibleSpace]", "1", "\[InvisibleSpace]", "\<\" p=\"\>", "\[InvisibleSpace]", "1.4137931034482758620689655172413793103448275862068965517241379310345`52.\ 24433666231008"}], SequenceForm[ "iteration:", 1, " p=", 1.41379310344827586206896551724137931034482758620689655`52.24433666231008], Editable->False]], "Print", CellChangeTimes->{3.3986012798699102`*^9}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"iteration:\"\>", "\[InvisibleSpace]", "2", "\[InvisibleSpace]", "\<\" p=\"\>", "\[InvisibleSpace]", "1.4142011834319526627218934911242603550295857988165680473372781065089`51.\ 947461176916136"}], SequenceForm[ "iteration:", 2, " p=", 1.414201183431952662721893491124260355029585798816568`51.947461176916136], Editable->False]], "Print", CellChangeTimes->{3.3986012798723497`*^9}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"iteration:\"\>", "\[InvisibleSpace]", "3", "\[InvisibleSpace]", "\<\" p=\"\>", "\[InvisibleSpace]", "1.4142135642135642135642135642135642135642135642135642135642135642131`51.\ 62701820565441"}], SequenceForm[ "iteration:", 3, " p=", 1.4142135642135642135642135642135642135642135642135642`51.62701820565441], Editable->False]], "Print", CellChangeTimes->{3.3986012798750477`*^9}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"iteration:\"\>", "\[InvisibleSpace]", "4", "\[InvisibleSpace]", "\<\" p=\"\>", "\[InvisibleSpace]", "1.4142135623730869937385181134378317398249598610377580202831379830882`51.\ 3258918402446"}], SequenceForm[ "iteration:", 4, " p=", 1.414213562373086993738518113437831739824959861037758`51.3258918402446], Editable->False]], "Print", CellChangeTimes->{3.398601279876511*^9}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"iteration:\"\>", "\[InvisibleSpace]", "5", "\[InvisibleSpace]", "\<\" p=\"\>", "\[InvisibleSpace]", "1.414213562373095048801683482746961997996535881398641392753444865966`51.\ 02485899383148"}], SequenceForm[ "iteration:", 5, " p=", 1.414213562373095048801683482746961997996535881398641`51.02485899383148], Editable->False]], "Print", CellChangeTimes->{3.398601279877964*^9}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"iteration:\"\>", "\[InvisibleSpace]", "6", "\[InvisibleSpace]", "\<\" p=\"\>", "\[InvisibleSpace]", "1.4142135623730950488016887242096980785845990103475265241618209448146`50.\ 7238289977436"}], SequenceForm[ "iteration:", 6, " p=", 1.414213562373095048801688724209698078584599010347527`50.7238289977436], Editable->False]], "Print", CellChangeTimes->{3.398601279879377*^9}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"iteration:\"\>", "\[InvisibleSpace]", "7", "\[InvisibleSpace]", "\<\" p=\"\>", "\[InvisibleSpace]", "1.4142135623730950488016887242096980785696718753769480731766797103287`50.\ 42279900207962"}], SequenceForm[ "iteration:", 7, " p=", 1.414213562373095048801688724209698078569671875376948`50.42279900207962], Editable->False]], "Print", CellChangeTimes->{3.398601279880653*^9}] }, Open ]], Cell[BoxData[ RowBox[{"{", RowBox[{ "7", ",", "1.4142135623730950488016887242096980785696718753769480731766797103287`50.\ 42279900207962"}], "}"}]], "Output", CellChangeTimes->{3.398601279881894*^9}] }, Open ]] }, Open ]] }, WindowSize->{811, 700}, WindowMargins->{{Automatic, 273}, {Automatic, 96}}, 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, 98, 4, 112, "Section"], Cell[691, 29, 91, 1, 34, "Subsection"] }, Open ]], Cell[CellGroupData[{ Cell[819, 35, 42, 0, 72, "Section"], Cell[864, 37, 2318, 61, 248, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[3219, 103, 157, 6, 80, "Section"], Cell[CellGroupData[{ Cell[3401, 113, 325, 9, 53, "Input"], Cell[CellGroupData[{ Cell[3751, 126, 450, 11, 20, "Print"], Cell[4204, 139, 447, 10, 20, "Print"], Cell[4654, 151, 446, 10, 20, "Print"], Cell[5103, 163, 441, 10, 20, "Print"], Cell[5547, 175, 442, 10, 20, "Print"], Cell[5992, 187, 441, 10, 20, "Print"], Cell[6436, 199, 443, 10, 20, "Print"] }, Open ]], Cell[6894, 212, 210, 6, 37, "Output"] }, Open ]] }, Open ]] } ] *) (* End of internal cache information *)