How to Animate Riemann Sums | QuantumSketch
Animate Riemann sums by filling the area under a curve with rectangles, then increasing their count so the staircase converges to the exact integral.
Animate Riemann sums by filling the area under a curve with rectangles, then increasing their count so the staircase converges to the exact integral. Watching the rectangles thin out is the definition of integration.
The core idea
A definite integral is the area under a curve. A Riemann sum approximates that area with rectangles:
As the number of rectangles n โ โ, the approximation becomes exact.
The animation, beat by beat
- Plot the curve
f(x) = xยฒon[0, 2]. - Add 4 rectangles โ a chunky staircase that misses area.
- Increase n: 4 โ 10 โ 50 โ 200. Rectangles thin; the staircase hugs the curve.
- Show the running total approaching 8/3 โ 2.667.
- Declare the limit = the integral.
Compare the three rules
| Rule | Rectangle height from | For increasing f | |---|---|---| | Left | left endpoint | underestimates | | Right | right endpoint | overestimates | | Midpoint | midpoint | closest |
Animating all three converging side by side is a memorable lesson. Pairs naturally with Animate the Derivative โ the inverse operation.
Manim building blocks
axes.plot for the curve and axes.get_riemann_rectangles โ a built-in that generates the rectangles for a given n. Animate Transform between successive n values; a DecimalNumber shows the running sum.
The prompt
"Show the area under f(x)=xยฒ on [0,2] with Riemann rectangles, increasing n from 4 to 200 so the sum converges to 8/3."
โ Render it at quantumsketch.app.
Written by Shihab Shahriar Antor ยท Shahriar Labs
FAQ
Q.How does an animation show that a Riemann sum becomes an integral?
By increasing the number of rectangles. A Riemann sum approximates the area under a curve with a row of rectangles whose heights touch the curve. With just a few rectangles, the staircase visibly under- or over-shoots the true area. As you animate the number of rectangles increasing โ 4, then 10, then 50, then 200 โ the rectangles get thinner and the staircase hugs the curve more tightly, and the total rectangle area converges to a single number. That limit is the definite integral, so the animation shows the integral being born from finer and finer sums.
Q.Can I animate left, right, and midpoint Riemann sums to compare them?
Yes, and it's a great teaching clip. Show the same curve three times with left-endpoint, right-endpoint, and midpoint rectangles, and animate each refining as n grows. For an increasing function, left sums underestimate and right sums overestimate, while the midpoint rule is closer for the same n โ all of which is obvious visually but tedious to explain in symbols. Describe the comparison as a prompt and QuantumSketch renders the three methods converging side by side as a narrated Manim animation.