Numerical Integration: The Riemann Sum
You know the integral is the area under a curve. But how does a computer measure that area when there's no neat formula? It cheats — by chopping the area into rectangles it can easily add up.
The Riemann sum — the oldest trick in calculus:
1. Slice the region under the curve into thin vertical strips, each dt wide.
2. Turn each strip into a rectangle: width = dt, height = the function's value there.
3. Add up all the rectangle areas. That sum approximates the true area.
That's it. Area of one rectangle = height × width = f(t) · dt. Sum them and you've integrated.
∫ f(t) dt ≈ Σ f(tᵢ) · dt
The integral (smooth area) is approximated by a sum of rectangle areas. As dt → 0, the approximation becomes exact.
The tradeoff is the same one as derivatives. Thinner rectangles (small dt) hug the curve better → more accurate. But more rectangles = more computation. Too-fat rectangles = fast but crude.
A subtle bias. If we build each rectangle using its left edge for the height while the curve is rising, every rectangle sits a little below the curve — so we underestimate the area. (Use the right edge on a rising curve and you'd overestimate.) Keep that in mind when you play with the explorer next.
🦌 Ilya says: the Riemann sum isn't just a toy. It's the seed of Euler's method — the way we'll actually simulate a neuron's voltage over time in the next quest. Add up tiny changes step by step → you've integrated the neuron's equation.