(* 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[ 9335, 270] NotebookOptionsPosition[ 8848, 249] NotebookOutlinePosition[ 9189, 264] CellTagsIndexPosition[ 9146, 261] WindowFrame->Normal ContainsDynamic->False*) (* Beginning of Notebook Content *) Notebook[{ Cell[TextData[{ "This notebook contains two routines, lefthandsum and righthandsum, which \ compute and display the corresponding Riemann sums for any function you \ enter, hence estimating the definite integral of that function on a given \ interval. \n\nHere's how to use it:\n1. \"Activate\" these two routines by \ putting your cursor anywhere on them and then pressing Shift-enter as usual \ (do this for each of the two). \tThere will be no output at this time.\n2. \ Now OPEN A NEW NOTEBOOK (for your output) from the File menu. Define the \ function you want to look at and then invoke the routine you want including \ the endpoints of the interval and the number of subdivisions you want. For \ example, to see the lefthand sums for the function ", Cell[BoxData[ FormBox[ SuperscriptBox["x", "2"], TraditionalForm]]], " on the interval [0, 6] divided up into 12 parts, type:\n\t\tf[x_] := x^2\n\ \t\tlefthandsum[f, {x, 0 ,6, 12}]\n" }], "Subsection", CellChangeTimes->{{3.417427577610439*^9, 3.417427719066702*^9}, { 3.417427803310072*^9, 3.417427831219014*^9}}], Cell[CellGroupData[{ Cell["Lefthand Riemann sums ", "Subsection"], Cell[BoxData[ RowBox[{"\[IndentingNewLine]", RowBox[{ RowBox[{"lefthandsum", "[", RowBox[{"f_", ",", RowBox[{"{", RowBox[{"x_", ",", "a_", ",", "b_", ",", "n_"}], "}"}]}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ "\[CapitalDelta]x", ",", "i", ",", "pic", ",", "plt", ",", "pts", ",", "values", ",", "ans"}], "}"}], ",", RowBox[{ RowBox[{"\[CapitalDelta]x", "=", FractionBox[ RowBox[{"(", RowBox[{"b", "-", "a"}], ")"}], "n"]}], ";", "\n", "\t\t", RowBox[{"pts", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"a", "+", RowBox[{"i", "*", "\[CapitalDelta]x"}]}], ",", RowBox[{"{", RowBox[{"i", ",", "0", ",", "n"}], "}"}]}], "]"}]}], ";", RowBox[{"values", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"f", "[", RowBox[{"pts", "[", RowBox[{"[", "i", "]"}], "]"}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{"n", "+", "1"}]}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"ans", "=", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"Apply", "[", RowBox[{"Plus", ",", "values"}], "]"}], "-", RowBox[{"values", "[", RowBox[{"[", RowBox[{"n", "+", "1"}], "]"}], "]"}]}], ")"}], " ", "\[CapitalDelta]x"}]}], ";", "\n", "\t\t", RowBox[{"pic", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"Line", "[", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"pts", "[", RowBox[{"[", "i", "]"}], "]"}], ",", "0"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"pts", "[", RowBox[{"[", "i", "]"}], "]"}], ",", RowBox[{"values", "[", RowBox[{"[", "i", "]"}], "]"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"pts", "[", RowBox[{"[", RowBox[{"i", "+", "1"}], "]"}], "]"}], ",", RowBox[{"values", "[", RowBox[{"[", "i", "]"}], "]"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"pts", "[", RowBox[{"[", RowBox[{"i", "+", "1"}], "]"}], "]"}], ",", "0"}], "}"}]}], "}"}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "n"}], "}"}]}], "]"}]}], ";", "\n", "\t\t\t\t", RowBox[{"plt", "=", RowBox[{"Plot", "[", RowBox[{ RowBox[{"f", "[", "x", "]"}], ",", RowBox[{"{", RowBox[{"x", ",", "a", ",", "b"}], "}"}], ",", RowBox[{"PlotRange", "\[Rule]", "All"}], ",", RowBox[{"DisplayFunction", "->", "Identity"}]}], "]"}]}], ";", RowBox[{"Print", "[", RowBox[{ RowBox[{"N", "[", "ans", "]"}], " ", "\"\< is our estimate.\>\""}], "]"}], ";", "\n", "\t\t\t\t", RowBox[{"Show", "[", RowBox[{"plt", ",", RowBox[{"Graphics", "[", "pic", "]"}], ",", RowBox[{"DisplayFunction", "->", "$DisplayFunction"}]}], "]"}]}]}], " ", "]"}]}]}]], "Input", CellChangeTimes->{{3.4174265686018724`*^9, 3.417426572527109*^9}, { 3.417426679014713*^9, 3.417426681541125*^9}, 3.417426767956969*^9, { 3.417426936787197*^9, 3.4174269443978167`*^9}, {3.417427038603505*^9, 3.4174270433346367`*^9}, {3.417427073429023*^9, 3.417427084739875*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["\<\ Righthand Riemann sums \ \>", "Subsection"], Cell[BoxData[ RowBox[{ RowBox[{"righthandsum", "[", RowBox[{"f_", ",", RowBox[{"{", RowBox[{"x_", ",", "a_", ",", "b_", ",", "n_"}], "}"}]}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ "\[CapitalDelta]", ",", "i", ",", "pic", ",", "plt", ",", "pts", ",", "values", ",", "ans"}], "}"}], ",", RowBox[{ RowBox[{"\[CapitalDelta]x", "=", FractionBox[ RowBox[{"(", RowBox[{"b", "-", "a"}], ")"}], "n"]}], ";", "\n", "\t\t", RowBox[{"pts", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"a", "+", RowBox[{"i", "*", "\[CapitalDelta]x"}]}], ",", RowBox[{"{", RowBox[{"i", ",", "0", ",", "n"}], "}"}]}], "]"}]}], ";", RowBox[{"values", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"f", "[", RowBox[{"pts", "[", RowBox[{"[", "i", "]"}], "]"}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{"n", "+", "1"}]}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"ans", "=", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"Apply", "[", RowBox[{"Plus", ",", "values"}], "]"}], "-", RowBox[{"values", "[", RowBox[{"[", "1", "]"}], "]"}]}], ")"}], " ", "\[CapitalDelta]x"}]}], ";", "\n", "\t\t", RowBox[{"pic", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"Line", "[", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"pts", "[", RowBox[{"[", "i", "]"}], "]"}], ",", "0"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"pts", "[", RowBox[{"[", "i", "]"}], "]"}], ",", RowBox[{"values", "[", RowBox[{"[", RowBox[{"i", "+", "1"}], "]"}], "]"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"pts", "[", RowBox[{"[", RowBox[{"i", "+", "1"}], "]"}], "]"}], ",", RowBox[{"values", "[", RowBox[{"[", RowBox[{"i", "+", "1"}], "]"}], "]"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"pts", "[", RowBox[{"[", RowBox[{"i", "+", "1"}], "]"}], "]"}], ",", "0"}], "}"}]}], "}"}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "n"}], "}"}]}], "]"}]}], ";", "\n", "\t\t\t\t", RowBox[{"plt", "=", RowBox[{"Plot", "[", RowBox[{ RowBox[{"f", "[", "x", "]"}], ",", RowBox[{"{", RowBox[{"x", ",", "a", ",", "b"}], "}"}], ",", RowBox[{"PlotRange", "\[Rule]", "All"}], ",", RowBox[{"DisplayFunction", "->", "Identity"}]}], "]"}]}], ";", RowBox[{"Print", "[", RowBox[{ RowBox[{"N", "[", "ans", "]"}], " ", "\"\< is our estimate.\>\""}], "]"}], ";", "\n", "\t\t\t\t", RowBox[{"Show", "[", RowBox[{"plt", ",", RowBox[{"Graphics", "[", "pic", "]"}], ",", RowBox[{"DisplayFunction", "->", "$DisplayFunction"}]}], "]"}]}]}], " ", "]"}]}]], "Input", CellChangeTimes->{{3.417427247180629*^9, 3.417427276392576*^9}}] }, Open ]] }, WindowSize->{639, 472}, WindowMargins->{{73, Automatic}, {Automatic, 0}}, FrontEndVersion->"6.0 for Microsoft Windows (32-bit) (April 20, 2007)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[568, 21, 1082, 18, 310, "Subsection"], Cell[CellGroupData[{ Cell[1675, 43, 44, 0, 28, "Subsection"], Cell[1722, 45, 3663, 97, 332, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[5422, 147, 55, 3, 53, "Subsection"], Cell[5480, 152, 3352, 94, 312, "Input"] }, Open ]] } ] *) (* End of internal cache information *)