Approximating Integrals
\(f(x) = \)  
Number of subintervals:
Interval: [, ]
Approximating Integral
There are a number of methods for approximating the definite integral of a function \(f\) over a closed interval \([a,b]\).

Riemann sums are just one example, named for Bernhard Riemann. The idea is to partition the interval into \(n\) smaller pieces. For each subinterval \([x_i, x_{i+1}]\), a representative point \(x^*\) is chosen. Adding the area of the rectangles with width \(x_{i+1} - x_i\) and height \(f(x^*)\) yields an approximation of the integral: \[ \int_a^b f(x)dx \approx \sum_{i=0}^{n-1} f(x^*)(x_{i+1} - x_i) \] As the number of subintervals increases towards infinity, the approximation will approach the actual Riemann integral of the function.

While the width of the subintervals is not required to be equal, many common formulations of the Riemann sum use a constant width. The representative point chosen from each subinterval can, in general, be any point in that subinterval. However, the Riemann sums considered in this app are defined by the points chosen: The trapezoidal rule, also a Riemann sum, differs from the above methods in that instead of adding rectangular areas on each subinterval \([x_i, x_{i+1}]\), we sum the area of a trapezoid with vertices \([x_i, 0], [x_{i+1}, 0], [x_i, f(x_i)], [x_{i+1}, f(x_{i+1})]\). The value of the approximation given by the trapezoidal rule is the average of the approximations given by the left and right endpoint rules.

Simpson's rule requires an even number of subintervals, which are paired together. A quadratic interpolating polynomial through the points on the curve at left endpoint, right endpoint, and center of each pairing of subintervals is used instead of a straight line at the top of the subdivisions. As a result, Simpson's rule gives the exact value of the integral for any quadratic polynomial. The rule is named for Thomas Simpson, though it was previously found by Johannes Kepler.
Using the Applet
Enter a function, the number of subintervals, and the lower and upper bounds for the definite integral. Each of the approximations, along with their error, will be updated. Click on a rule to toggle the display of that rule in the graph. Note that Simpson's rule is only available for an even number of intervals.

Click and drag to move the graph, and adjust the view with the zoom range below the graph.
About the Applet
This applet was created using JavaScript and the Konva graphics library.