(* 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[ 8874, 308] NotebookOptionsPosition[ 7260, 248] NotebookOutlinePosition[ 7684, 265] CellTagsIndexPosition[ 7641, 262] WindowFrame->Normal ContainsDynamic->False*) (* Beginning of Notebook Content *) Notebook[{ Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"f", "[", "x_", "]"}], ":=", " ", RowBox[{"2", RowBox[{"x", "^", "2"}]}]}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"(*", RowBox[{ RowBox[{"Simpson", "'"}], "s", " ", "Method"}], "*)"}]}]}], "Input", CellChangeTimes->{{3.422619934640625*^9, 3.422619941875*^9}, { 3.4356888941015997`*^9, 3.4356888949828672`*^9}, {3.435689102701552*^9, 3.4356891053854113`*^9}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"2", "[", RowBox[{"3", "^", "2"}], "]"}]], "Input", CellChangeTimes->{{3.422619946078125*^9, 3.42261996409375*^9}, { 3.435689130291224*^9, 3.435689144161168*^9}}], Cell[BoxData[ RowBox[{"2", "[", "9", "]"}]], "Output", CellChangeTimes->{ 3.435689112766024*^9, {3.435689145162608*^9, 3.4356891570096436`*^9}}] }, Open ]], Cell[BoxData[ RowBox[{"(*", RowBox[{ RowBox[{"imput", " ", "a"}], ",", " ", "b", ",", " ", RowBox[{"and", " ", "n", " ", "value"}]}], "*)"}]], "Input", CellChangeTimes->{{3.4356890784066176`*^9, 3.435689096692912*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"a", "=", "1"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"b", "=", "4"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"n", "=", "2"}], ";"}]}], "Input", CellChangeTimes->{ 3.422619964953125*^9, {3.43568890261384*^9, 3.4356890498655777`*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"Simpson", "[", RowBox[{"n", ",", "a", ",", "b"}], "]"}], ":=", RowBox[{"(", "\[IndentingNewLine]", RowBox[{ RowBox[{"NN", "=", RowBox[{"2", "n"}]}], ";", "\[IndentingNewLine]", RowBox[{"h", " ", "=", " ", RowBox[{ RowBox[{"(", RowBox[{"b", "-", "a"}], ")"}], "/", "NN"}]}], ";", "\[IndentingNewLine]", RowBox[{"oddsum", "=", "0"}], ";", "\[IndentingNewLine]", RowBox[{"evensum", "=", "0"}], ";", "\[IndentingNewLine]", RowBox[{"For", "[", RowBox[{ RowBox[{"i", "=", "0"}], ",", " ", RowBox[{"i", "\[LessEqual]", RowBox[{"n", "-", "1"}]}], ",", RowBox[{"i", "=", RowBox[{"i", "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"oddsum", " ", "=", " ", RowBox[{"oddsum", " ", "+", " ", RowBox[{"f", "[", RowBox[{"a", " ", "+", " ", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"2", "i"}], "+", "1"}], ")"}], "h"}]}], "]"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"evensum", " ", "=", " ", RowBox[{"evensum", " ", "+", " ", RowBox[{"f", "[", RowBox[{"a", "+", RowBox[{"2", "i", " ", "h"}]}], "]"}]}]}]}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"S", "=", " ", RowBox[{ RowBox[{"h", "/", "3"}], RowBox[{"(", " ", RowBox[{ RowBox[{"4", " ", "oddsum"}], " ", "+", " ", RowBox[{"2", "evensum"}], " ", "-", " ", RowBox[{"f", "[", "a", "]"}], "+", RowBox[{"f", "[", "b", "]"}]}], ")"}]}]}]}], ")"}]}]], "Input", CellChangeTimes->{{3.4356890527397103`*^9, 3.4356890566252975`*^9}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"N", "[", RowBox[{ RowBox[{"Simpson", "[", RowBox[{"n", ",", "a", ",", " ", "b"}], "]"}], ",", "10"}], "]"}]], "Input", CellChangeTimes->{{3.4226199941875*^9, 3.422620007640625*^9}, { 3.422620060734375*^9, 3.422620103765625*^9}, {3.42262013765625*^9, 3.4226202195*^9}, {3.4356889199687953`*^9, 3.435689001516054*^9}}], Cell[BoxData["42.`10."], "Output", CellChangeTimes->{ 3.422619865296875*^9, 3.422620014375*^9, {3.42262006471875*^9, 3.4226200919375*^9}, {3.422620123046875*^9, 3.42262022021875*^9}, 3.4356889030745025`*^9, {3.435688934089099*^9, 3.43568897981485*^9}, 3.4356890610516624`*^9, 3.43568911633115*^9, 3.4356891600440063`*^9}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"N", "[", "S", "]"}]], "Input"], Cell[BoxData["42.`"], "Output", CellChangeTimes->{ 3.422619866390625*^9, {3.4356889042762303`*^9, 3.4356889805158577`*^9}, 3.4356890618628287`*^9, 3.435689117092245*^9, 3.435689161035432*^9}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"Integrate", "[", RowBox[{ RowBox[{"f", "[", "x", "]"}], ",", RowBox[{"{", RowBox[{"x", ",", "a", ",", "b"}], "}"}]}], "]"}]], "Input", CellChangeTimes->{{3.4356889278200846`*^9, 3.4356889959981203`*^9}}], Cell[BoxData["42"], "Output", CellChangeTimes->{ 3.422619871515625*^9, 3.4356889070702477`*^9, {3.435688954398302*^9, 3.4356889812168655`*^9}, 3.4356890627040386`*^9, 3.4356891180836706`*^9, 3.4356891619868*^9}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"N", "[", "%", "]"}]], "Input"], Cell[BoxData["42.`"], "Output", CellChangeTimes->{ 3.42261987178125*^9, 3.4356889140302563`*^9, {3.435688955860405*^9, 3.435688981857787*^9}, 3.435689063415061*^9, 3.4356891192653694`*^9, 3.4356891628780813`*^9}] }, Open ]], Cell[BoxData[ RowBox[{ RowBox[{"f", "[", "x_", "]"}], ":=", " ", RowBox[{"Sin", "[", RowBox[{"Exp", "[", "x", "]"}], "]"}]}]], "Input"], Cell[BoxData[","], "Input", CellChangeTimes->{3.4356891701585503`*^9}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"N", "[", RowBox[{"Simpson", "[", RowBox[{"5", ",", "2", ",", "4"}], "]"}], "]"}]], "Input"], Cell[BoxData["0.05554942378203602`"], "Output", CellChangeTimes->{3.42261987196875*^9, 3.4356890649572783`*^9}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"Integrate", "[", RowBox[{ RowBox[{"f", "[", "x", "]"}], ",", RowBox[{"{", RowBox[{"x", ",", "2", ",", "4"}], "}"}]}], "]"}]], "Input"], Cell[BoxData[ RowBox[{ RowBox[{"-", RowBox[{"SinIntegral", "[", SuperscriptBox["\[ExponentialE]", "2"], "]"}]}], "+", RowBox[{"SinIntegral", "[", SuperscriptBox["\[ExponentialE]", "4"], "]"}]}]], "Output", CellChangeTimes->{3.422619872734375*^9}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"N", "[", "%", "]"}]], "Input"], Cell[BoxData["0.08087339642083569`"], "Output", CellChangeTimes->{3.422619874625*^9}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"NIntegrate", "[", RowBox[{ RowBox[{"f", "[", "x", "]"}], ",", RowBox[{"{", RowBox[{"x", ",", "2", ",", "4"}], "}"}]}], "]"}]], "Input"], Cell[BoxData["0.08087339642083453`"], "Output", CellChangeTimes->{3.422619876453125*^9}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"N", "[", RowBox[{"Simpson", "[", RowBox[{"100", ",", "2", ",", "4"}], "]"}], "]"}]], "Input"], Cell[BoxData["0.08087740615166572`"], "Output", CellChangeTimes->{3.422619877796875*^9}] }, Open ]] }, WindowSize->{1272, 886}, WindowMargins->{{0, Automatic}, {Automatic, 0}}, DockedCells->FEPrivate`FrontEndResource[ "FEExpressions", "CompatibilityToolbar"], FrontEndVersion->"6.0 for Microsoft Windows (32-bit) (June 19, 2007)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[568, 21, 462, 13, 72, "Input"], Cell[CellGroupData[{ Cell[1055, 38, 191, 4, 31, "Input"], Cell[1249, 44, 148, 3, 30, "Output"] }, Open ]], Cell[1412, 50, 230, 5, 31, "Input"], Cell[1645, 57, 297, 8, 72, "Input"], Cell[1945, 67, 1750, 47, 192, "Input"], Cell[CellGroupData[{ Cell[3720, 118, 360, 8, 31, "Input"], Cell[4083, 128, 336, 5, 30, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[4456, 138, 54, 1, 31, "Input"], Cell[4513, 141, 198, 3, 30, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[4748, 149, 243, 6, 31, "Input"], Cell[4994, 157, 222, 4, 30, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[5253, 166, 54, 1, 31, "Input"], Cell[5310, 169, 223, 4, 30, "Output"] }, Open ]], Cell[5548, 176, 145, 4, 31, "Input"], Cell[5696, 182, 71, 1, 31, "Input"], Cell[CellGroupData[{ Cell[5792, 187, 122, 3, 31, "Input"], Cell[5917, 192, 112, 1, 30, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[6066, 198, 173, 5, 31, "Input"], Cell[6242, 205, 266, 7, 33, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[6545, 217, 54, 1, 31, "Input"], Cell[6602, 220, 86, 1, 30, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[6725, 226, 174, 5, 31, "Input"], Cell[6902, 233, 89, 1, 30, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[7028, 239, 124, 3, 31, "Input"], Cell[7155, 244, 89, 1, 30, "Output"] }, Open ]] } ] *) (* End of internal cache information *)