(*********************************************************************** Mathematica-Compatible Notebook This notebook can be used on any computer system with Mathematica 3.0, MathReader 3.0, or any compatible application. The data for the notebook starts with the line of stars above. To get the notebook into a Mathematica-compatible application, do one of the following: * Save the data starting with the line of stars above into a file with a name ending in .nb, then open the file inside the application; * Copy the data starting with the line of stars above to the clipboard, then use the Paste menu command inside the application. Data for notebooks contains only printable 7-bit ASCII and can be sent directly in email or through ftp in text mode. Newlines can be CR, LF or CRLF (Unix, Macintosh or MS-DOS style). NOTE: If you modify the data for this notebook not in a Mathematica- compatible application, you must delete the line below containing the word CacheID, otherwise Mathematica-compatible applications may try to use invalid cache data. For more information on notebooks and Mathematica-compatible applications, contact Wolfram Research: web: http://www.wolfram.com email: info@wolfram.com phone: +1-217-398-0700 (U.S.) Notebook reader applications are available free of charge from Wolfram Research. ***********************************************************************) (*CacheID: 232*) (*NotebookFileLineBreakTest NotebookFileLineBreakTest*) (*NotebookOptionsPosition[ 47043, 1513]*) (*NotebookOutlinePosition[ 47944, 1542]*) (* CellTagsIndexPosition[ 47900, 1538]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell[TextData["Simpson's Rule\[LongDash]I:\nGeometry and derivation"], "Title"], Cell["\<\ By Robin Sue Sanders, Spring 1998, revised Spring 1999 copyright 1999\ \>", "Subtitle", TextAlignment->Center], Cell[CellGroupData[{ Cell["Idea", "Section"], Cell["\<\ Since curves are curved, it seems silly to use straight line \ segments to approximate them. Something that is curved would work better. \ Of the functions that you've worked with, parabolas are the simplest kind of \ curve that truly are curved. Unfortunately, we have to figure out how to get \ a set of parabolas to do what we want. That requires three steps: Finding an algebraic representation of the area \ under a parabolic \"slice\" (i.e. one that does not require calculus); \ finding a way to approximate the curve with a set of parabolas; and putting \ the first two steps together into a formula that we can program into the \ computer.\ \>", "Text"] }, Closed]], Cell[CellGroupData[{ Cell[TextData[ "Area of a parabolic slice\[LongDash]an alternate view"], "Section"], Cell[TextData[{ "A useful geometric fact is that we can find the area under a parabola and \ over the interval ", Cell[BoxData[ \(TraditionalForm\`\([x\_1, \ x\_3]\)\)]], " either through integration (using the fundametal theorem of calculus) or \ through some algebra and geometry (using the parabola's y-values at ", Cell[BoxData[ \(TraditionalForm\`x\_1\)]], ", ", Cell[BoxData[ \(TraditionalForm\`x\_2\)]], ", and ", Cell[BoxData[ \(TraditionalForm\`x\_3\)]], " where ", Cell[BoxData[ \(TraditionalForm\`x\_2\)]], " is the midpoint of the inverval ", Cell[BoxData[ \(TraditionalForm\`\([x\_1, \ x\_3]\)\)]], "). " }], "Text"], Cell["A typical parabola's formula is given by:", "Text"], Cell[BoxData[{ \(Clear[a, b, c]\), \(parabola[x_]\ := \ a\ + \ b\ x\ + \ c\ x\^2\)}], "Input"], Cell[TextData[{ "Using the fundamental theorem of calculus, the area under the parabola and \ over the x-interval ", Cell[BoxData[ \(TraditionalForm\`\([x\_1, \ x\_3]\)\)]], " is given by ", Cell[BoxData[ \(TraditionalForm \`\[Integral]\_x\_1\%x\_3 parabola[x] \[DifferentialD]x\)]], ": " }], "Text"], Cell[BoxData[{ \(Clear[x1, x2, \ \ x3]\), \(integralarea\ = \tIntegrate[parabola[x], \ {x, x1, x3}]\)}], "Input"], Cell[TextData[{ "The area under a parabola can also be found using algebra and geometry. \ An old formula (but probably unfamiliar one) states that the area under the \ parabola ", Cell[BoxData[ \(TraditionalForm\`y\ = \ a\ + \ b\ x\ + \ c\ x\^2\)]], " and over the interval ", Cell[BoxData[ \(TraditionalForm\`\([x\_1, \ x\_3]\)\)]], " is given by \n\t\t\n\t\t", Cell[BoxData[ \(TraditionalForm \`1\/3\ \((\ parabola[x\_1]\ + \ 4\ parabola[x\_2]\ + \ parabola[x\_3])\)\ \((x\_3 - \ x\_1)\)\/2\)], FontSize->15], "\n\nwhere ", Cell[BoxData[ \(TraditionalForm\`\(x\_2 = \ \(x\_1\ + \)\ \)\)]], Cell[BoxData[ \(TraditionalForm\`\((x\_3 - \ x\_1)\)\/2\)]], " is the midpoint of the x-interval ", Cell[BoxData[ \(TraditionalForm\`\([x\_1, \ x\_3]\)\)]], ":" }], "Text"], Cell[BoxData[ \(x2\ = \ x1\ + \ \((x3\ - \ x1)\)/2; \n geometricarea\ = \ \((1/3)\) \((parabola[x1]\ + \ 4\ parabola[x2]\ + \ parabola[x3])\)\ \((x3 - x1)\)/2\)], "Input"], Cell[TextData[{ "These two formulations of area superficially look different, but we can \ show they are the same by asking ", StyleBox["Mathematica", FontSlant->"Italic"], " to simplify their difference:" }], "Text"], Cell[BoxData[ \(Simplify[integralarea\ - \ geometricarea]\)], "Input"], Cell[TextData[{ "So we can use \t\t\n\t\t", Cell[BoxData[ \(TraditionalForm \`1\/3\ \((\ parabola[x\_1]\ + \ 4\ parabola[midpoint]\ + \ parabola[x\_3])\)\ \((x\_3 - \ x\_1)\)\/2\)], FontSize->15], "\n\nto find the area under a parabola and over ", Cell[BoxData[ \(TraditionalForm\`\([x\_1, \ x\_3]\)\)]], " without integrating." }], "Text"], Cell[TextData[{ "Exercise 1: Use the new formula for finding areas under parabolas to find \ the area under ", Cell[BoxData[ \(TraditionalForm\`y\ = \ x\^2\)]], "over the interval [0, 1]. Compare your answer to the value you get when \ you use the fundamental theorem to find\nthis area." }], "Text", FontColor->RGBColor[1, 0, 0]], Cell[TextData[{ "Exercise 2: Use the new formula for finding areas under parabolas to find \ the area under ", Cell[BoxData[ \(TraditionalForm\`\(y\ = \ x\^2\ + \ 5\ x\ - 2\ \)\)]], "over the interval [1, 5/4]. Compare your answer to the value you get when \ you use the fundamental theorem to find this area." }], "Text", FontColor->RGBColor[1, 0, 0]] }, Closed]], Cell[CellGroupData[{ Cell["Curve fitting", "Section"], Cell[TextData[{ "A theorem from algebra states that through any ", StyleBox["n ", FontSlant->"Italic"], "+ 1 points in the plane, there is exactly ", StyleBox["one", FontWeight->"Bold"], " polynomial of degree ", StyleBox["n", FontSlant->"Italic"], " that passes through all the points. Here's why it works: " }], "Text"], Cell[TextData[{ "Suppose we want a polynomial of degree ", StyleBox["n", FontSlant->"Italic"], " that passes through the points ", Cell[BoxData[ \(TraditionalForm\`\((x\_1, y\_1)\)\)]], ", ", Cell[BoxData[ \(TraditionalForm\`\((x\_2, y\_2)\)\)]], ", \[CenterEllipsis] ", Cell[BoxData[ \(TraditionalForm\`\((x\_\(n + 1\), y\_\(n + 1\))\)\)]], ". If we let ", Cell[BoxData[ \(TraditionalForm \`p(x)\ = \ a\_0 + \ \(a\_1\) x\ + \ \(a\_2\) x\^2 + \ \[CenterEllipsis]\ + \ \(a\_n\) x\^n\)]], " be the desired polynomial, then we get ", StyleBox["n", FontSlant->"Italic"], "+1 equations in the ", StyleBox["n", FontSlant->"Italic"], "+1 coefficients ", Cell[BoxData[ \(TraditionalForm\`a\_0\)]], ", ", Cell[BoxData[ \(TraditionalForm\`a\_1\)]], ", \[CenterEllipsis] ", Cell[BoxData[ \(TraditionalForm\`a\_n\)]], " by plugging each point into the equation ", Cell[BoxData[ \(TraditionalForm \`p(x)\ = \ a\_0 + \ \(a\_1\) x\ + \ \(a\_2\) x\^2 + \ \[CenterEllipsis]\ + \ \(a\_n\) x\^n\)]], ". We can then solve the equations simultaneously to find the correct \ coeffiecents." }], "Text"], Cell["An example", "Text", CellDingbat->"\[FilledCircle]", FontWeight->"Bold"], Cell[TextData[{ "Find the parabola that passes through (0, 2), (-1, 5) and (7, 8). Here's \ a picture of the points. Note that ", StyleBox["Mathematica", FontSlant->"Italic"], " uses { } to surround points instead of ( )." }], "Text"], Cell[BoxData[ \(\(dots\ = \ ListPlot[{{0, 2}, {\(-1\), 5}, {7, 8}}, \n\t\t\t\t\t\t\t\t\t PlotStyle -> {Green, \ PointSize[ .02]}]; \)\)], "Input"], Cell[TextData[{ "The desired polynomial is a parabola, so it has the form ", Cell[BoxData[ \(TraditionalForm\`p(x)\ = \ a\ + \ b\ x\ + \ c\ x\^2\)]], ". We get three equations when we plug in (0,2), (-1, 5), and (7,8):" }], "Text"], Cell[TextData[{ "\t", Cell[BoxData[{ \(TraditionalForm\`2\ = \ a\ + \ b*0\ + \ c*0\^2\), \(TraditionalForm\`5\ = \ a\ + \ b*\(-1\)\ + \ c*\((\(-1\))\)\^2\), \(TraditionalForm\`8\ = \ a\ + \ b*7\ + \ c*7\^\(2\ \ \)\)}]] }], "Text"], Cell[TextData[{ "We can have ", StyleBox["Mathematica", FontSlant->"Italic"], " solve these equations for us (Note the == in the equations):" }], "Text"], Cell[BoxData[ \(Solve[{2\ == \ \ \ a\ + \ b*0\ + \ c*0\^2, \n \t\ \ \ \ \ \ \ \ \ \ \ \ \ 5\ == \ \ \ a\ + \ b*\((\(-1\))\)\ + \ c*\((\(-1\))\)\^2, \n \t\ \ \ \ \ \ \ \ \ \ \ \ \ 8\ == \ \ \ a\ + \ b*7\ + \ c*7\^2}, { a, b, c}]\)], "Input"], Cell[TextData[{ "So the polynomial we want is ", Cell[BoxData[ \(TraditionalForm \`p(x)\ = \ 2\ - \ \(141\/56\) x\ + \ \(27\/56\) x\^2\)]], ". Here's a quick plot:" }], "Text"], Cell[BoxData[ \(\(parabola\ = \ Plot[2\ - \ \((141/56)\) x\ + \ \((27/56)\) x^2, \n \t\t\t\t\t\t\t\t\t\t\t\t\ {x, \ \(-2\), \ 8}]; \)\)], "Input"], Cell["\<\ And now we check to make sure that the parabola does what we \ want:\ \>", "Text"], Cell[BoxData[ \(\(Show[dots, \ parabola]; \)\)], "Input"], Cell["Yes, the green points all lie on the parabola.", "Text"], Cell["\<\ Exercise 3: Find the parabola that goes through (1,2), (3,5), (5, \ 10). Check your work by showing a plot that clearly shows the points are on \ the curve.\ \>", "Text", FontColor->RGBColor[1, 0, 0]], Cell["\<\ Exercise 4: Find a cubic polynomial that goes through (1,2), \ (3,5), (5, 10), and (7, 0). Check your work by showing a plot that clearly \ shows the points are on the curve. Hint: You will need to build a system of \ 4 equations in 4 unknown coefficients.\ \>", "Text", FontColor->RGBColor[1, 0, 0]] }, Closed]], Cell[CellGroupData[{ Cell[TextData[ "Putting it all together\[LongDash]the geometry of Simpson's Rule"], "Section"], Cell[TextData[{ "Recall our original problem: We want to use parabolas to approximate the \ area under a function on the interval [a, b]. As always, we need to define \ the function, the value for ", StyleBox["a", FontSlant->"Italic"], " and ", StyleBox["b", FontSlant->"Italic"], ", and then slice the area that is given by ", Cell[BoxData[ \(TraditionalForm\`\[Integral]\_a\%b f[x] \[DifferentialD]x\)]], ". The function Slices[n] shows us the slices:" }], "Text"], Cell[BoxData[ \(f[x_]\ := \ Sin[x^2]; \na = 0; \n\ b = \ Sqrt[Pi]; \nSlices[4]; \)], "Input"], Cell[TextData[{ "We need THREE points to fit a parabola. If the number of slices is even \ (say 2 ", StyleBox["n", FontSlant->"Italic"], "), we can use ", Cell[BoxData[ \(TraditionalForm\`n\)]], " parabolas by slapping adjacent pairs of subintervals together and using \ the three endpoints of the two intervals together to determine the parabola. \ Parabolas[n] shows how the ", StyleBox["n", FontSlant->"Italic"], " parabolas approximate the function:" }], "Text"], Cell[BoxData[ \(\(Parabolas[1]; \)\)], "Input"], Cell["\<\ Note how the endpoint of the first slice is used as the middle \ point for the parabola!\ \>", "Text"], Cell[BoxData[ \(\(Parabolas[2]; \)\)], "Input"], Cell["\<\ Note how the endpoints of the first and third slices are used as \ the middle points for the parabolas!\ \>", "Text"], Cell[BoxData[ \(\(Parabolas[3]; \)\)], "Input"], Cell["\<\ Note how the endpoints of the first, third, and fifth slices are \ used as the middle points for the parabolas!\ \>", "Text"], Cell[BoxData[ \(\(Parabolas[4]; \)\)], "Input"], Cell[TextData[{ "In general, the odd ", Cell[BoxData[ \(TraditionalForm\`x\_i\)]], "'s are used as the middle points for each parabola, while the even ", Cell[BoxData[ \(TraditionalForm\`x\_i\)]], "'s are used as the right and left hand endpoints of the parabolas." }], "Text"], Cell[TextData[{ "Exercise 5: Does using ", StyleBox["n", FontSlant->"Italic"], " parabolas seem to give better (visual) estimates than using 2", StyleBox["n", FontSlant->"Italic"], " rectangles? Do the parabolas do a better job than using 2", StyleBox["n", FontSlant->"Italic"], " trapezoids? Why? Hint: The intialization cells define the functions \ LeftRects[n], RightRects[n], MiddleRects[n], and Traps[n]. These functions \ draw the pictures and give you a numerical estimates for using ", StyleBox["n", FontSlant->"Italic"], " slices and ", StyleBox["n", FontSlant->"Italic"], " rectangles or trapezoids. You can get more information about these \ functions if you type ?LeftRects, ?RightRects, ?MiddleRects, and ?Traps in an \ input cell and activate it." }], "Text", FontColor->RGBColor[1, 0, 0]], Cell[TextData[{ "Exercise 6: Repeat Exercise 5 with several (in other words, 3 or 4) \ functions of your own choosing. Be sure to also declare values for ", StyleBox["a", FontSlant->"Italic"], " and ", StyleBox["b", FontSlant->"Italic"], " as well as defining the function. Do parabolas always seem to do a \ better job than trapezoids? Why?" }], "Text", FontColor->RGBColor[1, 0, 0]] }, Closed]], Cell[CellGroupData[{ Cell[TextData[ "Putting it all together\[LongDash]the algebra of Simpson's Rule"], "Section"], Cell["\<\ In each of the above pictures, a particular parabola covers two of \ the slice subintervals. Counting the first parabola as Parabola 0 (to make \ indexing easier), we find that:\ \>", "Text"], Cell[TextData[{ "\t", Cell[BoxData[ \(TraditionalForm\`Parabola\_0\)]], " uses ", Cell[BoxData[ \(TraditionalForm\`\((x\_0, f[x\_0])\)\)]], ", ", Cell[BoxData[ \(TraditionalForm\`\((x\_1, f[x\_1])\)\)]], ", and ", Cell[BoxData[ \(TraditionalForm\`\((x\_2, f[x\_2])\)\)]] }], "Text"], Cell[TextData[{ "\t", Cell[BoxData[ \(TraditionalForm\`Parabola\_1\)]], " uses ", Cell[BoxData[ \(TraditionalForm\`\((x\_2, f[x\_2])\)\)]], ", ", Cell[BoxData[ \(TraditionalForm\`\((x\_3, f[x\_2])\)\)]], ", and ", Cell[BoxData[ \(TraditionalForm\`\((x\_4, f[x\_4])\)\)]] }], "Text"], Cell[TextData[{ "\t", Cell[BoxData[ \(TraditionalForm\`Parabola\_2\)]], " uses ", Cell[BoxData[ \(TraditionalForm\`\((x\_4, f[x\_4])\)\)]], ", ", Cell[BoxData[ \(TraditionalForm\`\((x\_5, f[x\_5])\)\)]], ", and ", Cell[BoxData[ \(TraditionalForm\`\((x\_6, f[x\_6])\)\)]] }], "Text"], Cell[TextData[{ "and so on. In particular, the points ", Cell[BoxData[ \(TraditionalForm\`\((x\_\(2 i\), f[x\_\(2 i\)])\)\)]], ", ", Cell[BoxData[ \(TraditionalForm\`\((x\_\(2 i + 1\), f[x\_\(2 i + 1\)])\)\)]], ", and ", Cell[BoxData[ \(TraditionalForm\`\((x\_\(2 i + 2\), f[x\_\(2 i + 2\)])\)\)]], " are used to determine ", Cell[BoxData[ \(TraditionalForm\`Parabola\_i\)]], ". " }], "Text"], Cell[TextData[{ "Also note that ", StyleBox["f", FontSlant->"Italic"], " and ", Cell[BoxData[ \(TraditionalForm\`Parabola\_i\)]], " both go through these three points, so the area of the parabolic slice\n\ under ", Cell[BoxData[ \(TraditionalForm\`Parabola\_i\)]], " and over ", Cell[BoxData[ \(TraditionalForm\`\([x\_\(2 i\), \ x\_\(2 i\ + \ 2\)]\)\)]], " is given by:\n\n", Cell[BoxData[ \(TraditionalForm \`Area\ under\ Paraboloa\_i\ \n\t\t\ \ \ \ \ \ = \(1\/\(\ 3\)\ \((\ Parabola\_i[x\_\(2 i\)]\ + \ 4\ Parabola\_i[x\_\(2 i + 1\)]\ + \ Parabola\_i[x\_\(2 i + 2\)])\)\ \((x\_\(2 i + 2\) - \ x\_\(2 i\))\)\/2\n\t\t\t\ \ \ \ = \ \(1\/3\) \((f[x\_\(2 i\)]\ + \ 4\ f[x\_\(2 i + 1\)]\ + \ f[x\_\(2 i\ + \ 2\)]\ )\)\ \((\ \(b - a\)\/\(2 n\))\)\)\)], FontSize->15], "\n\nsince ", Cell[BoxData[ \(TraditionalForm\`x\_\(2 i + 1\)\)]], " is the midpoint of ", Cell[BoxData[ \(TraditionalForm\`\([x\_\(2 i\), \ x\_\(2 i + 2\)]\)\)]], " and ", Cell[BoxData[ \(TraditionalForm\`\((x\_\(2 i + 2\) - \ x\_\(2 i\))\)\/2\)]], " = width of one slice (and ", StyleBox["n", FontSlant->"Italic"], " parabolas require 2", StyleBox["n", FontSlant->"Italic"], " slices)." }], "Text"], Cell[TextData[{ "Adding up the areas under all the parabolas gives us an estimate for ", Cell[BoxData[ \(TraditionalForm\`\[Integral]\_a\%b f[x] \[DifferentialD]x\)]], ": Using 2", StyleBox["n", FontSlant->"Italic"], " slices (and ", StyleBox["n", FontSlant->"Italic"], " parabolas, counting from Parabola 0 to Parabola ", StyleBox["n", FontSlant->"Italic"], " - 1), we get:" }], "Text"], Cell[TextData[{ "\t", StyleBox[" ", FontSize->16], Cell[BoxData[ FormBox[ RowBox[{ RowBox[{ \(\[Integral]\_a\%b f[x] \[DifferentialD]x\ \[TildeTilde] \[Sum]\+\(i = 0\)\%\(n - 1\)\(1\/3\) \((f[x\_\(2 i\)]\ + \ 4\ f[x\_\(2 i + 1\)]\ + \ f[x\_\(2 i\ + \ 2\)]\ )\)\ \((\ \(b - a\)\/\(2 n\))\)\), "\n", "\t\t\t\t ", "\n", "\t\t ", "=", " ", RowBox[{ \(\(1\/3\) \((\ \(b - a\)\/\(2 n\))\)\ \((\ f[x\_0]\ + \ 4\ f[x\_1]\ + \ f[x\_2]\ + \n \t\t\t\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ f[x\_2]\ + \ 4\ f[x\_3]\ + \ f[x\_4]\ + \n \t\t\t\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ f[x\_4]\ + \ 4\ f[x\_5]\ + \ f[x\_6]\ + \n \t\t\t\t\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \[CenterEllipsis]\ + \n \t\t\t\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ f[x\_\(2 n - 2\)]\ + \ 4\ f[x\_\(2 n - 1\)]\ + \ f[x\_\(2 n\)]\ )\)\), "\n", "\t", "\n", " ", "=", " ", RowBox[{ \(\((\ \(b - a\)\/\(6 n\))\)\ \((\ f[x\_0]\ + \ 4\ f[x\_1]\ + \ 2 f[x\_2]\ + \n \t\t\t\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 4\ f[x\_3]\ + \ 2 f[x\_4]\ + \ \ 4\ f[x\_5]\ + \n \t\t\t\t\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \[CenterEllipsis]\ + \n \t\t\t\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 2 f[x\_\(2 n - 2\)]\ + \ 4\ f[x\_\(2 n - 1\)]\ + \ f[x\_\(2 n\)]\ )\)\), "\n", " ", "=", " ", RowBox[{ \(\((\ \(b - a\)\/\(6 n\))\)\ \((\ f[x\_0]\ + \ \n \t\t\t\t\t\t\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 2 f[x\_2]\ + \ \ 2 f[x\_4]\ + \ \(+\ 2\) f[x\_6]\ + \ \[CenterEllipsis]\ + \ 2 f[x\_\(2 n - 2\)]\ + \n \t\t\t\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 4\ f[x\_1]\ + \ \ 4\ f[x\_3]\ + \ 4 f[x\_5]\ + \ \ 4\ f[x\_7]\ + \ \[CenterEllipsis]\ + \ 4\ f[x\_\(2 n - 1\)]\ + \ \n \t\t\t\t\t\t\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ f[x\_\(2 n\)]\ )\)\), "\n", "\t\t\t", "\n", " ", "=", " ", RowBox[{\((\ \(b - a\)\/\(6 n\))\), " ", RowBox[{"(", " ", RowBox[{ \(f[x\_0]\), " ", "+", " ", \(f[x\_\(2 n\)]\), " ", "+", " ", "\n", "\t\t\t\t\t\t\t \ ", RowBox[{ StyleBox[\(\[Sum]\+\(i = 1\)\%\(n - 1\)\), FontSize->19], StyleBox[" ", FontSize->19], \(2 f[x\_\(2 i\)]\)}], " ", "+", " ", RowBox[{ StyleBox[\(\[Sum]\+\(i = 0\)\%\(n - 1\)\), FontSize->19], " ", \(4\ f[x\_\(2 i\ + \ 1\)]\)}]}], " ", ")"}]}]}]}]}]}], "\n", "\t"}], TraditionalForm]], FontSize->16] }], "Text"], Cell[TextData[{ "Here's the appropriate ", StyleBox["Mathematica", FontSlant->"Italic"], " code for Simpson's Rule:" }], "Text"], Cell[BoxData[ \(Clear[SimpsonsRule]; \n SimpsonsRule[n_]\ := \ \n\t\ N[\ \ \(\(b - a\)\/\(6\ n\)\) \((f[a]\ + f[b]\ + \ \[Sum]\+\(i = 1\)\%\(n - 1\)\(( 2\ f[a\ + \ 2\ i\ \ \(b - a\)\/\(2 n\)]\ )\) + \ \[Sum]\+\(i = 0\)\%\(n - 1\)\((\ 4 f[a\ + \ \((2\ i\ + 1)\)\ \(b - a\)\/\(2 n\)])\))\)] \)], "Input"], Cell[TextData[{ "Recall that in our example, f[x] = ", Cell[BoxData[ \(TraditionalForm\`\(Sin[x\^2\)\)]], "] and we want to approximate ", Cell[BoxData[ \(TraditionalForm \`\[Integral]\_0\%\(\@\[Pi]\)Sin[x\^2] \[DifferentialD]x\)]], " using Simpson's Rule. \nHere's a table for the approximations given by 1 \ to 10 parabolas (2 to 20 slices):" }], "Text"], Cell[BoxData[ \(f[x_]\ := \ Sin[x^2]; \na = 0; \n\ b = \ Sqrt[Pi]; \n Table[SimpsonsRule[n], \ {n, \ 1, \ 10}]\)], "Input"], Cell[TextData[{ "This data gives us enough evidence to conclude that ", Cell[BoxData[ \(TraditionalForm \`\[Integral]\_0\%\(\@\[Pi]\)Sin[x\^2] \[DifferentialD]x\)]], " is probably between 0.8948 and 0.8949. If we extend the table out \ further (say to parabolas), we get a better idea of a good estimated value \ for the integral:" }], "Text"], Cell[BoxData[ \(Table[SimpsonsRule[n], \ {n, \ 1, \ 30}]\)], "Input"], Cell[TextData[{ "This is pretty clear evidence that ", Cell[BoxData[ \(TraditionalForm \`\[Integral]\_0\%\(\@\[Pi]\)Sin[x\^2] \[DifferentialD]x\)]], " is about 0.89483 (to five decimal places.)" }], "Text"], Cell[TextData[{ "Exercise 7. Make a picture that uses 100 trapezoids to estimate the value \ of ", Cell[BoxData[ \(TraditionalForm \`\[Integral]\_0\%1\( 4\/\(x\^2 + 1\)\) \[DifferentialD]x\)]], ". Note that this result\nleads us to guess that the true value of this \ integral is \[Pi]. Make pictures that use around 100 rectangles to estimate \ this integral and note that we get a good estimate for \[Pi]. Make a table \ of values using Simpson's Rule to approximate this integral. How many \ parabolas do you need before it becomes clear that this integral is probably \ approaching \[Pi]? How many slices does this number of parabolas require? \ Is this fewer slices than the trapezoids took?" }], "Text", FontColor->RGBColor[1, 0, 0]], Cell[TextData[{ "Exercise 8. The exact value of ", Cell[BoxData[ \(TraditionalForm \`\[Integral]\_\(-1\)\%0\(\@\( 1 - x\^2\)\) \[DifferentialD]x\)]], " is \[Pi]/4\[TildeTilde]0.785398. Look at the estimate formed by using 50 \ LeftRects. (It should be ", StyleBox["0.774567.", FontColor->RGBColor[1, 0, 0]], ") Look at the estimate formed by using 10 Trapezoids. Does this give a \ better estimate than 50 LeftRects? How many Parabolas are needed to beat the \ error in the 50 LeftRects estimate? How many slices does this number of \ rectangles require? " }], "Text", FontColor->RGBColor[1, 0, 0]] }, Closed]], Cell[CellGroupData[{ Cell["A look ahead", "Section"], Cell["\<\ In this notebook, we have not yet examined how quickly the error in \ Simpson's Rule disappears. We can do that using the same techniques that \ we've used before for LeftRects, MidRects, and RightRects: In the next \ notebook, we'll look at how quickly the error seems to drop off using \ Simpson's Rule. We'll also compare it to the other numerical techniques \ we've looked at. \ \>", "Text"] }, Closed]], Cell[CellGroupData[{ Cell["Initialization Cells---No need to open this group", "Section", Evaluatable->False, InitializationCell->True, AspectRatioFixed->True], Cell[CellGroupData[{ Cell["General", "Subsection", InitializationCell->True], Cell["Read in the Graphics package, Colors.m and turn off spell", "Text", InitializationCell->True], Cell["\<\ Needs[\"Graphics`Colors`\"] Off[General::Spell]\ \>", "Input", InitializationCell->True], Cell["\<\ Make sure that the picture of the function is drawn correctly:\ \>", "Text", InitializationCell->True], Cell[BoxData[{ \(Clear[f, x, \ a, \ b, \ picture]\), \(picture\ := \ Plot[{f[x], 0}, {x, a, b}, \n \t\t\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ DisplayFunction -> Identity]\)}], "Input", InitializationCell->True], Cell["\<\ Define jump[n], the width of each subinterval in the \ partition:\ \>", "Text", InitializationCell->True], Cell["\<\ Clear[n,jump] jump[n_] := (b-a)/n;\ \>", "Input", InitializationCell->True], Cell["Commands for drawing the partition lines in Purple", "Text", InitializationCell->True], Cell["\<\ Clear[SliceLine] SliceLine[k_,n_] := Graphics[{Purple, Line[{{a + k jump[n], 0}, {a + k jump[n], f[a + k jump[n]]}}] }]\ \>", "Input", InitializationCell->True], Cell["\<\ Slices[n_] := Show[picture, Table[SliceLine[k,n],{k,0,n}], DisplayFunction->$DisplayFunction]\ \>", "Input", InitializationCell->True] }, Open ]], Cell[CellGroupData[{ Cell["Parabolas", "Subsection", InitializationCell->True], Cell["Parabolas in pictures", "Text", InitializationCell->True], Cell["\<\ Clear[ParabolasPicture, ParabolaTop] ParabolaTop[k_,n_] := Module[{x1, x2, x3, a0, a1, a2, coeffs, c0, c1, c2}, {x3 = a + (2 k)jump[2 n]; x2 = a + (2 k - 1)jump[2 n]; x1 = a + (2 k - 2)jump[2 n]; coeffs = Solve[{ \t\t\tf[x1] == a0 + a1 x1 + a2 (x1)^2, \t\t\tf[x2] == a0 + a1 x2 + a2 (x2)^2, \t\t\tf[x3] == a0 + a1 x3 + a2 (x3)^2}, \t\t\t {a0, a1, a2}]; c0 = If[coeffs[[1,1,1]] === a0, c0 = coeffs[[1,1,2]], \t\t If[coeffs[[1,2,1]] === a0, \t\t\t c0 = coeffs[[1,2,2]], \t\t\t c0 = coeffs[[1,3,2]] \t\t\t ]]; c1 = If[coeffs[[1,1,1]] === a1, c1 = coeffs[[1,1,2]], \t\t If[coeffs[[1,2,1]] === a1, \t\t\t c1 = coeffs[[1,2,2]], \t\t\t c1 = coeffs[[1,3,2]] \t\t\t ]]; c2 = If[coeffs[[1,1,1]] === a2, c2 = coeffs[[1,1,2]], \t\t If[coeffs[[1,2,1]] === a2, \t\t\t c2 = coeffs[[1,2,2]], \t\t\t c2 = coeffs[[1,3,2]] \t\t\t ]]; Plot[c0 + c1 x + c2 x^2, {x, x1, x3}, \t\t PlotStyle->{{Green}}, \t\t \t\t DisplayFunction->Identity] \t\t } \t\t ]\ \>", "Input", InitializationCell->True], Cell["\<\ ParabolasPicture[n_] := Show[picture, Table[SliceLine[k,2 n],{k,0,2 n}], Table[ParabolaTop[k,n],{k,1,n}], DisplayFunction->$DisplayFunction]\ \>", "Input", InitializationCell->True], Cell["\<\ ParabolasPicture::usage = \"ParabolasPictures[n] draws a picture of \ the parabolic estimate. The function f and the values a and b must already \ be defined.\";\ \>", "Input", InitializationCell->True], Cell[BoxData[ \(Clear[SimpsonsRule]; \n SimpsonsRule[n_]\ := \ \n\t\ N[\ \ \(\(b - a\)\/\(6\ n\)\) \((f[a]\ + f[b]\ + \ \[Sum]\+\(i = 1\)\%\(n - 1\)\(( 2\ f[a\ + \ 2\ i\ \ \(b - a\)\/\(2 n\)]\ )\) + \ \[Sum]\+\(i = 0\)\%\(n - 1\)\((\ 4 f[a\ + \ \((2\ i\ + 1)\)\ \(b - a\)\/\(2 n\)])\))\)] \)], "Input", InitializationCell->True], Cell["\<\ SimpsonsRule::usage = \"SimpsonsRule[n] gives the numerical \ estimate using n parabolas. The function f and the values a and b must already be \ defined.\";\ \>", "Input", InitializationCell->True], Cell["\<\ Clear[Parabolas] Parabolas[n_] := \tModule[{pe}, \t\t\tParabolasPicture[n]; \t\t\tpe = SimpsonsRule[n]; \t\t\tPrint[\"Parabolas estimate is \",pe] \t\t ]\ \>", "Input", InitializationCell->True], Cell["\<\ Parabolas::usage = \"Parabolas[n] draws a picture of the parabolic \ estimate using n parabolas and prints out the estimate. The function f and \ the values a and b must already be defined.\";\ \>", "Input", InitializationCell->True], Cell[CellGroupData[{ Cell[BoxData[ \(?? Parabolas\)], "Input"], Cell[BoxData[ \("Parabolas[n] draws a picture of the parabolic estimate using n \ parabolas and prints out the estimate. The function f and the values a and b \ must already be defined."\)], "Print"], Cell[BoxData[ InterpretationBox[ StyleBox[ \(Parabolas[n_]\ := \ Module[{pe}, \ ParabolasPicture[n]; \ pe\ = \ SimpsonsRule[n]; \ Print["\", \ pe]]\), ShowStringCharacters->True, NumberMarks->True], InputForm[ Definition[ Parabolas]], Editable->True, AutoDelete->True]], "Print"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["Right Rectangles", "Subsection", InitializationCell->True], Cell["Commands for showing Right-hand rule rectangles", "Text", Evaluatable->False, InitializationCell->True], Cell["\<\ Clear[RightRectanglesPicture, RightHandTop] RightHandTop[k_,n_] := Graphics[{{Blue, Line[{ {a + (k-1) jump[n], f[a + k jump[n]]}, {a + k jump[n], f[a + k jump[n]]}}] }, If[Abs[f[a + k jump[n]]] > Abs[f[a + (k-1) jump[n]]], {Blue, Line[{ {a + (k-1) jump[n], f[a + k jump[n]]}, {a + (k-1) jump[n], f[a + (k-1)jump[n]]} }] }, {Blue, Point[{a + (k-1) jump[n], f[a + (k-1) jump[n]]}] }]}] \ \>", "Input", InitializationCell->True], Cell["\<\ RightRectanglesPicture[n_] := Show[picture, Table[SliceLine[k,n],{k,0,n}], Table[RightHandTop[k,n],{k,1,n}], DisplayFunction->$DisplayFunction]\ \>", "Input", InitializationCell->True], Cell["\<\ RightRectanglesPicture::usage = \"RightRectanglesPictures[n] draws \ a picture of the right rectangle estimate. The function f and the values a \ and b must already be defined.\";\ \>", "Input", InitializationCell->True], Cell[BoxData[ RowBox[{\(Clear[RightRectsEst]\), ";", "\n", RowBox[{\(RightRectsEst[n_]\), " ", ":=", " ", "\n", " ", RowBox[{"N", "[", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"b", StyleBox[" ", FontSize->11, FontWeight->"Plain"], "-", StyleBox[" ", FontSize->11, FontWeight->"Plain"], "a"}], ")"}], "/", "n"}], StyleBox[" ", FontSize->11, FontWeight->"Plain"], "*", StyleBox[" ", FontSize->11, FontWeight->"Plain"], RowBox[{"Sum", "[", RowBox[{ RowBox[{"f", "[", RowBox[{"a", " ", "+", " ", RowBox[{"i", " ", RowBox[{ RowBox[{"(", RowBox[{"b", StyleBox[" ", FontSize->11, FontWeight->"Plain"], "-", StyleBox[" ", FontSize->11, FontWeight->"Plain"], "a"}], ")"}], "/", "n"}]}]}], "]"}], ",", "\n", "\t \ ", RowBox[{"{", \(i, \ 1, \ n\), StyleBox[" ", FontSize->11, FontWeight->"Plain"], "}"}]}], "]"}]}], "]"}]}]}]], "Input", InitializationCell->True], Cell["\<\ RightRectsEst::usage = \"RightRectsEst[n] gives the numerical \ estimate using n right rectangles. The function f and the values a and b must already \ be defined.\";\ \>", "Input", InitializationCell->True], Cell["\<\ Clear[RightRects] RightRects[n_] := \tModule[{re}, \t\t\tRightRectanglesPicture[n]; \t\t\tre = RightRectsEst[n]; \t\t\tPrint[\"Right Rectangle estimate is \",re] \t\t ]\ \>", "Input", InitializationCell->True], Cell["\<\ RightRects::usage = \"RightRects[n] draws a picture of the right \ rectangle estimate using n rectangles and prints out the estimate. The \ function f and the values a and b must already be defined.\";\ \>", "Input", InitializationCell->True] }, Closed]], Cell[CellGroupData[{ Cell["Left Rectangles", "Subsection", InitializationCell->True], Cell["\<\ The commands for drawing the picture for Left-hand rule rectangles.\ \ \>", "Text", Evaluatable->False, InitializationCell->True], Cell["\<\ Clear[LeftRectanglesPicture, LeftHandTop] LeftHandTop[k_,n_] := Graphics[{{Red, Line[{ {a + (k-1) jump[n], f[a + (k-1) jump[n]]}, {a + k jump[n], f[a + (k-1) jump[n]]}}] }, If[Abs[f[a + k jump[n]]] < Abs[f[a + (k-1) jump[n]]], {Red, Line[{ {a + k jump[n], f[a + k jump[n]]}, {a + k jump[n], f[a + (k-1) jump[n]]} }] }, {Red, Point[{a + k jump[n], f[a + k jump[n]]}] }]}]\ \>", "Input", InitializationCell->True], Cell["\<\ LeftRectanglesPicture[n_] := Show[picture, Table[SliceLine[k,n],{k,0,n}], Table[LeftHandTop[k,n],{k,1,n}], DisplayFunction->$DisplayFunction]\ \>", "Input", InitializationCell->True], Cell["\<\ LeftRectanglesPicture::usage = \"LeftRectanglesPictures[n] draws a \ picture of the left rectangle estimate. The function f and the values a and \ b must already be defined.\";\ \>", "Input", InitializationCell->True], Cell[BoxData[ RowBox[{\(Clear[LeftRectsEst]\), ";", "\n", RowBox[{\(LeftRectsEst[n_]\), " ", ":=", " ", "\n", " ", RowBox[{"N", "[", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"b", StyleBox[" ", FontSize->11, FontWeight->"Plain"], "-", StyleBox[" ", FontSize->11, FontWeight->"Plain"], "a"}], ")"}], "/", "n"}], StyleBox[" ", FontSize->11, FontWeight->"Plain"], "*", StyleBox[" ", FontSize->11, FontWeight->"Plain"], RowBox[{"Sum", "[", RowBox[{ RowBox[{"f", "[", RowBox[{"a", " ", "+", " ", RowBox[{"i", " ", RowBox[{ RowBox[{"(", RowBox[{"b", StyleBox[" ", FontSize->11, FontWeight->"Plain"], "-", StyleBox[" ", FontSize->11, FontWeight->"Plain"], "a"}], ")"}], "/", "n"}]}]}], "]"}], ",", "\n", "\t \ ", RowBox[{"{", RowBox[{"i", ",", " ", "0", ",", " ", RowBox[{"n", StyleBox[" ", FontSize->11, FontWeight->"Plain"], "-", StyleBox[" ", FontSize->11, FontWeight->"Plain"], "1"}]}], "}"}]}], "]"}]}], "]"}]}]}]], "Input", InitializationCell->True], Cell["\<\ LeftRectsEst::usage = \"LeftRectsEst[n] gives the numerical \ estimate using n left rectangles. The function f and the values a and b must already \ be defined.\";\ \>", "Input", InitializationCell->True], Cell["\<\ Clear[LeftRects] LeftRects[n_] := \tModule[{le}, \t\t\tLeftRectanglesPicture[n]; \t\t\tle = LeftRectsEst[n]; \t\t\tPrint[\"Left Rectangle estimate is \",le] \t\t ]\ \>", "Input", InitializationCell->True], Cell["\<\ LeftRects::usage = \"LeftRects[n] draws a picture of the left \ rectangle estimate using n rectangles and prints out the estimate. The \ function f and the values a and b must already be defined.\";\ \>", "Input", InitializationCell->True] }, Closed]], Cell[CellGroupData[{ Cell["Middle Rectangles", "Subsection", InitializationCell->True], Cell["Commands for showing \"Midpoint Rule\" rectangles.", "Text", Evaluatable->False, InitializationCell->True], Cell["\<\ Clear[MiddleRectanglesPicture, MidpointTop] MidpointTop[k_,n_] := Graphics[ {{Brick, Line[{ {a + (k-1) jump[n], f[(a + (k-1) jump[n] + a + k jump[n])/2]}, {a + k jump[n], f[(a + (k-1) jump[n] + a + k jump[n])/2]} }]}, If[Abs[f[a + k jump[n]]] < Abs[f[(a + (k-1) jump[n] + a + k jump[n])/2]], {Brick, Line[{ {a + k jump[n], f[a + k jump[n]]}, {a + k jump[n], f[(a + (k-1) jump[n] + a + k jump[n])/2]} }] }, {Brick, Point[{a + k jump[n], f[(a + (k-1) jump[n] + a + k jump[n])/2]}] }], If[Abs[f[a + (k-1) jump[n]]] < Abs[f[(a + (k-1) jump[n] + a + k jump[n])/2]], {Brick, Line[{ {a + (k-1) jump[n], f[a + (k-1) jump[n]]}, {a + (k-1) jump[n], f[(a + (k-1) jump[n] + a + k jump[n])/2]} }] }, {Brick, Point[{a + (k-1) jump[n], f[(a + (k-1) jump[n] + a + k jump[n])/2]}] }] }]\ \>", "Input", InitializationCell->True], Cell["\<\ MiddleRectanglesPicture[n_] := Show[picture, Table[SliceLine[k,n],{k,0,n}], Table[MidpointTop[k,n],{k,1,n}], DisplayFunction->$DisplayFunction]\ \>", "Input", InitializationCell->True], Cell["\<\ MiddleRectanglesPicture::usage = \"MiddleRectanglesPictures[n] \ draws a picture of the middle rectangle estimate. The function f and the \ values a and b must already be defined.\";\ \>", "Input", InitializationCell->True], Cell[BoxData[ RowBox[{\(Clear[MidRectsEst]\), ";", "\n", RowBox[{\(MidRectsEst[n_]\), " ", ":=", " ", "\n", " ", RowBox[{"N", "[", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"b", StyleBox[" ", FontSize->11, FontWeight->"Plain"], "-", StyleBox[" ", FontSize->11, FontWeight->"Plain"], "a"}], ")"}], "/", "n"}], StyleBox[" ", FontSize->11, FontWeight->"Plain"], "*", StyleBox[" ", FontSize->11, FontWeight->"Plain"], RowBox[{"Sum", "[", RowBox[{ RowBox[{"f", "[", RowBox[{"a", " ", "+", " ", RowBox[{\((i\ + \ 1/2)\), " ", RowBox[{ RowBox[{"(", RowBox[{"b", StyleBox[" ", FontSize->11, FontWeight->"Plain"], "-", StyleBox[" ", FontSize->11, FontWeight->"Plain"], "a"}], ")"}], "/", "n"}]}]}], "]"}], ",", "\n", "\t\t\t\t \ ", RowBox[{"{", RowBox[{"i", ",", " ", "0", ",", " ", RowBox[{"n", StyleBox[" ", FontSize->11, FontWeight->"Plain"], "-", StyleBox[" ", FontSize->11, FontWeight->"Plain"], "1"}]}], "}"}]}], "]"}]}], "]"}]}]}]], "Input", InitializationCell->True], Cell["\<\ MidRectsEst::usage = \"MidRectsEst[n] gives the numerical estimate using n middle rectangles. The function f and the values a and b must \ already be defined.\";\ \>", "Input", InitializationCell->True], Cell["\<\ Clear[MiddleRects] MiddleRects[n_] := \tModule[{me}, \t\t\tMiddleRectanglesPicture[n]; \t\t\tme = MidRectsEst[n]; \t\t\tPrint[\"Middle Rectangle estimate is \",me] \t\t ]\ \>", "Input", InitializationCell->True], Cell["\<\ MiddleRects::usage = \"MiddleRects[n] draws a picture of the middle \ rectangle estimate using n rectangles and prints out the estimate. The \ function f and the values a and b must already be defined.\";\ \>", "Input", InitializationCell->True] }, Closed]], Cell[CellGroupData[{ Cell["Trapezoids", "Subsection", InitializationCell->True], Cell["\<\ Clear[TrapezoidsPicture, TrapTop] TrapTop[k_,n_] := Graphics[{Orange, Line[{ {a + (k-1) jump[n], f[a + (k-1) jump[n]]}, {a + k jump[n], f[a + k jump[n]]}}] }]\ \>", "Input", InitializationCell->True], Cell["\<\ TrapezoidsPicture[n_] := Show[picture, Table[SliceLine[k,n],{k,0,n}], Table[TrapTop[k,n],{k,1,n}], DisplayFunction->$DisplayFunction]\ \>", "Input", InitializationCell->True], Cell["\<\ TrapezoidsPicture::usage = \"TrapezoidsPicture[n] draws a picture \ of the trapezoid estimate. The function f and the values a and b must \ already be defined.\";\ \>", "Input", InitializationCell->True], Cell[BoxData[ \(Clear[TrapsEst]; \n TrapsEst[n_]\ := \ N[\ \((b\ - \ a)\)/n\ *\n\ \((\((f[a]\ + \ f[b])\)/2\ + \ Sum[f[a\ + \ i\ \((b\ - \ a)\)/n], \n \t\t\t\t\t\t\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ {i, \ 1, \ n - 1}])\)]\)], "Input", InitializationCell->True], Cell["\<\ TrapsEst::usage = \"TrapsEst[n] gives the numerical estimate using n trapezoids. The function f and the values a and b must already be \ defined.\";\ \>", "Input", InitializationCell->True], Cell["\<\ Clear[Traps] Traps[n_] := \tModule[{te}, \t\t\tTrapezoidsPicture[n]; \t\t\tte = TrapsEst[n]; \t\t\tPrint[\"Trapezoids estimate is \",te] \t\t ]\ \>", "Input", InitializationCell->True], Cell["\<\ Traps::usage = \"Traps[n] draws a picture of the trapezoid estimate \ using n trapezoids and prints out the estimate. The function f and the \ values a and b must already be defined.\";\ \>", "Input", InitializationCell->True] }, Closed]], Cell[CellGroupData[{ Cell["Random Rectangles", "Subsection", InitializationCell->True], Cell["Commands for drawing Random Rectangles", "Text", Evaluatable->False, InitializationCell->True], Cell["\<\ Clear[RandomRects, RandomRtop] RandomRtop[k_,n_] := Module[{xk, RandomRectSum}, xk = a + (k-1 + Random[ ])jump[n]; rk = jump[n]*f[xk]; {Graphics[{{DeepPink, Line[{ {a + (k-1) jump[n], f[xk]}, {a + k jump[n], f[xk]}}] }, If[Abs[f[xk]] > Abs[f[a + k jump[n]]], {DeepPink, Line[{ {a + k jump[n], f[xk]}, {a + k jump[n], f[a + k jump[n]]} }] }, {DeepPink, Point[{a + k jump[n], f[xk]}] }], If[Abs[f[xk]] > Abs[f[a + (k-1) jump[n]]], {DeepPink, Line[{ {a + (k-1) jump[n], f[xk]}, {a + (k-1) jump[n], f[a + (k-1) jump[n]]} }] }, {DeepPink, Point[{a + (k-1) jump[n], f[xk]}] }] }], rk}]\ \>", "Input", InitializationCell->True], Cell["\<\ RandomRects[n_] := \tModule[{tops, areasum, currentslice}, \t\t\tareasum = 0; \t\t\ttops = { }; \t\t\t \t\t\tDo[{currentslice = RandomRtop[k,n]; \t\t\t\tareasum = areasum + currentslice[[2]]; \t\t\t\ttops = Append[tops, currentslice[[1]]]}, \t\t\t\t{k,1,n}]; \t Show[picture, Table[SliceLine[k,n],{k,0,n}], Table[tops[[k]],{k,1,n}], \t\t DisplayFunction->$DisplayFunction]; \t\t Print[\"Random Rectangle estimate is \",areasum] ]\ \>", "Input", InitializationCell->True], Cell["\<\ RandomRects::usage = \"RandomRects[n] draws a picture of a random \ rectangle estimate using n rectangles and prints out the estimate. The \ function f and the values a and b must already be defined.\";\ \>", "Input", InitializationCell->True] }, Closed]] }, Open ]] }, Open ]] }, FrontEndVersion->"Macintosh 3.0", ScreenRectangle->{{0, 800}, {0, 580}}, AutoGeneratedPackage->None, WindowSize->{632, 433}, WindowMargins->{{4, Automatic}, {Automatic, 1}}, StyleDefinitions -> "ACStyles.nb", MacintoshSystemPageSetup->"\<\ 00<0001804P000000]P2:?oQon82n@960dL5:0?l0080001804P000000]P2:001 0000I00000400`<300000BL?00400@0000000000000006P801T1T00000000000 00000000000000000000000000000000\>" ] (*********************************************************************** Cached data follows. If you edit this Notebook file directly, not using Mathematica, you must remove the line containing CacheID at the top of the file. The cache data will then be recreated when you save this file from within Mathematica. ***********************************************************************) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[1731, 51, 79, 0, 152, "Title"], Cell[1813, 53, 122, 4, 87, "Subtitle"], Cell[CellGroupData[{ Cell[1960, 61, 23, 0, 55, "Section"], Cell[1986, 63, 676, 11, 128, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[2699, 79, 83, 1, 35, "Section"], Cell[2785, 82, 692, 22, 71, "Text"], Cell[3480, 106, 57, 0, 33, "Text"], Cell[3540, 108, 106, 2, 48, "Input"], Cell[3649, 112, 328, 10, 56, "Text"], Cell[3980, 124, 123, 2, 46, "Input"], Cell[4106, 128, 862, 25, 152, "Text"], Cell[4971, 155, 201, 4, 64, "Input"], Cell[5175, 161, 227, 6, 52, "Text"], Cell[5405, 169, 75, 1, 28, "Input"], Cell[5483, 172, 394, 12, 93, "Text"], Cell[5880, 186, 347, 8, 71, "Text"], Cell[6230, 196, 371, 8, 71, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[6638, 209, 32, 0, 35, "Section"], Cell[6673, 211, 349, 11, 53, "Text"], Cell[7025, 224, 1244, 42, 90, "Text"], Cell[8272, 268, 82, 2, 34, "Text"], Cell[8357, 272, 246, 6, 52, "Text"], Cell[8606, 280, 166, 3, 46, "Input"], Cell[8775, 285, 247, 5, 52, "Text"], Cell[9025, 292, 263, 6, 70, "Text"], Cell[9291, 300, 163, 5, 33, "Text"], Cell[9457, 307, 286, 5, 71, "Input"], Cell[9746, 314, 199, 6, 36, "Text"], Cell[9948, 322, 168, 3, 46, "Input"], Cell[10119, 327, 92, 3, 33, "Text"], Cell[10214, 332, 61, 1, 28, "Input"], Cell[10278, 335, 62, 0, 33, "Text"], Cell[10343, 337, 214, 5, 52, "Text"], Cell[10560, 344, 316, 6, 71, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[10913, 355, 94, 1, 35, "Section"], Cell[11010, 358, 498, 13, 74, "Text"], Cell[11511, 373, 101, 2, 82, "Input"], Cell[11615, 377, 496, 14, 71, "Text"], Cell[12114, 393, 51, 1, 28, "Input"], Cell[12168, 396, 112, 3, 33, "Text"], Cell[12283, 401, 51, 1, 28, "Input"], Cell[12337, 404, 127, 3, 33, "Text"], Cell[12467, 409, 51, 1, 28, "Input"], Cell[12521, 412, 135, 3, 33, "Text"], Cell[12659, 417, 51, 1, 28, "Input"], Cell[12713, 420, 299, 8, 52, "Text"], Cell[13015, 430, 854, 22, 109, "Text"], Cell[13872, 454, 410, 11, 71, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[14319, 470, 93, 1, 35, "Section"], Cell[14415, 473, 201, 4, 52, "Text"], Cell[14619, 479, 322, 13, 33, "Text"], Cell[14944, 494, 322, 13, 33, "Text"], Cell[15269, 509, 322, 13, 33, "Text"], Cell[15594, 524, 442, 14, 52, "Text"], Cell[16039, 540, 1416, 44, 180, "Text"], Cell[17458, 586, 424, 14, 54, "Text"], Cell[17885, 602, 4196, 76, 462, "Text"], Cell[22084, 680, 138, 5, 33, "Text"], Cell[22225, 687, 412, 9, 136, "Input"], Cell[22640, 698, 385, 10, 60, "Text"], Cell[23028, 710, 132, 2, 82, "Input"], Cell[23163, 714, 363, 8, 60, "Text"], Cell[23529, 724, 73, 1, 28, "Input"], Cell[23605, 727, 224, 6, 41, "Text"], Cell[23832, 735, 766, 14, 131, "Text"], Cell[24601, 751, 632, 14, 105, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[25270, 770, 31, 0, 35, "Section"], Cell[25304, 772, 409, 7, 90, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[25750, 784, 144, 3, 35, "Section", Evaluatable->False, InitializationCell->True], Cell[CellGroupData[{ Cell[25919, 791, 57, 1, 46, "Subsection", InitializationCell->True], Cell[25979, 794, 101, 1, 32, "Text", InitializationCell->True], Cell[26083, 797, 100, 4, 44, "Input", InitializationCell->True], Cell[26186, 803, 117, 4, 32, "Text", InitializationCell->True], Cell[26306, 809, 269, 6, 64, "Input", InitializationCell->True], Cell[26578, 817, 117, 4, 32, "Text", InitializationCell->True], Cell[26698, 823, 87, 4, 44, "Input", InitializationCell->True], Cell[26788, 829, 94, 1, 32, "Text", InitializationCell->True], Cell[26885, 832, 226, 8, 108, "Input", InitializationCell->True], Cell[27114, 842, 168, 6, 76, "Input", InitializationCell->True] }, Open ]], Cell[CellGroupData[{ Cell[27319, 853, 59, 1, 46, "Subsection", InitializationCell->True], Cell[27381, 856, 65, 1, 32, "Text", InitializationCell->True], Cell[27449, 859, 1134, 40, 620, "Input", InitializationCell->True], Cell[28586, 901, 225, 7, 92, "Input", InitializationCell->True], Cell[28814, 910, 216, 6, 76, "Input", InitializationCell->True], Cell[29033, 918, 440, 10, 153, "Input", InitializationCell->True], Cell[29476, 930, 211, 6, 76, "Input", InitializationCell->True], Cell[29690, 938, 207, 9, 124, "Input", InitializationCell->True], Cell[29900, 949, 246, 5, 76, "Input", InitializationCell->True], Cell[CellGroupData[{ Cell[30171, 958, 45, 1, 28, "Input"], Cell[30219, 961, 204, 3, 52, "Print"], Cell[30426, 966, 391, 11, 37, "Print"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[30866, 983, 66, 1, 46, "Subsection", InitializationCell->True], Cell[30935, 986, 113, 2, 34, "Text", Evaluatable->False, InitializationCell->True], Cell[31051, 990, 662, 19, 284, "Input", InitializationCell->True], Cell[31716, 1011, 228, 7, 92, "Input", InitializationCell->True], Cell[31947, 1020, 233, 5, 60, "Input", InitializationCell->True], Cell[32183, 1027, 1649, 42, 82, "Input", InitializationCell->True], Cell[33835, 1071, 220, 6, 60, "Input", InitializationCell->True], Cell[34058, 1079, 222, 9, 124, "Input", InitializationCell->True], Cell[34283, 1090, 255, 5, 60, "Input", InitializationCell->True] }, Closed]], Cell[CellGroupData[{ Cell[34575, 1100, 65, 1, 30, "Subsection", InitializationCell->True], Cell[34643, 1103, 143, 5, 33, "Text", Evaluatable->False, InitializationCell->True], Cell[34789, 1110, 647, 19, 284, "Input", InitializationCell->True], Cell[35439, 1131, 226, 7, 92, "Input", InitializationCell->True], Cell[35668, 1140, 230, 5, 60, "Input", InitializationCell->True], Cell[35901, 1147, 1876, 47, 82, "Input", InitializationCell->True], Cell[37780, 1196, 217, 6, 76, "Input", InitializationCell->True], Cell[38000, 1204, 217, 9, 124, "Input", InitializationCell->True], Cell[38220, 1215, 252, 5, 60, "Input", InitializationCell->True] }, Closed]], Cell[CellGroupData[{ Cell[38509, 1225, 67, 1, 30, "Subsection", InitializationCell->True], Cell[38579, 1228, 116, 2, 34, "Text", Evaluatable->False, InitializationCell->True], Cell[38698, 1232, 1155, 39, 604, "Input", InitializationCell->True], Cell[39856, 1273, 228, 7, 92, "Input", InitializationCell->True], Cell[40087, 1282, 236, 5, 60, "Input", InitializationCell->True], Cell[40326, 1289, 1890, 47, 82, "Input", InitializationCell->True], Cell[42219, 1338, 215, 5, 60, "Input", InitializationCell->True], Cell[42437, 1345, 224, 9, 124, "Input", InitializationCell->True], Cell[42664, 1356, 258, 5, 60, "Input", InitializationCell->True] }, Closed]], Cell[CellGroupData[{ Cell[42959, 1366, 60, 1, 30, "Subsection", InitializationCell->True], Cell[43022, 1369, 319, 11, 156, "Input", InitializationCell->True], Cell[43344, 1382, 218, 7, 92, "Input", InitializationCell->True], Cell[43565, 1391, 216, 5, 60, "Input", InitializationCell->True], Cell[43784, 1398, 426, 9, 82, "Input", InitializationCell->True], Cell[44213, 1409, 202, 5, 60, "Input", InitializationCell->True], Cell[44418, 1416, 197, 9, 124, "Input", InitializationCell->True], Cell[44618, 1427, 239, 5, 60, "Input", InitializationCell->True] }, Closed]], Cell[CellGroupData[{ Cell[44894, 1437, 67, 1, 30, "Subsection", InitializationCell->True], Cell[44964, 1440, 104, 2, 34, "Text", Evaluatable->False, InitializationCell->True], Cell[45071, 1444, 1098, 36, 556, "Input", InitializationCell->True], Cell[46172, 1482, 572, 19, 284, "Input", InitializationCell->True], Cell[46747, 1503, 256, 5, 60, "Input", InitializationCell->True] }, Closed]] }, Open ]] }, Open ]] } ] *) (*********************************************************************** End of Mathematica Notebook file. ***********************************************************************)