(* Content-type: application/vnd.wolfram.mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 9.0' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 157, 7] NotebookDataLength[ 12430, 381] NotebookOptionsPosition[ 11619, 349] NotebookOutlinePosition[ 12000, 365] CellTagsIndexPosition[ 11957, 362] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[BoxData[{ RowBox[{ RowBox[{"Quiet", "@", RowBox[{"Remove", "[", "\"\\"", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"SetDirectory", "[", RowBox[{"NotebookDirectory", "[", "]"}], "]"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"$HistoryLength", "=", "3"}], ";"}]}], "Input"], Cell[CellGroupData[{ Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"expr", "[", "t_", "]"}], ":=", RowBox[{ RowBox[{"a", "*", SuperscriptBox["t", "2"]}], "+", RowBox[{"b", "*", "t"}], "+", "c"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"eqn", "=", RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"expr", "[", RowBox[{"tin", "-", "\[CapitalDelta]t"}], "]"}], "\[Equal]", "fleft"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"expr", "[", "tin", "]"}], "\[Equal]", "fin"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"expr", "[", RowBox[{"tin", "+", "\[CapitalDelta]t"}], "]"}], "\[Equal]", "fright"}]}], "\[IndentingNewLine]", "}"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"solabc", "=", RowBox[{ RowBox[{"Solve", "[", RowBox[{"eqn", ",", RowBox[{"{", RowBox[{"a", ",", "b", ",", "c"}], "}"}]}], "]"}], "[", RowBox[{"[", "1", "]"}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"integrand", "=", RowBox[{ RowBox[{"expr", "[", "t", "]"}], "/.", "solabc"}]}], ";"}], "\[IndentingNewLine]", RowBox[{"Integrate", "[", RowBox[{"integrand", ",", RowBox[{"{", RowBox[{"t", ",", RowBox[{"tin", "-", "\[CapitalDelta]t"}], ",", RowBox[{"tin", "+", "\[CapitalDelta]t"}]}], "}"}]}], "]"}], "\[IndentingNewLine]", RowBox[{ FractionBox["%", FractionBox["\[CapitalDelta]t", "3"]], "//", "Simplify"}]}], "Input", CellChangeTimes->{{3.7197425786121006`*^9, 3.719742599874938*^9}, { 3.7197427008695154`*^9, 3.719742762474024*^9}, {3.7197428478841734`*^9, 3.7197429380835323`*^9}, {3.7197430471121235`*^9, 3.7197430772357764`*^9}, { 3.719743359284272*^9, 3.7197433847903166`*^9}}], Cell[BoxData[ RowBox[{ FractionBox[ RowBox[{"4", " ", "fin", " ", "\[CapitalDelta]t"}], "3"], "+", FractionBox[ RowBox[{"fleft", " ", "\[CapitalDelta]t"}], "3"], "+", FractionBox[ RowBox[{"fright", " ", "\[CapitalDelta]t"}], "3"]}]], "Output", CellChangeTimes->{{3.7197428664482064`*^9, 3.7197428954642572`*^9}, { 3.71974293117272*^9, 3.719742938801133*^9}, 3.719743077968978*^9, { 3.7197433803755093`*^9, 3.719743385414318*^9}, {3.7197446636825633`*^9, 3.7197446685809717`*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"4", " ", "fin"}], "+", "fleft", "+", "fright"}]], "Output", CellChangeTimes->{{3.7197428664482064`*^9, 3.7197428954642572`*^9}, { 3.71974293117272*^9, 3.719742938801133*^9}, 3.719743077968978*^9, { 3.7197433803755093`*^9, 3.719743385414318*^9}, {3.7197446636825633`*^9, 3.719744668596572*^9}}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[{ RowBox[{ RowBox[{"Quiet", "@", RowBox[{"Remove", "[", "\"\\"", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"tmin", "=", "0."}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"tmax", "=", FractionBox["Pi", "2"]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"nIntervals", "=", "6"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"\[CapitalDelta]t", "=", FractionBox[ RowBox[{"tmax", "-", "tmin"}], "nIntervals"]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"functionValues", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"Sin", "[", "t", "]"}], ",", RowBox[{"{", RowBox[{"t", ",", "tmin", ",", "tmax", ",", "\[CapitalDelta]t"}], "}"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"weights", "=", RowBox[{"{", RowBox[{"1", ",", "4", ",", "1"}], "}"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"triples", "=", RowBox[{"Partition", "[", RowBox[{"functionValues", ",", "3", ",", "2"}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{"integral", "=", RowBox[{ FractionBox["\[CapitalDelta]t", "3"], RowBox[{"Plus", "@@", RowBox[{"(", RowBox[{"triples", "/.", RowBox[{ RowBox[{"{", RowBox[{"a_Real", ",", "b_", ",", "c_"}], "}"}], "\[RuleDelayed]", RowBox[{"weights", ".", RowBox[{"{", RowBox[{"a", ",", "b", ",", "c"}], "}"}]}]}]}], ")"}]}]}]}]}], "Input", CellChangeTimes->{{3.719743644593173*^9, 3.7197436835308414`*^9}, { 3.7197438157098737`*^9, 3.719743830186699*^9}, {3.719743950790511*^9, 3.7197440135806212`*^9}, {3.719744118147605*^9, 3.7197441354480352`*^9}, { 3.7197442345238094`*^9, 3.7197442995447235`*^9}, {3.719744352836417*^9, 3.719744393006488*^9}, {3.7197444366397643`*^9, 3.7197444671378183`*^9}, { 3.71974481568923*^9, 3.7197448335980616`*^9}, {3.7197455467845144`*^9, 3.719745555333329*^9}, {3.719745662567918*^9, 3.719745681693551*^9}}], Cell[BoxData["1.0000263121705926`"], "Output", CellChangeTimes->{ 3.719744229656601*^9, {3.7197442711526737`*^9, 3.719744300309125*^9}, { 3.719744441007772*^9, 3.7197444676682186`*^9}, 3.719744671654177*^9, { 3.719744815970031*^9, 3.7197448342376623`*^9}, 3.719745548375717*^9, { 3.7197456642995205`*^9, 3.7197456821771517`*^9}}] }, Open ]], Cell[BoxData[{ RowBox[{ RowBox[{"Quiet", "@", RowBox[{"Remove", "[", "\"\\"", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"expr", "[", "t_", "]"}], ":=", RowBox[{ RowBox[{"b", "*", "t"}], "+", "c"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"eqn", "=", RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"expr", "[", "tleft", "]"}], "\[Equal]", "fleft"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"expr", "[", RowBox[{"tleft", "+", "\[CapitalDelta]t"}], "]"}], "\[Equal]", "fright"}]}], "\[IndentingNewLine]", "}"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"solbc", "=", RowBox[{ RowBox[{"Solve", "[", RowBox[{"eqn", ",", RowBox[{"{", RowBox[{"b", ",", "c"}], "}"}]}], "]"}], "[", RowBox[{"[", "1", "]"}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"integrand", "=", RowBox[{ RowBox[{"expr", "[", "t", "]"}], "/.", "solbc"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Integrate", "[", RowBox[{"integrand", ",", RowBox[{"{", RowBox[{"t", ",", "tleft", ",", RowBox[{"tleft", "+", "\[CapitalDelta]t"}]}], "}"}]}], "]"}], ";"}], "\[IndentingNewLine]"}], "Input", CellChangeTimes->{{3.7197449881631327`*^9, 3.7197450252131977`*^9}, { 3.7197450691116753`*^9, 3.7197451906670885`*^9}, 3.7197455258648777`*^9}], Cell[CellGroupData[{ Cell[BoxData[{ RowBox[{ RowBox[{"Quiet", "@", RowBox[{"Remove", "[", "\"\\"", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"tmin", "=", "0."}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"tmax", "=", FractionBox["Pi", "2"]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"nIntervals", "=", "8"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"\[CapitalDelta]t", "=", FractionBox[ RowBox[{"tmax", "-", "tmin"}], "nIntervals"]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"functionValues", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"Sin", "[", "t", "]"}], ",", RowBox[{"{", RowBox[{"t", ",", "tmin", ",", "tmax", ",", "\[CapitalDelta]t"}], "}"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"weights", "=", RowBox[{"{", RowBox[{"1", ",", "1"}], "}"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"triples", "=", RowBox[{"Partition", "[", RowBox[{"functionValues", ",", "2", ",", "1"}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{"integral", "=", RowBox[{ FractionBox["\[CapitalDelta]t", "2"], RowBox[{"Plus", "@@", RowBox[{"(", RowBox[{"triples", "/.", RowBox[{ RowBox[{"{", RowBox[{"a_Real", ",", "b_"}], "}"}], "\[RuleDelayed]", RowBox[{"weights", ".", RowBox[{"{", RowBox[{"a", ",", "b"}], "}"}]}]}]}], ")"}]}]}]}]}], "Input", CellChangeTimes->{{3.719745312128902*^9, 3.71974534502936*^9}, { 3.719745539795702*^9, 3.7197455406693034`*^9}, {3.7197457383372507`*^9, 3.7197457465116653`*^9}}], Cell[BoxData["0.9967851718861696`"], "Output", CellChangeTimes->{ 3.719745346058962*^9, 3.719745541402505*^9, 3.7197456140206327`*^9, { 3.719745738586851*^9, 3.7197457467924657`*^9}}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[{ RowBox[{ RowBox[{"Quiet", "@", RowBox[{"Remove", "[", "\"\\"", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"tmin", "=", "0."}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"tmax", "=", FractionBox["Pi", "2"]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"nIntervals", "=", "8"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"\[CapitalDelta]t", "=", FractionBox[ RowBox[{"tmax", "-", "tmin"}], "nIntervals"]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"integrand", "=", RowBox[{"1.", "+", "t", "+", SuperscriptBox["t", "2"], "+", SuperscriptBox["t", "3"], "+", RowBox[{"a", "*", SuperscriptBox["t", "4"]}]}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"functionValues", "=", RowBox[{"Table", "[", RowBox[{"integrand", ",", RowBox[{"{", RowBox[{"t", ",", "tmin", ",", "tmax", ",", "\[CapitalDelta]t"}], "}"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"weights", "=", RowBox[{"{", RowBox[{"1", ",", "4", ",", "1"}], "}"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"triples", "=", RowBox[{"Partition", "[", RowBox[{"functionValues", ",", "3", ",", "2"}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"integral", "=", RowBox[{ FractionBox["\[CapitalDelta]t", "3"], RowBox[{"Plus", "@@", RowBox[{"(", RowBox[{"triples", "/.", RowBox[{ RowBox[{"{", RowBox[{"a_", ",", "b_", ",", "c_"}], "}"}], "\[RuleDelayed]", RowBox[{"weights", ".", RowBox[{"{", RowBox[{"a", ",", "b", ",", "c"}], "}"}]}]}]}], ")"}]}]}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"integral", "-", RowBox[{"Integrate", "[", RowBox[{"integrand", ",", RowBox[{"{", RowBox[{"t", ",", "tmin", ",", "tmax"}], "}"}]}], "]"}]}], "//", "Simplify"}]}], "Input", CellChangeTimes->{{3.719745924773178*^9, 3.7197460745958414`*^9}, { 3.719746231422917*^9, 3.719746291514222*^9}}], Cell[BoxData[ RowBox[{"0.`", "\[VeryThinSpace]", "+", RowBox[{"0.00031129932127371696`", " ", "a"}]}]], "Output", CellChangeTimes->{{3.719745969358056*^9, 3.719746075048242*^9}, { 3.7197462402993326`*^9, 3.7197462920446234`*^9}}] }, Open ]] }, WindowSize->{1188, 836}, WindowMargins->{{24, Automatic}, {23, Automatic}}, Magnification->2.1000001430511475`, FrontEndVersion->"9.0 for Microsoft Windows (64-bit) (January 25, 2013)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[557, 20, 333, 10, 168, "Input"], Cell[CellGroupData[{ Cell[915, 34, 1768, 50, 453, "Input"], Cell[2686, 86, 508, 11, 112, "Output"], Cell[3197, 99, 339, 6, 88, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[3573, 110, 2022, 53, 536, "Input"], Cell[5598, 165, 341, 5, 88, "Output"] }, Open ]], Cell[5954, 173, 1435, 43, 402, "Input"], Cell[CellGroupData[{ Cell[7414, 220, 1637, 48, 497, "Input"], Cell[9054, 270, 189, 3, 88, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[9280, 278, 2084, 62, 617, "Input"], Cell[11367, 342, 236, 4, 120, "Output"] }, Open ]] } ] *) (* End of internal cache information *)