(* 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[ 12900, 444] NotebookOptionsPosition[ 11554, 393] NotebookOutlinePosition[ 11956, 410] CellTagsIndexPosition[ 11913, 407] WindowFrame->Normal ContainsDynamic->False*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell[" Project - Riemann Sum", "Title", CellChangeTimes->{{3.449681240091041*^9, 3.449681247628324*^9}}], Cell["\<\ In this project you will use some of the graphics primitives to create a \ function that produces a nice animation illustrating the connection between \ Riemann sums, the area underneath the curve and the definite integral.\ \>", "Text", FontWeight->"Bold"], Cell[CellGroupData[{ Cell["Overview", "Subsection"], Cell[TextData[{ "When introducing integration, one starts with the idea of the area \ underneath a curve. To approximate this area, one draws a sequence of \ approximating rectangles, whose height is related to the function. The \ general approach is to divide the interval [a, b], for which the area under \ the curve is to be determined, into ", StyleBox["n", FontSlant->"Italic"], " equally long intervals, each of length (", StyleBox["b-a", FontSlant->"Italic"], ")", StyleBox["/n", FontSlant->"Italic"], ". These subintervals form the base of their respective rectangle. Then one \ of three ways can be chosen to determine the height of the rectangle:\n\t1) \ function value at left endpoint of the subinterval\n\t2) function value at \ the midpoint of the subinterval\n\t3) function value at the right endpoint of \ the subinterval.\n\nIn each case, the area under the curve is approximated by \ the sum of the areas of the rectangles. As ", StyleBox["n\[Rule]\[Infinity]", FontSlant->"Italic"], ", the Riemann sum ", Cell[BoxData[ FormBox[ RowBox[{ UnderoverscriptBox["\[Sum]", RowBox[{"k", "=", "0"}], "n"], RowBox[{ RowBox[{"f", "(", SubsuperscriptBox["x", "k", "*"], ")"}], SubscriptBox["\[CapitalDelta]x", RowBox[{"k", " "}]]}]}], TraditionalForm]]], "approaches the area under the curve, and this limit is defined as the \ integral ", Cell[BoxData[ FormBox[ RowBox[{ SubsuperscriptBox["\[Integral]", "a", "b"], RowBox[{ RowBox[{"f", "(", "x", ")"}], RowBox[{"\[DifferentialD]", "x"}]}]}], TraditionalForm]]], ".\n\nYou are to write a function that has as inputs the interval limits ", StyleBox["a", FontSlant->"Italic"], " and ", StyleBox["b", FontSlant->"Italic"], ". You can assume that the function ", StyleBox["f", FontSlant->"Italic"], " itself is defined before the function ", StyleBox["RiemannAnimation", FontWeight->"Bold"], " is called. Your function will use the left endpoint method. As output it \ will print a table which indicates the value of ", StyleBox["n ", FontSlant->"Italic"], "together with the approximate area and the difference \[CapitalDelta] \ between the approximation and the actual area, where the latter is computed \ from the integral (and is the same for all values of ", StyleBox["n", FontSlant->"Italic"], "). \n\n\t\t", Cell[BoxData[GridBox[{ {"n", RowBox[{"approx", ".", " ", "area"}], "\[CapitalDelta]"}, {"10", "\[Placeholder]", "\[Placeholder]"}, {"20", "\[Placeholder]", "\[Placeholder]"}, {"\[VerticalEllipsis]", "\[Placeholder]", "\[Placeholder]"} }, GridBoxDividers->{ "Columns" -> {{False}}, "ColumnsIndexed" -> {}, "Rows" -> {False, AbsoluteThickness[0.5], {False}, False}, "RowsIndexed" -> {}}]]], "\n\t\t\nSecondly, your function should create 10 graphs (for ", StyleBox["n", FontSlant->"Italic"], " = 10, 20,..., 100) of the function together with the approximating \ rectangles to be used for an animation. " }], "Text", CellChangeTimes->{{3.418766032214899*^9, 3.418766033499754*^9}, { 3.418766191278943*^9, 3.41876625530163*^9}, {3.4201623342014303`*^9, 3.420162334438436*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["\<\ Details (possible way to break down the task, but you may choose to do it \ differently)\ \>", "Subsection", CellChangeTimes->{{3.41876613122019*^9, 3.418766148593437*^9}}], Cell["\<\ The project can be broken down into these smaller steps, which result from \ thinking about which pieces are needed to complete the whole.\ \>", "Text"], Cell[CellGroupData[{ Cell["Step 1: Creating the subintervals", "Subsubsection"], Cell[TextData[{ "When drawing the rectangles under the function, we usually divide the given \ interval [a, b] into ", StyleBox["n", FontSlant->"Italic"], " subintervals\n\n\t[", Cell[BoxData[ FormBox[ SubscriptBox["x", "0"], TraditionalForm]]], ", ", Cell[BoxData[ FormBox[ SubscriptBox["x", "1"], TraditionalForm]]], "], [", Cell[BoxData[ FormBox[ SubscriptBox["x", "1"], TraditionalForm]]], ", ", Cell[BoxData[ FormBox[ SubscriptBox["x", "2"], TraditionalForm]]], "], [", Cell[BoxData[ FormBox[ SubscriptBox["x", "2"], TraditionalForm]]], ", ", Cell[BoxData[ FormBox[ SubscriptBox["x", "3"], TraditionalForm]]], "], ...., [", Cell[BoxData[ FormBox[ SubscriptBox["x", RowBox[{"n", "-", "2"}]], TraditionalForm]]], ", ", Cell[BoxData[ FormBox[ SubscriptBox["x", RowBox[{"n", "-", "1"}]], TraditionalForm]]], "], [", Cell[BoxData[ FormBox[ SubscriptBox["x", RowBox[{"n", "-", "1"}]], TraditionalForm]]], ", ", Cell[BoxData[ FormBox[ SubscriptBox["x", "n"], TraditionalForm]]], "], \n\nwhere ", Cell[BoxData[ FormBox[ SubscriptBox["x", "0"], TraditionalForm]]], "= a, and ", Cell[BoxData[ FormBox[ RowBox[{ RowBox[{ SubscriptBox["x", "n"], " ", "=", " ", RowBox[{"b", "."}]}], ",", " ", RowBox[{ RowBox[{"and", " ", SubscriptBox["x", "i"]}], "="}]}], TraditionalForm]]], Cell[BoxData[ FormBox[ RowBox[{ SubscriptBox["x", "0"], "+", RowBox[{ RowBox[{"i", "(", FractionBox[ RowBox[{"b", "-", "a"}], "n"], ")"}], "."}]}], TraditionalForm]]], " Create a list of subintervals for given ", StyleBox["a, b, ", FontSlant->"Italic"], "and ", StyleBox["n", FontSlant->"Italic"], ".", " " }], "Text"] }, Open ]], Cell[CellGroupData[{ Cell["Step 2: Creating a single rectangle", "Subsubsection"], Cell[TextData[{ "Now that the endpoints of the subintervals have been computed, we need to \ create a rectangle for each subinterval. The width of the rectangle is the \ length of each subinterval, i.e. ", StyleBox["w", FontSlant->"Italic"], " = ", Cell[BoxData[ FormBox[ StyleBox[ FractionBox[ RowBox[{"b", "-", "a"}], "n"], FontSize->15], TraditionalForm]]], ", and the height is determined by the method. Let's consider the \ subinterval with endpoints ", Cell[BoxData[ FormBox[ SubscriptBox["x", RowBox[{"i", " "}]], TraditionalForm]]], "and ", Cell[BoxData[ FormBox[ RowBox[{ SubscriptBox["x", RowBox[{"i", "+", "1"}]], "."}], TraditionalForm]]], " The height ", StyleBox["h", FontSlant->"Italic"], " of the rectangle is given by ", StyleBox["h = f(", FontSlant->"Italic"], Cell[BoxData[ FormBox[ SubscriptBox["x", "i"], TraditionalForm]]], ").\n\nWrite a function that draws a rectangle of width ", StyleBox["w", FontSlant->"Italic"], " and height ", StyleBox["f(", FontSlant->"Italic"], Cell[BoxData[ FormBox[ SubscriptBox["x", "i"], TraditionalForm]]], ") above the interval [", Cell[BoxData[ FormBox[ RowBox[{ RowBox[{ RowBox[{ SubscriptBox["x", "i"], ",", SubscriptBox["x", RowBox[{"i", "+", "1"}]]}], "]"}], " "}], TraditionalForm]]], " in a color of your choice. You should use the position of the lower left \ corner of the rectangle and the height of the rectangle as variables for your \ function, and assume that the other quantities (", StyleBox["f, a, b,", FontSlant->"Italic"], " and ", StyleBox["n", FontSlant->"Italic"], ") are known outside of your function." }], "Text", CellChangeTimes->{{3.418766160503106*^9, 3.418766172589013*^9}, { 3.418766269847672*^9, 3.41876628442306*^9}}], Cell[BoxData[ RowBox[{" ", StyleBox[ RowBox[{ RowBox[{"drawRectangle", "[", RowBox[{"llcpos_", ",", " ", "height_"}], "]"}], ":="}], FontWeight->"Bold"]}]], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["Step 3: Creating all the rectangles", "Subsubsection"], Cell[TextData[{ "Once your function ", StyleBox["drawRectangle", FontWeight->"Bold"], " works, you can use the built-in function ", StyleBox["Map", FontWeight->"Bold"], " to apply the function easily to a list consisting of pairs {left \ endpoint,", StyleBox[" f", FontSlant->"Italic"], "(left endpoint)} (which you can derive from the list of all the endpoints \ created in Step 1). You have now created the rectangles that approximate the \ area under the curve. Give this graphics object a name." }], "Text"] }, Open ]], Cell[CellGroupData[{ Cell["\<\ Step 4: Combining the rectangle graph with a graph of the function and \ computing the approximate area\ \>", "Subsubsection"], Cell[TextData[{ "Combine the above graphics object with a graph of the function, which \ should be drawn slightly thicker in a color of your choice. Also compute the \ total area for all the rectangles, given by ", Cell[BoxData[ FormBox[ RowBox[{ RowBox[{"w", RowBox[{ UnderoverscriptBox["\[Sum]", RowBox[{"k", "=", "0"}], "n"], RowBox[{"f", "(", SubsuperscriptBox["x", "k", "\[Placeholder]"], ")"}]}]}], ","}], TraditionalForm]]], " which is the approximate area under the curve. You have now created all \ the pieces for a function that uses the left endpoint method for \ approximation." }], "Text", CellChangeTimes->{{3.4187663215306187`*^9, 3.418766337594346*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["Step 5: Putting the pieces together", "Subsubsection"], Cell[TextData[{ "Now you can combine all the different pieces into a function called ", StyleBox["Riemann Animation[a_,b_]", FontWeight->"Bold"], " which uses the left endpoint method to create a sequence of graphs of the \ function together with the approximating rectangles, and also prints out the \ table described above. You can assume that the function ", StyleBox["f", FontSlant->"Italic"], " is given outside the function ", StyleBox["Riemann Animation[a_,b_]", FontWeight->"Bold"], "." }], "Text", CellChangeTimes->{{3.418766355410693*^9, 3.4187663767003098`*^9}, { 3.4201623544280367`*^9, 3.42016241985045*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["Step 6: Usage statement and error checking", "Subsubsection", CellChangeTimes->{{3.4187663851506777`*^9, 3.4187663861411057`*^9}}], Cell[TextData[{ "Write a usage statement for the function ", StyleBox["RiemannAnimation ", FontWeight->"Bold"], "and make sure your function behaves properly when given bad input (i.e., \ the lower limit ", StyleBox["a ", FontSlant->"Italic"], "is bigger than upper limit ", StyleBox["b", FontSlant->"Italic"], ") or gives an error statement in that case. " }], "Text", CellChangeTimes->{ 3.41876639535145*^9, {3.420162430934381*^9, 3.420162446974051*^9}}] }, Open ]] }, Open ]] }, Open ]] }, WindowSize->{772, 518}, WindowMargins->{{40, Automatic}, {Automatic, 5}}, PrintingCopies->1, PrintingPageRange->{Automatic, Automatic}, FrontEndVersion->"6.0 for Mac OS X PowerPC (32-bit) (April 20, 2007)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[590, 23, 105, 1, 76, "Title"], Cell[698, 26, 268, 5, 41, "Text"], Cell[CellGroupData[{ Cell[991, 35, 30, 0, 34, "Subsection"], Cell[1024, 37, 3212, 82, 374, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[4273, 124, 183, 4, 34, "Subsection"], Cell[4459, 130, 162, 3, 41, "Text"], Cell[CellGroupData[{ Cell[4646, 137, 58, 0, 25, "Subsubsection"], Cell[4707, 139, 1775, 78, 98, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[6519, 222, 60, 0, 25, "Subsubsection"], Cell[6582, 224, 1836, 63, 129, "Text"], Cell[8421, 289, 185, 6, 27, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[8643, 300, 60, 0, 25, "Subsubsection"], Cell[8706, 302, 524, 14, 56, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[9267, 321, 136, 3, 25, "Subsubsection"], Cell[9406, 326, 721, 18, 63, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[10164, 349, 60, 0, 25, "Subsubsection"], Cell[10227, 351, 638, 15, 56, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[10902, 371, 137, 1, 25, "Subsubsection"], Cell[11042, 374, 472, 14, 41, "Text"] }, Open ]] }, Open ]] }, Open ]] } ] *) (* End of internal cache information *)