Riemann Sum Visualizer

Plots a right Riemann sum for a variety of functions and displays the corresponding notation.

Function Type

$$f(x) = x+1$$


Start Value \((x=a)\)
End Value \((x=b)\)
Number of Rectangles \((n)\)
iChoose \(n=0\) for the definite integral.

Note that for certain functions and small, positive values of \(n\) \((n<10)\), the graphed Riemann sum may be slightly inaccurate in that it may 'bleed' over the x-axis. The calculations at the bottom are still accurate however.

Finding the area under the curve using these Riemann sums involves essentially just summing the areas of all of the little rectangles underneath the curve. Informally, this looks like: $$\sum \, (\textrm{length of rectangle})(\textrm{width of rectangle})$$ (The \(\Sigma\) just means that we are summing together the areas of all of the rectangles, instead of just one.)

To make this a little more formal, we may write: $$\sum \, (f(x_{i}))(\Delta x)$$ Here, \(x_{i}\) is the x-value of the right edge of a rectangle, and \(f(x_{i})\) represents the height of this rectangle under the graph. The \(\Delta x\) is the width of this rectangle, which we will keep constant for the purposes of this derivation.

Still, this notation is incomplete. We need to include the \(a\), \(b\), and \(n\) values in the sum. We can represent the width of each rectangle by the fraction: $$\textrm{width of rectangle}=\Delta x=\frac{\textrm{length of interval}}{\textrm{number of rectangles}}=\frac{b-a}{n}$$ Think: Let's say we have an interval that is 20 units long, (\(b-a=20\)) and we have 10 rectangles (\(n=10\)) in that interval. It makes sense that the width of each rectangle (given equal widths for each rectangle) must be 2 units.

The height of each rectangle is a little bit more complicated. We know that the height of the first rectangle on the graph is \(f(a+\textrm{width})\) or \(f(a+\frac{b-a}{n})\). Why? Because this is a right Riemann sum, the height is given by the function at the right edge of the rectangle. Evaluating just at \(f(a)\) would give us the left edge, so we add by the width of one rectangle to move over to the right edge.

We therefore naturally expect the height of the second rectangle to be \(f(a+2\cdot\textrm{width})\), or \(f(a+2\cdot\frac{b-a}{n})\). We may generalize this pattern, and state that the height of the \(k\)-th rectangle is: $$f(a+k\cdot\frac{b-a}{n})$$ You may think of the function argument (the expression inside of the function parentheses) as a little pointer under the graph. At \(x=a\), the pointer sits right under the left edge of the first rectangle. At \(x=a+\frac{b-a}{n}\), it sits under the right edge of the first rectangle. At \(x=a+5\cdot\frac{b-a}{n}\), it sits under the right edge of the fifth rectangle.

Putting what we have together, we arrive at $$\sum \Bigl(f\,\Bigl(a+k\cdot\frac{b-a}{n}\Bigr)\Bigr)\Bigl(\frac{b-a}{n}\Bigr)$$ We're almost done, we just need to add a few finishing details. To make this notation fully complete, we need to add upper and lower summation bounds to the sum. Doing this, we finally arrive at: $$\textrm{Area under the curve} \approx \sum_{k=1}^{n} \Bigl(f\,\Bigl(a+k\cdot\frac{b-a}{n}\Bigr)\Bigr)\Bigl(\frac{b-a}{n}\Bigr)$$ These bounds essentially tell us that we are summing through different values of \(k\), starting at 1 and ending at \(n\). Once \(k\) reaches \(n\), we have reached the last rectangle and the sum is complete. To investigate further, we can expand out the formula we've just created.

Let's consider a sum with 3 rectangles (\(n=3\)). In our formula, this would look like: $$S=\sum_{k=1}^{3} \Bigl(f\,\Bigl(a+k\cdot\frac{b-a}{3}\Bigr)\Bigr)\Bigl(\frac{b-a}{3}\Bigr)$$ We can rewrite this sum by expanding it out: $$S=\Bigl(f\,\Bigl(a+1\cdot\frac{b-a}{3}\Bigr)\Bigr)\Bigl(\frac{b-a}{3}\Bigr)+\Bigl(f\,\Bigl(a+2\cdot\frac{b-a}{3}\Bigr)\Bigr)\Bigl(\frac{b-a}{3}\Bigr)+\Bigl(f\,\Bigl(a+3\cdot\frac{b-a}{3}\Bigr)\Bigr)\Bigl(\frac{b-a}{3}\Bigr)$$ Notice how the value \(k\) had been replaced with 1, 2, and 3. It ends at 3 because we only have 3 rectangles, as stated in our initial condition, \(n=3\). If we had 74 rectangles, we would've had a sum with 74 terms, and 74 different values for \(k\). The \(\Sigma\) is therefore a powerful notational tool for condensing these very large sums.

From here we can formally define the Riemann integral[1] by taking the limit of the sum as \(n\to\infty\): $$\textrm{Area under the curve} = \lim_{n\to\infty} \sum_{k=1}^{n} \Bigl(f\,\Bigl(a+k\cdot\frac{b-a}{n}\Bigr)\Bigr)\Bigl(\frac{b-a}{n}\Bigr)=\int_{a}^{b} f(x)\,dx$$ If the limit exists, then the function is said to be Riemann integrable on the interval \([a,b]\). If the limit DNE (does not exist), then the Riemann integral is undefined on the interval \([a,b]\).

Fundamentally, nothing has changed here. Now, instead of taking some finite number of rectangles, we imagine an "infinite"[2] number of "infinitely"[2] thin rectangles assembling themselves underneath the curve. In terms of the notation, \(f(x)\) represents the height of these rectangles, and \(dx\) is the width. We sum the areas of all of these tiny rectangles (\(f(x)\cdot dx\)) from \(x=a\) to \(x=b\). Don't be confused by the notation here. The \(k\) and the \(n\) above and below the sum (\(\Sigma\)) do not mean the same thing as the \(a\) and the \(b\) above and below the integral.

To summarize, enjoy this color-coded explanation of the notation: $${\color{#c43119} \textrm{Area}} \; {\color{#0086b3} \approx} \, {\color{navy} \sum_{k=1}^{n}} {\color{purple} \Bigl(f\,\Bigl(a+{\color{blue} k}\cdot\frac{b-a}{n}\Bigr)\Bigr)}{\color{green} \Bigl(\frac{b-a}{n}\Bigr)}$$ To approximate the area under the curve, multiply the height by the width to get the area of a rectangle, and then sum the areas of each of the rectangles together.

FOOTNOTES
1. Historically, Riemann had never defined the integral this way. In fact, this is much simpler than his original formulation. More precisely, this definition makes two assumptions about the partitions of the interval that are not present in the historical definition: that each sub-interval of the partition is of equal width, and that the height of each rectangle necessarily be given by the end of the sub-interval. With some work, however, it can be shown that these two definitions are equivalent. Learn more on Wikipedia.

2. This is an extreme oversimplification. Things are not actually becoming infinitely large or small, but it's often useful to act as if they are.