(* 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[ 14127, 413] NotebookOptionsPosition[ 12608, 362] NotebookOutlinePosition[ 13014, 378] CellTagsIndexPosition[ 12971, 375] WindowFrame->Normal ContainsDynamic->False*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["\<\ Math 481A California State University, Northridge Method of Regula Falsi\ \>", "Section"], Cell["\[Copyright]2007 BE Shapiro", "Subsection", CellChangeTimes->{3.3986012429750834`*^9}] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "Implementation of ", StyleBox["Regula Falsi", FontSlant->"Italic"], " algorithm" }], "Section"], Cell[BoxData[ RowBox[{ RowBox[{"RegulaFalsiMethod", "[", RowBox[{"f_", ",", " ", "x0_", ",", "x1_", ",", " ", RowBox[{"\[Epsilon]_:", "0.001"}], ",", RowBox[{"Nmax_:", "10"}]}], "]"}], ":=", "\[IndentingNewLine]", " ", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ "\[Delta]", ",", "i", ",", "p0", ",", " ", "p1", ",", " ", "q0", ",", "q1", ",", " ", "p"}], "}"}], ",", "\[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", "=", "1"}], ";", "\[IndentingNewLine]", RowBox[{"While", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"Abs", "[", "\[Delta]", "]"}], ">", "\[Epsilon]"}], " ", "\[And]", " ", RowBox[{"(", RowBox[{ RowBox[{"i", "++"}], "<", "Nmax"}], ")"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"p", "=", RowBox[{"p1", "-", "\[Delta]"}]}], ";", "\[IndentingNewLine]", RowBox[{"q", "=", RowBox[{"f", "[", "p", "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"Sign", "[", "q", "]"}], RowBox[{"Sign", "[", "q1", "]"}]}], " ", "<", "0"}], ",", " ", RowBox[{ RowBox[{"p0", "=", "p1"}], ";", RowBox[{"q0", "=", "q1"}], ";"}]}], "]"}], ";", " ", "\[IndentingNewLine]", RowBox[{"p1", "=", "p"}], ";", "\[IndentingNewLine]", RowBox[{"q1", "=", "q"}], ";", "\[IndentingNewLine]", RowBox[{"\[Delta]", "=", RowBox[{"q1", "*", RowBox[{ RowBox[{"(", RowBox[{"p1", "-", "p0"}], ")"}], "/", RowBox[{"(", RowBox[{"q1", "-", "q0"}], ")"}]}]}]}], ";", " ", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{ "\"\\"", ",", "i", ",", " ", "\"\< p \>\"", ",", "p"}], "]"}], ";"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"Return", "[", RowBox[{"{", RowBox[{"i", ",", "p"}], "}"}], "]"}], ";"}]}], " ", "\[IndentingNewLine]", "]"}]}]], "Input"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "Use ", StyleBox["Regula Falsi", FontSlant->"Italic"], " to find square root of 2 to 25 significant figures" }], "Section"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"f", "[", "x_", "]"}], ":=", RowBox[{ RowBox[{"x", "^", "2"}], "-", "2"}]}], ";", RowBox[{"RegulaFalsiMethod", "[", RowBox[{"f", ",", "1.`25", ",", "2.`25", ",", " ", RowBox[{"10", "^", RowBox[{"-", "25"}]}], ",", "50"}], "]"}], ";"}]], "Input"], Cell[CellGroupData[{ Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"iteration:\"\>", "\[InvisibleSpace]", "2", "\[InvisibleSpace]", "\<\" p \"\>", "\[InvisibleSpace]", "1.33333333333333333333333333333333333334`24.17609125905568"}], SequenceForm[ "iteration:", 2, " p ", 1.3333333333333333333333333`24.17609125905568], Editable->False]], "Print", CellChangeTimes->{3.398601252504376*^9}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"iteration:\"\>", "\[InvisibleSpace]", "3", "\[InvisibleSpace]", "\<\" p \"\>", "\[InvisibleSpace]", "1.4`23.889891502472313"}], SequenceForm["iteration:", 3, " p ", 1.4`23.889891502472313], Editable->False]], "Print", CellChangeTimes->{3.3986012525067663`*^9}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"iteration:\"\>", "\[InvisibleSpace]", "4", "\[InvisibleSpace]", "\<\" p \"\>", "\[InvisibleSpace]", "1.41176470588235294117647058823529411765`23.623076118070127"}], SequenceForm[ "iteration:", 4, " p ", 1.411764705882352941176471`23.623076118070127], Editable->False]], "Print", CellChangeTimes->{3.3986012525093727`*^9}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"iteration:\"\>", "\[InvisibleSpace]", "5", "\[InvisibleSpace]", "\<\" p \"\>", "\[InvisibleSpace]", "1.41379310344827586206896551724137931035`23.360221295084084"}], SequenceForm[ "iteration:", 5, " p ", 1.413793103448275862068966`23.360221295084084], Editable->False]], "Print", CellChangeTimes->{3.398601252510764*^9}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"iteration:\"\>", "\[InvisibleSpace]", "6", "\[InvisibleSpace]", "\<\" p \"\>", "\[InvisibleSpace]", "1.41414141414141414141414141414141414141`23.098016993293047"}], SequenceForm[ "iteration:", 6, " p ", 1.41414141414141414141414`23.098016993293047], Editable->False]], "Print", CellChangeTimes->{3.398601252512182*^9}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"iteration:\"\>", "\[InvisibleSpace]", "7", "\[InvisibleSpace]", "\<\" p \"\>", "\[InvisibleSpace]", "1.41420118343195266272189349112426035503`22.835918336693297"}], SequenceForm[ "iteration:", 7, " p ", 1.41420118343195266272189`22.835918336693297], Editable->False]], "Print", CellChangeTimes->{3.3986012525135803`*^9}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"iteration:\"\>", "\[InvisibleSpace]", "8", "\[InvisibleSpace]", "\<\" p \"\>", "\[InvisibleSpace]", "1.41421143847487001733102253032928942808`22.573837149231313"}], SequenceForm[ "iteration:", 8, " p ", 1.41421143847487001733102`22.573837149231313], Editable->False]], "Print", CellChangeTimes->{3.398601252514946*^9}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"iteration:\"\>", "\[InvisibleSpace]", "9", "\[InvisibleSpace]", "\<\" p \"\>", "\[InvisibleSpace]", "1.41421319796954314720812182741116751269`22.311758894565138"}], SequenceForm[ "iteration:", 9, " p ", 1.41421319796954314720812`22.311758894565138], Editable->False]], "Print", CellChangeTimes->{3.398601252516211*^9}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"iteration:\"\>", "\[InvisibleSpace]", "10", "\[InvisibleSpace]", "\<\" p \"\>", "\[InvisibleSpace]", "1.41421349985132322331251858459708593518`22.04968113695911"}], SequenceForm[ "iteration:", 10, " p ", 1.4142134998513232233125`22.04968113695911], Editable->False]], "Print", CellChangeTimes->{3.398601252517406*^9}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"iteration:\"\>", "\[InvisibleSpace]", "11", "\[InvisibleSpace]", "\<\" p \"\>", "\[InvisibleSpace]", "1.41421355164605469430412820066190559136`21.787603464057682"}], SequenceForm[ "iteration:", 11, " p ", 1.4142135516460546943041`21.787603464057682], Editable->False]], "Print", CellChangeTimes->{3.398601252518556*^9}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"iteration:\"\>", "\[InvisibleSpace]", "12", "\[InvisibleSpace]", "\<\" p \"\>", "\[InvisibleSpace]", "1.41421356053262588643436559359216366512`21.525525805635013"}], SequenceForm[ "iteration:", 12, " p ", 1.4142135605326258864344`21.525525805635013], Editable->False]], "Print", CellChangeTimes->{3.3986012525196743`*^9}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"iteration:\"\>", "\[InvisibleSpace]", "13", "\[InvisibleSpace]", "\<\" p \"\>", "\[InvisibleSpace]", "1.41421356205732046262813424583843877947`21.263448149691424"}], SequenceForm[ "iteration:", 13, " p ", 1.4142135620573204626281`21.263448149691424], Editable->False]], "Print", CellChangeTimes->{3.398601252520726*^9}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"iteration:\"\>", "\[InvisibleSpace]", "14", "\[InvisibleSpace]", "\<\" p \"\>", "\[InvisibleSpace]", "1.41421356231891669511479915618462400322`21.001370494172694"}], SequenceForm[ "iteration:", 14, " p ", 1.414213562318916695115`21.001370494172694], Editable->False]], "Print", CellChangeTimes->{3.398601252521783*^9}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"iteration:\"\>", "\[InvisibleSpace]", "15", "\[InvisibleSpace]", "\<\" p \"\>", "\[InvisibleSpace]", "1.4142135623637995128829637225996667094`20.739292838726815"}], SequenceForm[ "iteration:", 15, " p ", 1.414213562363799512883`20.739292838726815], Editable->False]], "Print", CellChangeTimes->{3.398601252522963*^9}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"iteration:\"\>", "\[InvisibleSpace]", "16", "\[InvisibleSpace]", "\<\" p \"\>", "\[InvisibleSpace]", "1.41421356237150018697708366811492557711`20.47721518329343"}], SequenceForm[ "iteration:", 16, " p ", 1.414213562371500186977`20.47721518329343], Editable->False]], "Print", CellChangeTimes->{3.3986012525240498`*^9}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"iteration:\"\>", "\[InvisibleSpace]", "17", "\[InvisibleSpace]", "\<\" p \"\>", "\[InvisibleSpace]", "1.41421356237282141377280856945039496291`20.215137527862186"}], SequenceForm[ "iteration:", 17, " p ", 1.414213562372821413773`20.215137527862186], Editable->False]], "Print", CellChangeTimes->{3.3986012525251007`*^9}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"iteration:\"\>", "\[InvisibleSpace]", "18", "\[InvisibleSpace]", "\<\" p \"\>", "\[InvisibleSpace]", "1.41421356237304810045301359298451209372`19.95305987243131"}], SequenceForm[ "iteration:", 18, " p ", 1.41421356237304810045`19.95305987243131], Editable->False]], "Print", CellChangeTimes->{3.398601252526185*^9}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"iteration:\"\>", "\[InvisibleSpace]", "19", "\[InvisibleSpace]", "\<\" p \"\>", "\[InvisibleSpace]", "1.41421356237308699373851811343783173983`19.6909822170005"}], SequenceForm[ "iteration:", 19, " p ", 1.41421356237308699374`19.6909822170005], Editable->False]], "Print", CellChangeTimes->{3.398601252527245*^9}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"iteration:\"\>", "\[InvisibleSpace]", "20", "\[InvisibleSpace]", "\<\" p \"\>", "\[InvisibleSpace]", "1.41421356237309366677134019144701805655`19.4289045615697"}], SequenceForm[ "iteration:", 20, " p ", 1.41421356237309366677`19.4289045615697], Editable->False]], "Print", CellChangeTimes->{3.398601252528296*^9}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"iteration:\"\>", "\[InvisibleSpace]", "21", "\[InvisibleSpace]", "\<\" p \"\>", "\[InvisibleSpace]", "1.41421356237309481168276813842`19.166826906138898"}], SequenceForm[ "iteration:", 21, " p ", 1.41421356237309481168`19.166826906138898], Editable->False]], "Print", CellChangeTimes->{3.39860125257583*^9}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"iteration:\"\>", "\[InvisibleSpace]", "22", "\[InvisibleSpace]", "\<\" p \"\>", "\[InvisibleSpace]", "1.41421356237309500811851374223`18.9047492507081"}], SequenceForm[ "iteration:", 22, " p ", 1.4142135623730950081`18.9047492507081], Editable->False]], "Print", CellChangeTimes->{3.398601252625969*^9}], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"iteration:\"\>", "\[InvisibleSpace]", "23", "\[InvisibleSpace]", "\<\" p \"\>", "\[InvisibleSpace]", "1.41421356237309504182155941809`18.64267159527734"}], SequenceForm[ "iteration:", 23, " p ", 1.4142135623730950418`18.64267159527734], Editable->False]], "Print", CellChangeTimes->{3.398601252675838*^9}] }, Open ]] }, Open ]] }, Open ]] }, WindowSize->{943, 854}, WindowMargins->{{20, Automatic}, {Automatic, 44}}, 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, 100, 4, 112, "Section"], Cell[693, 29, 93, 1, 34, "Subsection"] }, Open ]], Cell[CellGroupData[{ Cell[823, 35, 117, 5, 72, "Section"], Cell[943, 42, 2711, 71, 278, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[3691, 118, 144, 5, 72, "Section"], Cell[CellGroupData[{ Cell[3860, 127, 317, 9, 37, "Input"], Cell[CellGroupData[{ Cell[4202, 140, 382, 8, 20, "Print"], Cell[4587, 150, 322, 7, 20, "Print"], Cell[4912, 159, 385, 8, 20, "Print"], Cell[5300, 169, 383, 8, 20, "Print"], Cell[5686, 179, 382, 8, 20, "Print"], Cell[6071, 189, 384, 8, 20, "Print"], Cell[6458, 199, 382, 8, 20, "Print"], Cell[6843, 209, 382, 8, 20, "Print"], Cell[7228, 219, 381, 8, 20, "Print"], Cell[7612, 229, 383, 8, 20, "Print"], Cell[7998, 239, 385, 8, 20, "Print"], Cell[8386, 249, 383, 8, 20, "Print"], Cell[8772, 259, 382, 8, 20, "Print"], Cell[9157, 269, 381, 8, 20, "Print"], Cell[9541, 279, 382, 8, 20, "Print"], Cell[9926, 289, 384, 8, 20, "Print"], Cell[10313, 299, 379, 8, 20, "Print"], Cell[10695, 309, 377, 8, 20, "Print"], Cell[11075, 319, 377, 8, 20, "Print"], Cell[11455, 329, 371, 8, 20, "Print"], Cell[11829, 339, 367, 8, 20, "Print"], Cell[12199, 349, 369, 8, 20, "Print"] }, Open ]] }, Open ]] }, Open ]] } ] *) (* End of internal cache information *)