This demo allows one to approximate the (net) area under a curve using left, right, mipoint, trapezoid, and Simpson rules. Specifically we are trying to approximate $\int_a^b f(x)\,dx$ using $N$ rectangles (or trapezoids or parabolas).
Several built-in demos (in the drop-down box) are provided. Otherwise you can specify an example of your own. You can enter a formula in the box next to "$f(x)=$". Then you may select the interval in which you are working: $I = [a,b]$ and specify the number of subintervals/rectangles (or trapezoids): $N$.
The demo computes an equally spaced partition of $I=[a,b]$. In particular, let $\Delta x = \dfrac{b-a}{N}$ then $x_0=a$, $x_1=a+\Delta x$, ..., $x_N=b$.
The demo then computes \[ L_N = f(x_0)\Delta x + f(x_1)\Delta x + \cdots + f(x_{N-1}) \Delta x \qquad \mbox{(the left hand sum approximation)} \] \[ R_N = f(x_1)\Delta x + f(x_2)\Delta x + \cdots + f(x_{N}) \Delta x \qquad \mbox{(the right hand sum approximation)} \] \[ M_N = f(x_0+\Delta x/2)\Delta x + f(x_1 +\Delta x/2)\Delta x + \cdots + f(x_{N-1} +\Delta x/2)\Delta x \qquad \mbox{(the midpoint rule approximation)} \] \[ T_N = \dfrac{L_N+R_N}{2} \qquad \mbox{(the trapezoid rule approximation)} \] \[ S_N = \dfrac{2}{3}M_N + \dfrac{1}{3}T_N \qquad \mbox{(the Simpson's rule approximation)} \] If "calculation details" is selected in the "Show" drop down box, the details of the calculations of $L_N$, $R_N$, and $M_N$ are displayed.
The demo also generates a plot. Each partition point, corresponding point on the graph, as well as the graph of $f(x)$ itself are plotted.
If the "left hand rule" display box is checked, the corresponding left hand approximation rectangles are plotted in light blue. For "right hand rule", green boxes are plotted. If "midpoint rule" is checked, the corresponding boxes are plotted in blue. If the "trapezoid rule" display box is checked, the corresponding trapezoids are displayed (in violet). If "Simpson's rule" is checked, parabolas (in light purple) are displayed. If the "shade exact area" box is checked, the area under the graph is colored in gray.
Note: The details in the detailed calculations are rounded to 5 digits to make the calculations more readable.
The computation above is powered by SageMath. The Sage code is embedded in this webpage's html file. To view the code instruct your browser to show you this page's source. For example, in Chrome, right-click and choose "View page source".