Area Approximation Demo

This demo allows one to approximate the (net) area under a curve using left, right, and trapezoid rules. Specifically we are trying to approximate $\int_a^b f(x)\,dx$ using $N$ rectangles (or trapezoids).

Several built-in demos (in the drop-down box) are provided. Otherwise you can specify an example of your own. If you select "formula" (the default), 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 a partition of $I=[a,b]$ using equally spaced partition points. Say $\Delta x = \dfrac{b-a}{N}$ then $x_0=a$, $x_1=a+\Delta x$, ..., $x_N=b$. If you want to override this choice, you may specify your own list of partition points in the box next to "$x=$".

Next, the demo computes a list of outputs ($y$ values). This is $f(x)$ evaluated at each $x$ in your list of $x$ values (i.e. partition points). If you select "table", you can specify your own $y$ values (this list must be of the same length as the $x$ list). So "table" allows you the option of specifying a function via a table of values instead of a formula.

Given this set up, $L_N$ (the left hand rule approximation), $R_N$ (the right hand rule approximation), $T_N$ (the trapezoid rule approximation), and $\int_a^b f(x)\,dx$ (the exact value) are computed. If "calculation details" is selected in the "Show" drop down box, the details of the calculations of $L_N$ and $R_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 "table" was selected, a interpolating polynomial is computed and that is plotted instead of $f(x)$).

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 the "trapezoid rule" display box is checked, the corresponding trapezoids are displayed (in violet). If the "shade exact area" box is checked, the area under the graph is colored in gray.

Note: I have rounded all values to 5 digits so many of these calculations suffer from significant rounding error. The purpose of this demo is not to provide accurate calculations, but rather to demonstrate how such calculations of are done and what the approximations mean graphically.

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".