An illustration of Riemann sums

Choose a function, method, and partition size to compute and visualize the corresponding numerical integration approximation. The midpoint sum allows you the opportunity to "skew" the rectangles, illustrating the relationship with the trapezoidal sum.

Skew rectangle Approximation $\approx$ Error $\approx$
$f(x)=x^2+x/2+1/3$ $f(x)=\sin(x)$ $f(x)=\sin(\pi \, x^2)$ $f(x)=e^{-x^2}$

In principle, computing these kinds of sums is easy on a computer. Here's a little Sage code to estimate $$\int_{-1}^1 e^{-x^2} dx.$$

Note how close the code is to the mathematical notation. For example, the right sum $$\sum_{i=1}^n f(x_i)\Delta x$$ is expressed as
sum(f(x(i))*dx, i,1,n)