(* Content-type: application/vnd.wolfram.mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 10.0' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 158, 7] NotebookDataLength[ 35253, 922] NotebookOptionsPosition[ 34228, 881] NotebookOutlinePosition[ 34589, 897] CellTagsIndexPosition[ 34546, 894] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["Riemann Sums", "Title", CellChangeTimes->{{3.6297194777217493`*^9, 3.629719518303899*^9}, { 3.629719934656958*^9, 3.629719941143162*^9}}, TextAlignment->Center], Cell["\<\ by Ruth Dover Illinois Mathematics and Science Academy\ \>", "Subsubtitle", CellChangeTimes->{{3.693183751755031*^9, 3.693183763915751*^9}}], Cell["\<\ First, define a function, choose your window, and the maximum number of \ rectangles (or trapezoids) you wish to see. An example is given, but these \ pieces may all be edited in this first command or within the separate \ commands below.\ \>", "Text", CellChangeTimes->{{3.629719742124618*^9, 3.6297198426240253`*^9}, { 3.629719953398903*^9, 3.629719977564473*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"f", "[", "x_", "]"}], ":=", RowBox[{ SuperscriptBox["x", "2"], "+", "1"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"xmin", "=", "0"}], ";", " ", RowBox[{"xmax", "=", "3"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"maxrect", "=", "20"}], ";"}]}], "Input", CellChangeTimes->{{3.62971985323409*^9, 3.6297198914636307`*^9}}], Cell[CellGroupData[{ Cell["LeftSum", "Section", CellChangeTimes->{{3.403269671702868*^9, 3.403269673302601*^9}}], Cell[BoxData[ RowBox[{"Manipulate", "[", RowBox[{ RowBox[{"LeftSum", "[", RowBox[{ RowBox[{"f", "[", "x", "]"}], ",", " ", RowBox[{"{", RowBox[{"x", ",", "xmin", ",", " ", "xmax"}], "}"}], ",", " ", "n", ",", " ", RowBox[{"ImageSize", "\[Rule]", "500"}]}], "]"}], ",", " ", RowBox[{"{", RowBox[{"n", ",", " ", "1", ",", " ", "maxrect", ",", " ", "1"}], "}"}]}], "]"}]], "Input", CellChangeTimes->{{3.403269388886189*^9, 3.4032694892494783`*^9}, { 3.403269613005494*^9, 3.403269617144491*^9}, {3.40326965482663*^9, 3.403269662728404*^9}, 3.403271977124041*^9, {3.403272045505875*^9, 3.4032720526407003`*^9}, 3.403273065305121*^9}] }, Open ]], Cell[CellGroupData[{ Cell["RightSum", "Section", CellChangeTimes->{{3.4032696816795177`*^9, 3.403269683238147*^9}}], Cell[BoxData[ RowBox[{"Manipulate", "[", RowBox[{ RowBox[{"RightSum", "[", RowBox[{ RowBox[{"f", "[", "x", "]"}], ",", " ", RowBox[{"{", RowBox[{"x", ",", "xmin", ",", " ", "xmax"}], "}"}], ",", " ", "n", ",", " ", RowBox[{"ImageSize", "\[Rule]", "500"}]}], "]"}], ",", " ", RowBox[{"{", RowBox[{"n", ",", " ", "1", ",", " ", "maxrect", ",", " ", "1"}], "}"}]}], "]"}]], "Input", CellChangeTimes->{{3.403269388886189*^9, 3.4032694892494783`*^9}, { 3.403269613005494*^9, 3.403269617144491*^9}, {3.40326965482663*^9, 3.403269662728404*^9}, {3.4032697431851797`*^9, 3.4032697438164473`*^9}, { 3.403272209843328*^9, 3.403272219829679*^9}, 3.40327306879126*^9}] }, Open ]], Cell[CellGroupData[{ Cell["MidpointSum", "Section", CellChangeTimes->{{3.4032697170948*^9, 3.403269723222384*^9}}], Cell[BoxData[ RowBox[{"Manipulate", "[", RowBox[{ RowBox[{"MidSum", "[", RowBox[{ RowBox[{"f", "[", "x", "]"}], ",", " ", RowBox[{"{", RowBox[{"x", ",", "xmin", ",", " ", "xmax"}], "}"}], ",", " ", "n", ",", " ", RowBox[{"ImageSize", "->", " ", "500"}]}], "]"}], ",", " ", RowBox[{"{", RowBox[{"n", ",", " ", "1", ",", " ", "maxrect", ",", " ", "1"}], "}"}]}], "]"}]], "Input", CellChangeTimes->{{3.403269388886189*^9, 3.4032694892494783`*^9}, { 3.403269613005494*^9, 3.403269617144491*^9}, {3.40326965482663*^9, 3.403269662728404*^9}, {3.403269733443049*^9, 3.403269737032442*^9}, { 3.403272268767787*^9, 3.403272269453682*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["TrapezoidalSum", "Section", CellChangeTimes->{{3.403269750426074*^9, 3.403269760598308*^9}}], Cell["\<\ No, this isn't really a Riemann sum, but it seems to fit in this notebook.\ \>", "Text", CellChangeTimes->{{3.403269764965342*^9, 3.403269777870326*^9}, { 3.403269877547515*^9, 3.4032698783345337`*^9}}], Cell[BoxData[ RowBox[{"Manipulate", "[", RowBox[{ RowBox[{"TrapSum", "[", RowBox[{ RowBox[{"f", "[", "x", "]"}], ",", " ", RowBox[{"{", RowBox[{"x", ",", "xmin", ",", " ", "xmax"}], "}"}], ",", " ", "n", ",", " ", RowBox[{"ImageSize", "->", " ", "500"}]}], "]"}], ",", " ", RowBox[{"{", RowBox[{"n", ",", " ", "1", ",", " ", "maxrect", ",", " ", "1"}], "}"}]}], "]"}]], "Input", CellChangeTimes->{{3.403269388886189*^9, 3.4032694892494783`*^9}, { 3.403269613005494*^9, 3.403269617144491*^9}, {3.40326965482663*^9, 3.403269662728404*^9}, {3.403269786188354*^9, 3.403269786808481*^9}, { 3.4032730727746677`*^9, 3.403273073250011*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["initialization", "Section", CellChangeTimes->{{3.6297195647998123`*^9, 3.6297195675107737`*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"LeftSum", "[", RowBox[{"f_", ",", " ", RowBox[{"{", RowBox[{"x_", ",", " ", "a_", ",", " ", "b_"}], "}"}], ",", " ", "n_", ",", " ", "opts___"}], "]"}], " ", ":=", "\n", "\t", "\n", " ", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ "\[CapitalDelta]x", ",", " ", "rects", ",", " ", "i", ",", " ", "area", ",", " ", "k", ",", " ", "w", ",", " ", "z", ",", " ", "u", ",", " ", "v", ",", " ", "p", ",", " ", "q"}], "}"}], ",", " ", "\n", "\t\t", RowBox[{ RowBox[{"\[CapitalDelta]x", " ", "=", " ", RowBox[{ RowBox[{"(", RowBox[{"b", " ", "-", " ", "a"}], ")"}], "/", "n"}]}], ";", "\n", "\t\t", RowBox[{"rects", " ", "=", " ", "\n", " ", RowBox[{"Table", "[", RowBox[{ RowBox[{"Line", "[", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"a", " ", "+", " ", RowBox[{ RowBox[{"(", RowBox[{"i", " ", "-", " ", "1"}], ")"}], "\[CapitalDelta]x"}]}], ",", " ", "\n", " ", "0"}], "}"}], ",", " ", RowBox[{"{", RowBox[{ RowBox[{"a", " ", "+", " ", RowBox[{ RowBox[{"(", RowBox[{"i", " ", "-", " ", "1"}], ")"}], "\[CapitalDelta]x"}]}], ",", " ", "\n", " ", RowBox[{ RowBox[{"Function", "[", RowBox[{ RowBox[{"{", "x", "}"}], ",", " ", RowBox[{"Evaluate", "[", "f", "]"}]}], "]"}], "[", RowBox[{"a", " ", "+", " ", RowBox[{ RowBox[{"(", RowBox[{"i", " ", "-", " ", "1"}], ")"}], "\[CapitalDelta]x"}]}], "]"}]}], "}"}], ",", " ", RowBox[{"{", RowBox[{ RowBox[{"a", " ", "+", " ", "\n", " ", RowBox[{"i", "*", " ", "\[CapitalDelta]x"}]}], ",", " ", "\n", " ", RowBox[{ RowBox[{"Function", "[", RowBox[{ RowBox[{"{", "x", "}"}], ",", " ", RowBox[{"Evaluate", "[", "f", "]"}]}], "]"}], "[", RowBox[{"a", " ", "+", " ", RowBox[{ RowBox[{"(", RowBox[{"i", " ", "-", " ", "1"}], ")"}], "\[CapitalDelta]x"}]}], "]"}]}], "}"}], ",", " ", RowBox[{"{", RowBox[{ RowBox[{"a", " ", "+", " ", "\n", " ", RowBox[{"i", "*", "\[CapitalDelta]x"}]}], ",", " ", "0"}], "}"}], ",", " ", RowBox[{"{", RowBox[{ RowBox[{"a", " ", "+", " ", RowBox[{ RowBox[{"(", RowBox[{"i", " ", "-", " ", "1"}], ")"}], "\[CapitalDelta]x"}]}], ",", " ", "\n", " ", "0"}], "}"}]}], "}"}], "]"}], ",", " ", RowBox[{"{", RowBox[{"i", ",", " ", "1", ",", " ", "n"}], "}"}]}], "]"}]}], ";", "\n", "\t\t", RowBox[{"area", " ", "=", " ", RowBox[{ RowBox[{"Plus", " ", "@@", " ", "\n", " ", RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"Function", "[", RowBox[{ RowBox[{"{", "x", "}"}], ",", " ", RowBox[{"Evaluate", "[", "f", "]"}]}], "]"}], "[", "\n", " ", RowBox[{"a", " ", "+", " ", RowBox[{ RowBox[{"(", RowBox[{"k", " ", "-", " ", "1"}], ")"}], "\[CapitalDelta]x"}]}], "]"}], "*", "\[CapitalDelta]x"}], ",", " ", RowBox[{"{", RowBox[{"k", ",", " ", "1", ",", " ", "n"}], "}"}]}], "]"}]}], " ", "//", " ", "\n", " ", "N"}]}], ";", "\n", "\t\t", RowBox[{"z", " ", "=", " ", RowBox[{"Plot", "[", RowBox[{ RowBox[{ RowBox[{"Function", "[", RowBox[{ RowBox[{"{", "x", "}"}], ",", " ", RowBox[{"Evaluate", "[", "f", "]"}]}], "]"}], "[", "x", "]"}], ",", " ", RowBox[{"{", RowBox[{"x", ",", " ", "a", ",", " ", "b"}], "}"}]}], "]"}]}], ";", "\n", "\t\t", "\n", "\t", RowBox[{"p", " ", "=", " ", RowBox[{"Min", "[", RowBox[{"0", ",", " ", RowBox[{ RowBox[{"PlotRange", "[", "z", "]"}], "[", RowBox[{"[", RowBox[{"2", ",", " ", "1"}], "]"}], "]"}]}], "]"}]}], ";", " ", RowBox[{"q", " ", "=", " ", RowBox[{"Max", "[", RowBox[{"0", ",", " ", RowBox[{ RowBox[{"PlotRange", "[", "z", "]"}], "[", RowBox[{"[", RowBox[{"2", ",", " ", "2"}], "]"}], "]"}]}], " ", "]"}]}], ";", "\n", "\t\t", "\n", "\t\t", RowBox[{"Plot", "[", RowBox[{ RowBox[{ RowBox[{"Function", "[", RowBox[{ RowBox[{"{", "x", "}"}], ",", " ", RowBox[{"Evaluate", "[", "f", "]"}]}], "]"}], "[", "x", "]"}], ",", " ", RowBox[{"{", RowBox[{"x", ",", " ", RowBox[{"a", " ", "-", " ", RowBox[{ RowBox[{"(", RowBox[{"b", " ", "-", " ", "a"}], ")"}], "/", "10"}]}], ",", " ", RowBox[{"b", " ", "+", " ", RowBox[{ RowBox[{"(", RowBox[{"b", " ", "-", " ", "a"}], ")"}], "/", "10"}]}]}], "}"}], ",", " ", "\n", " ", RowBox[{"Evaluate", "[", RowBox[{"Sequence", " ", "@@", " ", RowBox[{"FilterRules", "[", RowBox[{ RowBox[{"{", "opts", "}"}], ",", " ", RowBox[{"Options", "[", "Plot", "]"}]}], "]"}]}], "]"}], ",", " ", RowBox[{"Epilog", " ", "->", " ", RowBox[{"{", RowBox[{"Red", ",", " ", "rects"}], "}"}]}], ",", " ", "\n", " ", RowBox[{"Axes", " ", "->", " ", "True"}], ",", " ", RowBox[{"PlotRange", " ", "->", " ", RowBox[{"{", RowBox[{"p", ",", " ", "q"}], "}"}]}], ",", " ", RowBox[{"PlotStyle", " ", "->", " ", RowBox[{"Thickness", "[", ".01", "]"}]}], ",", " ", "\n", " ", RowBox[{"PlotLabel", " ", "->", "\n", " ", RowBox[{"Style", "[", RowBox[{ RowBox[{"StringForm", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"NumberForm", "[", RowBox[{"area", ",", " ", "4"}], "]"}]}], "]"}], ",", " ", "\n", " ", RowBox[{"FontSize", " ", "->", " ", "20"}], ",", " ", RowBox[{"FontWeight", " ", "->", " ", "\"\\""}]}], " ", "]"}]}]}], "]"}]}]}], "\n", "\t", "]"}]}], "\t\t\t\t\t\t\t\t\t\t\t", "\n", "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t", "\n", "\t\t\t\t\t\t"}], "\n", RowBox[{ RowBox[{ RowBox[{"RightSum", "[", RowBox[{"f_", ",", " ", RowBox[{"{", RowBox[{"x_", ",", " ", "a_", ",", " ", "b_"}], "}"}], ",", " ", "n_", ",", " ", "opts___"}], "]"}], " ", ":=", "\n", "\t", "\n", " ", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ "\[CapitalDelta]x", ",", " ", "rects", ",", " ", "i", ",", " ", "area", ",", " ", "k", ",", " ", "w", ",", " ", "z", ",", " ", "u", ",", " ", "v", ",", " ", "p", ",", " ", "q"}], "}"}], ",", " ", "\n", "\t\t", RowBox[{ RowBox[{"\[CapitalDelta]x", " ", "=", " ", RowBox[{ RowBox[{"(", RowBox[{"b", " ", "-", " ", "a"}], ")"}], "/", "n"}]}], ";", "\n", "\t\t", RowBox[{"rects", " ", "=", " ", "\n", " ", RowBox[{"Table", "[", RowBox[{ RowBox[{"Line", "[", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"a", " ", "+", " ", RowBox[{ RowBox[{"(", RowBox[{"i", " ", "-", " ", "1"}], ")"}], "\[CapitalDelta]x"}]}], ",", " ", "\n", " ", "0"}], "}"}], ",", " ", RowBox[{"{", RowBox[{ RowBox[{"a", " ", "+", " ", RowBox[{ RowBox[{"(", RowBox[{"i", " ", "-", " ", "1"}], ")"}], "\[CapitalDelta]x"}]}], ",", " ", "\n", " ", RowBox[{ RowBox[{"Function", "[", RowBox[{ RowBox[{"{", "x", "}"}], ",", " ", RowBox[{"Evaluate", "[", "f", "]"}]}], "]"}], "[", RowBox[{"a", " ", "+", " ", RowBox[{"i", "*", "\[CapitalDelta]x"}]}], "]"}]}], "}"}], ",", " ", RowBox[{"{", RowBox[{ RowBox[{"a", " ", "+", " ", "\n", " ", RowBox[{"i", "*", "\[CapitalDelta]x"}]}], ",", " ", "\n", " ", RowBox[{ RowBox[{"Function", "[", RowBox[{ RowBox[{"{", "x", "}"}], ",", " ", RowBox[{"Evaluate", "[", "f", "]"}]}], "]"}], "[", RowBox[{"a", " ", "+", " ", RowBox[{"i", "*", "\[CapitalDelta]x"}]}], "]"}]}], "}"}], ",", " ", RowBox[{"{", RowBox[{ RowBox[{"a", " ", "+", " ", "\n", " ", RowBox[{"i", "*", "\[CapitalDelta]x"}]}], ",", " ", "0"}], "}"}], ",", " ", RowBox[{"{", RowBox[{ RowBox[{"a", " ", "+", " ", RowBox[{ RowBox[{"(", RowBox[{"i", " ", "-", " ", "1"}], ")"}], "\[CapitalDelta]x"}]}], ",", " ", "\n", " ", "0"}], "}"}]}], "}"}], "]"}], ",", " ", RowBox[{"{", RowBox[{"i", ",", " ", "1", ",", " ", "n"}], "}"}]}], "]"}]}], ";", "\n", "\t\t", RowBox[{"area", " ", "=", " ", RowBox[{ RowBox[{"Plus", " ", "@@", " ", "\n", " ", RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"Function", "[", RowBox[{ RowBox[{"{", "x", "}"}], ",", " ", RowBox[{"Evaluate", "[", "f", "]"}]}], "]"}], "[", "\n", " ", RowBox[{"a", " ", "+", " ", RowBox[{"k", "*", "\[CapitalDelta]x"}]}], "]"}], "*", "\[CapitalDelta]x"}], ",", " ", RowBox[{"{", RowBox[{"k", ",", " ", "1", ",", " ", "n"}], "}"}]}], "]"}]}], " ", "//", " ", "N"}]}], ";", "\n", "\t", "\n", "\t\t", RowBox[{"z", " ", "=", " ", RowBox[{"Plot", "[", RowBox[{ RowBox[{ RowBox[{"Function", "[", RowBox[{ RowBox[{"{", "x", "}"}], ",", " ", RowBox[{"Evaluate", "[", "f", "]"}]}], "]"}], "[", "x", "]"}], ",", " ", RowBox[{"{", RowBox[{"x", ",", " ", "a", ",", " ", "b"}], "}"}]}], "]"}]}], ";", "\n", "\t\t", "\n", "\t", RowBox[{"p", " ", "=", " ", RowBox[{"Min", "[", RowBox[{"0", ",", " ", RowBox[{ RowBox[{"PlotRange", "[", "z", "]"}], "[", RowBox[{"[", RowBox[{"2", ",", " ", "1"}], "]"}], "]"}]}], "]"}]}], ";", " ", RowBox[{"q", " ", "=", " ", RowBox[{"Max", "[", RowBox[{"0", ",", " ", RowBox[{ RowBox[{"PlotRange", "[", "z", "]"}], "[", RowBox[{"[", RowBox[{"2", ",", " ", "2"}], "]"}], "]"}]}], " ", "]"}]}], ";", "\n", "\t\t\t", "\n", "\t\t", RowBox[{"Plot", "[", RowBox[{ RowBox[{ RowBox[{"Function", "[", RowBox[{ RowBox[{"{", "x", "}"}], ",", " ", RowBox[{"Evaluate", "[", "f", "]"}]}], "]"}], "[", "x", "]"}], ",", " ", RowBox[{"{", RowBox[{"x", ",", " ", RowBox[{"a", " ", "-", " ", RowBox[{ RowBox[{"(", RowBox[{"b", " ", "-", " ", "a"}], ")"}], "/", "10"}]}], ",", " ", RowBox[{"b", " ", "+", " ", RowBox[{ RowBox[{"(", RowBox[{"b", " ", "-", " ", "a"}], ")"}], "/", "10"}]}]}], "}"}], ",", " ", "\n", " ", RowBox[{"Evaluate", "[", RowBox[{"Sequence", " ", "@@", " ", RowBox[{"FilterRules", "[", RowBox[{ RowBox[{"{", "opts", "}"}], ",", " ", RowBox[{"Options", "[", "Plot", "]"}]}], "]"}]}], "]"}], ",", " ", RowBox[{"Epilog", " ", "->", " ", RowBox[{"{", RowBox[{"Red", ",", " ", "rects"}], "}"}]}], ",", " ", "\n", " ", RowBox[{"Axes", " ", "->", " ", "True"}], ",", " ", RowBox[{"PlotRange", " ", "->", " ", RowBox[{"{", RowBox[{"p", ",", " ", "q"}], "}"}]}], ",", " ", RowBox[{"PlotStyle", " ", "->", " ", RowBox[{"Thickness", "[", ".01", "]"}]}], ",", " ", "\n", " ", RowBox[{"PlotLabel", " ", "->", "\n", " ", RowBox[{"Style", "[", RowBox[{ RowBox[{"StringForm", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"NumberForm", "[", RowBox[{"area", ",", " ", "4"}], "]"}]}], "]"}], ",", " ", "\n", " ", RowBox[{"FontSize", " ", "->", " ", "20"}], ",", " ", RowBox[{"FontWeight", " ", "->", " ", "\"\\""}]}], " ", "]"}]}]}], "]"}]}]}], "\n", "\t", "]"}]}], "\n", "\t"}], "\n", RowBox[{ RowBox[{ RowBox[{"MidSum", "[", RowBox[{"f_", ",", " ", RowBox[{"{", RowBox[{"x_", ",", " ", "a_", ",", " ", "b_"}], "}"}], ",", " ", "n_", ",", " ", "opts___"}], "]"}], " ", ":=", "\n", "\t", "\n", " ", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ "\[CapitalDelta]x", ",", " ", "rects", ",", " ", "i", ",", " ", "area", ",", " ", "k", ",", " ", "w", ",", " ", "z", ",", " ", "u", ",", " ", "v", ",", " ", "p", ",", " ", "q"}], "}"}], ",", " ", "\n", "\t\t", RowBox[{ RowBox[{"\[CapitalDelta]x", " ", "=", " ", RowBox[{ RowBox[{"(", RowBox[{"b", " ", "-", " ", "a"}], ")"}], "/", "n"}]}], ";", "\n", "\t\t", RowBox[{"rects", " ", "=", " ", "\n", " ", RowBox[{"Table", "[", RowBox[{ RowBox[{"Line", "[", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"a", " ", "+", " ", RowBox[{ RowBox[{"(", RowBox[{"i", " ", "-", " ", "1"}], ")"}], "\[CapitalDelta]x"}]}], ",", " ", "\n", " ", "0"}], "}"}], ",", " ", RowBox[{"{", RowBox[{ RowBox[{"a", " ", "+", " ", RowBox[{ RowBox[{"(", RowBox[{"i", " ", "-", " ", "1"}], ")"}], "\[CapitalDelta]x"}]}], ",", " ", "\n", " ", RowBox[{ RowBox[{"Function", "[", RowBox[{ RowBox[{"{", "x", "}"}], ",", " ", RowBox[{"Evaluate", "[", "f", "]"}]}], "]"}], "[", "\n", " ", RowBox[{"a", " ", "+", " ", RowBox[{ RowBox[{"(", RowBox[{"i", " ", "-", " ", RowBox[{"1", "/", "2"}]}], ")"}], "*", "\[CapitalDelta]x"}]}], "]"}]}], "}"}], ",", " ", RowBox[{"{", RowBox[{ RowBox[{"a", " ", "+", " ", RowBox[{"i", "*", "\[CapitalDelta]x"}]}], ",", " ", "\n", " ", RowBox[{ RowBox[{"Function", "[", RowBox[{ RowBox[{"{", "x", "}"}], ",", " ", RowBox[{"Evaluate", "[", "f", "]"}]}], "]"}], "[", "\n", " ", RowBox[{"a", " ", "+", " ", RowBox[{ RowBox[{"(", RowBox[{"i", " ", "-", " ", RowBox[{"1", "/", "2"}]}], ")"}], "*", "\[CapitalDelta]x"}]}], "]"}]}], "}"}], ",", " ", RowBox[{"{", RowBox[{ RowBox[{"a", " ", "+", " ", RowBox[{"i", "*", "\[CapitalDelta]x"}]}], ",", " ", "\n", " ", "0"}], "}"}], ",", " ", RowBox[{"{", RowBox[{ RowBox[{"a", " ", "+", " ", RowBox[{ RowBox[{"(", RowBox[{"i", " ", "-", " ", "1"}], ")"}], "\[CapitalDelta]x"}]}], ",", " ", "0"}], "}"}]}], "}"}], "]"}], ",", " ", RowBox[{"{", RowBox[{"i", ",", " ", "1", ",", " ", "n"}], "}"}]}], "]"}]}], ";", "\n", "\t\t", RowBox[{"area", " ", "=", " ", RowBox[{ RowBox[{"Plus", " ", "@@", " ", "\n", " ", RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"Function", "[", RowBox[{ RowBox[{"{", "x", "}"}], ",", " ", RowBox[{"Evaluate", "[", "f", "]"}]}], "]"}], "[", "\n", " ", RowBox[{"a", " ", "+", " ", RowBox[{ RowBox[{"(", RowBox[{"k", " ", "-", " ", RowBox[{"1", "/", "2"}]}], ")"}], "*", "\[CapitalDelta]x"}]}], "]"}], "*", "\[CapitalDelta]x"}], ",", " ", RowBox[{"{", RowBox[{"k", ",", " ", "1", ",", " ", "n"}], "}"}]}], "]"}]}], " ", "//", "\n", " ", "N"}]}], ";", "\n", "\t\t", RowBox[{"z", " ", "=", " ", RowBox[{"Plot", "[", RowBox[{ RowBox[{ RowBox[{"Function", "[", RowBox[{ RowBox[{"{", "x", "}"}], ",", " ", RowBox[{"Evaluate", "[", "f", "]"}]}], "]"}], "[", "x", "]"}], ",", " ", RowBox[{"{", RowBox[{"x", ",", " ", "a", ",", " ", "b"}], "}"}]}], "]"}]}], ";", "\n", "\t\t", RowBox[{"p", " ", "=", " ", RowBox[{"Min", "[", RowBox[{"0", ",", " ", RowBox[{ RowBox[{"PlotRange", "[", "z", "]"}], "[", RowBox[{"[", RowBox[{"2", ",", " ", "1"}], "]"}], "]"}]}], "]"}]}], ";", " ", RowBox[{"q", " ", "=", " ", RowBox[{"Max", "[", RowBox[{"0", ",", " ", RowBox[{ RowBox[{"PlotRange", "[", "z", "]"}], "[", RowBox[{"[", RowBox[{"2", ",", " ", "2"}], "]"}], "]"}]}], " ", "]"}]}], ";", "\n", "\t\t\t", "\n", "\t\t", RowBox[{"Plot", "[", RowBox[{ RowBox[{ RowBox[{"Function", "[", RowBox[{ RowBox[{"{", "x", "}"}], ",", " ", RowBox[{"Evaluate", "[", "f", "]"}]}], "]"}], "[", "x", "]"}], ",", " ", RowBox[{"{", RowBox[{"x", ",", " ", RowBox[{"a", " ", "-", " ", RowBox[{ RowBox[{"(", RowBox[{"b", " ", "-", " ", "a"}], ")"}], "/", "10"}]}], ",", " ", RowBox[{"b", " ", "+", " ", RowBox[{ RowBox[{"(", RowBox[{"b", " ", "-", " ", "a"}], ")"}], "/", "10"}]}]}], "}"}], ",", " ", "\n", " ", RowBox[{"Evaluate", "[", RowBox[{"Sequence", " ", "@@", " ", RowBox[{"FilterRules", "[", RowBox[{ RowBox[{"{", "opts", "}"}], ",", " ", RowBox[{"Options", "[", "Plot", "]"}]}], "]"}]}], "]"}], ",", " ", RowBox[{"Epilog", " ", "->", " ", RowBox[{"{", RowBox[{"Red", ",", " ", "rects"}], "}"}]}], ",", " ", "\n", " ", RowBox[{"Axes", " ", "->", " ", "True"}], ",", " ", RowBox[{"PlotRange", " ", "->", " ", RowBox[{"{", RowBox[{"p", ",", " ", "q"}], "}"}]}], ",", " ", RowBox[{"PlotStyle", " ", "->", " ", RowBox[{"Thickness", "[", ".01", "]"}]}], ",", " ", "\n", " ", RowBox[{"PlotLabel", " ", "->", "\n", " ", RowBox[{"Style", "[", RowBox[{ RowBox[{"StringForm", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"NumberForm", "[", RowBox[{"area", ",", " ", "4"}], "]"}]}], "]"}], ",", " ", "\n", " ", RowBox[{"FontSize", " ", "->", " ", "20"}], ",", " ", RowBox[{"FontWeight", " ", "->", " ", "\"\\""}]}], " ", "]"}]}]}], "]"}]}]}], "\n", "\t", "]"}]}], "\n", "\t"}], "\n", RowBox[{ RowBox[{"TrapSum", "[", RowBox[{"f_", ",", " ", RowBox[{"{", RowBox[{"x_", ",", " ", "a_", ",", " ", "b_"}], "}"}], ",", " ", "n_", ",", " ", "opts___"}], "]"}], " ", ":=", "\n", "\t", "\n", " ", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ "\[CapitalDelta]x", ",", " ", "traps", ",", " ", "i", ",", " ", "area", ",", " ", "k", ",", " ", "w", ",", " ", "z", ",", " ", "u", ",", " ", "v", ",", " ", "p", ",", " ", "q"}], "}"}], ",", " ", "\n", "\t\t", RowBox[{ RowBox[{"\[CapitalDelta]x", " ", "=", " ", RowBox[{ RowBox[{"(", RowBox[{"b", " ", "-", " ", "a"}], ")"}], "/", "n"}]}], ";", "\n", "\t\t", RowBox[{"traps", " ", "=", " ", "\n", " ", RowBox[{"Table", "[", RowBox[{ RowBox[{"Line", "[", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"a", " ", "+", " ", RowBox[{ RowBox[{"(", RowBox[{"i", " ", "-", " ", "1"}], ")"}], "\[CapitalDelta]x"}]}], ",", " ", "\n", " ", "0"}], "}"}], ",", " ", RowBox[{"{", RowBox[{ RowBox[{"a", " ", "+", " ", RowBox[{ RowBox[{"(", RowBox[{"i", " ", "-", " ", "1"}], ")"}], "\[CapitalDelta]x"}]}], ",", " ", "\n", " ", RowBox[{ RowBox[{"Function", "[", RowBox[{ RowBox[{"{", "x", "}"}], ",", " ", RowBox[{"Evaluate", "[", "f", "]"}]}], "]"}], "[", RowBox[{"a", " ", "+", " ", RowBox[{ RowBox[{"(", RowBox[{"i", " ", "-", " ", "1"}], ")"}], "*", "\[CapitalDelta]x"}]}], "]"}]}], "}"}], ",", " ", RowBox[{"{", RowBox[{ RowBox[{"a", " ", "+", " ", "\n", " ", RowBox[{"i", "*", "\[CapitalDelta]x"}]}], ",", " ", "\n", " ", RowBox[{ RowBox[{"Function", "[", RowBox[{ RowBox[{"{", "x", "}"}], ",", " ", RowBox[{"Evaluate", "[", "f", "]"}]}], "]"}], "[", RowBox[{"a", " ", "+", " ", RowBox[{"i", "*", "\[CapitalDelta]x"}]}], "]"}]}], "}"}], ",", " ", RowBox[{"{", RowBox[{ RowBox[{"a", " ", "+", " ", "\n", " ", RowBox[{"i", "*", "\[CapitalDelta]x"}]}], ",", " ", "0"}], "}"}], ",", " ", RowBox[{"{", RowBox[{ RowBox[{"a", " ", "+", " ", RowBox[{ RowBox[{"(", RowBox[{"i", " ", "-", " ", "1"}], ")"}], "\[CapitalDelta]x"}]}], ",", " ", "\n", " ", "0"}], "}"}]}], "}"}], "]"}], ",", " ", RowBox[{"{", RowBox[{"i", ",", " ", "1", ",", " ", "n"}], "}"}]}], "]"}]}], ";", "\n", "\t\t", RowBox[{"area", " ", "=", " ", RowBox[{ RowBox[{"Plus", " ", "@@", " ", "\n", " ", RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"Function", "[", RowBox[{ RowBox[{"{", "x", "}"}], ",", " ", RowBox[{"Evaluate", "[", "f", "]"}]}], "]"}], "[", RowBox[{"a", " ", "+", " ", RowBox[{ RowBox[{"(", RowBox[{"k", " ", "-", " ", "1"}], ")"}], "\[CapitalDelta]x"}]}], "]"}], " ", "+", " ", "\n", " ", RowBox[{ RowBox[{"Function", "[", RowBox[{ RowBox[{"{", "x", "}"}], ",", " ", RowBox[{"Evaluate", "[", "f", "]"}]}], "]"}], "[", "\n", " ", RowBox[{"a", " ", "+", " ", RowBox[{"k", "*", "\[CapitalDelta]x"}]}], "]"}]}], ")"}], "*", RowBox[{"\[CapitalDelta]x", "/", "2"}]}], ",", " ", RowBox[{"{", RowBox[{"k", ",", " ", "1", ",", " ", "n"}], "}"}]}], "]"}]}], " ", "//", "\n", " ", "N"}]}], ";", "\n", "\t\t", RowBox[{"z", " ", "=", " ", RowBox[{"Plot", "[", RowBox[{ RowBox[{ RowBox[{"Function", "[", RowBox[{ RowBox[{"{", "x", "}"}], ",", " ", RowBox[{"Evaluate", "[", "f", "]"}]}], "]"}], "[", "x", "]"}], ",", " ", RowBox[{"{", RowBox[{"x", ",", " ", "a", ",", " ", "b"}], "}"}]}], "]"}]}], ";", "\n", "\t\t", RowBox[{"p", " ", "=", " ", RowBox[{"Min", "[", RowBox[{"0", ",", " ", RowBox[{ RowBox[{"PlotRange", "[", "z", "]"}], "[", RowBox[{"[", RowBox[{"2", ",", " ", "1"}], "]"}], "]"}]}], "]"}]}], ";", " ", RowBox[{"q", " ", "=", " ", RowBox[{"Max", "[", RowBox[{"0", ",", " ", RowBox[{ RowBox[{"PlotRange", "[", "z", "]"}], "[", RowBox[{"[", RowBox[{"2", ",", " ", "2"}], "]"}], "]"}]}], " ", "]"}]}], ";", "\n", "\t", RowBox[{"Plot", "[", RowBox[{ RowBox[{ RowBox[{"Function", "[", RowBox[{ RowBox[{"{", "x", "}"}], ",", " ", RowBox[{"Evaluate", "[", "f", "]"}]}], "]"}], "[", "x", "]"}], ",", " ", RowBox[{"{", RowBox[{"x", ",", " ", RowBox[{"a", " ", "-", " ", RowBox[{ RowBox[{"(", RowBox[{"b", " ", "-", " ", "a"}], ")"}], "/", "10"}]}], ",", " ", RowBox[{"b", " ", "+", " ", RowBox[{ RowBox[{"(", RowBox[{"b", " ", "-", " ", "a"}], ")"}], "/", "10"}]}]}], "}"}], ",", " ", "\n", " ", RowBox[{"Evaluate", "[", RowBox[{"Sequence", " ", "@@", " ", RowBox[{"FilterRules", "[", RowBox[{ RowBox[{"{", "opts", "}"}], ",", " ", RowBox[{"Options", "[", "Plot", "]"}]}], "]"}]}], "]"}], ",", " ", RowBox[{"Epilog", " ", "->", " ", RowBox[{"{", RowBox[{"Red", ",", " ", "traps"}], "}"}]}], ",", " ", "\n", " ", RowBox[{"Axes", " ", "->", " ", "True"}], ",", " ", RowBox[{"PlotRange", " ", "->", " ", RowBox[{"{", RowBox[{"p", ",", " ", "q"}], "}"}]}], ",", " ", RowBox[{"PlotStyle", " ", "->", " ", RowBox[{"Thickness", "[", ".01", "]"}]}], ",", " ", "\n", " ", RowBox[{"PlotLabel", " ", "->", "\n", " ", RowBox[{"Style", "[", RowBox[{ RowBox[{"StringForm", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"NumberForm", "[", RowBox[{"area", ",", " ", "4"}], "]"}]}], "]"}], ",", " ", "\n", " ", RowBox[{"FontSize", " ", "->", " ", "20"}], ",", " ", RowBox[{"FontWeight", " ", "->", " ", "\"\\""}]}], " ", "]"}]}]}], "]"}]}]}], "\n", "\t", "]"}]}]}], "Input", InitializationCell->True] }, Closed]] }, Open ]] }, WindowSize->{808, 724}, WindowMargins->{{Automatic, 737}, {Automatic, 120}}, FrontEndVersion->"11.0 for Mac OS X x86 (32-bit, 64-bit Kernel) (September \ 21, 2016)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[580, 22, 170, 3, 92, "Title"], Cell[753, 27, 151, 4, 49, "Subsubtitle"], Cell[907, 33, 379, 7, 68, "Text"], Cell[1289, 42, 383, 10, 75, "Input"], Cell[CellGroupData[{ Cell[1697, 56, 92, 1, 64, "Section"], Cell[1792, 59, 695, 16, 32, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[2524, 80, 95, 1, 64, "Section"], Cell[2622, 83, 721, 16, 32, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[3380, 104, 94, 1, 64, "Section"], Cell[3477, 107, 691, 16, 32, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[4205, 128, 99, 1, 64, "Section"], Cell[4307, 131, 215, 4, 30, "Text"], Cell[4525, 137, 694, 16, 32, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[5256, 158, 103, 1, 64, "Section"], Cell[5362, 161, 28838, 716, 2338, "Input", InitializationCell->True] }, Closed]] }, Open ]] } ] *)