← SciSim / Mathematics

Riemann Sums & the Definite Integral

Left, right, midpoint, trapezoidal, Simpson -- error rates on log-log plot, convergence animated.
🎓 Tier: HSC / Early Undergraduate -- Single-Variable Calculus

📊 Section 1 -- Interactive Simulation

S_n
--
Exact
--
|Error|
--
n
--
Rule
--
Order
--

Controls

Function & Rule

Display

💡 Section 2 -- The Idea, Step by Step

One idea — adding up many thin rectangles — is the whole engine behind the definite integral. Here it is, built from a playground picture all the way up to the calculus statement.

Start -- Tiling a Curvy Shape

Suppose you want the area of a hill whose top is a curve. You can't just do length × width, because the top isn't flat. So cover the region with thin vertical strips, like floor tiles stood on end. Each tile is a skinny rectangle, and rectangles are easy: area = height × width. Add up every tile and you get a close estimate of the curvy area. Make the tiles thinner and the estimate gets better.

Build -- Naming the Pieces

Slice the interval $[a,b]$ into $n$ equal strips. Each strip has width $\Delta x=\frac{b-a}{n}$, and its height is the function value $f(x_i)$ at a sample point inside the strip. One strip's area is $f(x_i)\,\Delta x$, so the whole estimate is the Riemann sum $S_n=\sum_{i=1}^{n} f(x_i)\,\Delta x$. For $f(x)=x^2$ on $[0,1]$ with $n=4$ left-corner samples, $S_4=0.25\,(0+0.0625+0.25+0.5625)=0.219$ — already close to the true area $\tfrac13\approx0.333$.

Deepen -- Letting the Strips Vanish

Now let $n\to\infty$, so $\Delta x\to0$. The staircase of rectangles presses onto the curve and $S_n$ settles on a single number — the definite integral $\int_a^b f(x)\,dx$. For a continuous $f$ it doesn't matter whether you sample each strip on the left, right, or middle: every choice shares the same limit. The choices differ only in speed. Left and right corners trail the answer like $O(h)$, midpoint and trapezoid like $O(h^2)$, and Simpson's little parabolas like $O(h^4)$ — so each halving of the strip width shrinks Simpson's error roughly 16×.

Try This in the Sim Above

Set Rule = Left and drag n from 2 to 100 — watch $S_n$ climb toward $0.3333$ while $|\text{Error}|$ collapses. Switch Rule = Simpson at $n=4$: its error is already about $10^{-5}$, far below Left at the same $n$. Then open the Error Rates tab to see each rule as a straight line on log-log axes — the steeper the line, the faster it converges, and Simpson's is steepest.

📐 Section 3 -- Riemann Sums

Definite Integral as Limit

$$\int_a^b f(x)\,dx=\lim_{n\to\infty}\sum_{i=1}^n f(x_i^*)\,\Delta x,\quad \Delta x=\frac{b-a}{n}.$$

RuleFormulaError order
Left$\sum f(x_{i-1})\,\Delta x$$O(h)$
Midpoint$\sum f(x_{i-1/2})\,\Delta x$$O(h^2)$
Trapezoidal$\frac{h}{2}[f_0+2f_1+\cdots+f_n]$$O(h^2)$
Simpson$\frac{h}{3}[f_0+4f_1+2f_2+\cdots+f_n]$$O(h^4)$
Step 1 -- Riemann Definition

Partition $[a,b]$: $a=x_0<\cdots

Step 2 -- Trapezoidal Rule

Linear interpolation on each subinterval: $T_n=h/2[f_0+2f_1+\cdots+2f_{n-1}+f_n]$. Error bound: $|E_T|\leq M_2(b-a)^3/(12n^2)$.

Step 3 -- Simpson's Rule

Quadratic fit per pair of intervals (n must be even): $S_n=h/3[f_0+4f_1+2f_2+4f_3+\cdots+f_n]$. Error $O(h^4)$ -- exact for polynomials up to degree 3.

Step 4 -- Worked: int_0^1 x^2 dx

Simpson n=2: h=0.5, f_0=0, f_1=0.25, f_2=1. $S=(0.5/3)[0+4(0.25)+1]=1/3$ exactly. Simpson is exact for quadratics since error involves $f^{(4)}=0$.

Step 5 -- Integrable Functions

Every continuous function is Riemann integrable. Every monotone bounded function is integrable. NOT integrable: Dirichlet function (1 on rationals, 0 on irrationals). Lebesgue integral handles this general case.

Step 6 -- FTC Connection

By MVT: $F(x_i)-F(x_{i-1})=f(c_i)\Delta x$. Summing: $F(b)-F(a)=\sum f(c_i)\Delta x$ -- a Riemann sum. As $n\to\infty$: $F(b)-F(a)=\int_a^b f(x)\,dx$.

Reference: Stewart -- Calculus §5.1-5.3; Spivak -- Calculus Ch.13; Burden & Faires -- Numerical Analysis §4.

❓ Section 4 -- FAQ

🧮Conceptual  What do the rectangles represent?

Each rectangle has width Delta-x and height f(x_i*). Its area approximates the signed area under the curve on that subinterval. As n increases, the rectangles become thinner and the total area converges to the integral.

Key takeaway: Each rectangle area = f(xi)*Delta_x. Sum approximates signed area under curve.
🔬Simulation  What does the error log-log plot show?

Four rules plotted as |error| vs n on log-log axes. Left/Right: slope 1 (O(h)). Midpoint/Trap: slope 2 (O(h^2)). Simpson: slope 4 (O(h^4)). Steeper slope = faster convergence. Doubling n: Simpson error shrinks by factor 16.

Key takeaway: Slope on log-log error plot = convergence order. Simpson slope 4 is far better than Left slope 1.
🌍Applied  Where is numerical integration used?

Finite element analysis (structural engineering). Monte Carlo integration for high-dimensional probability in ML. Computer graphics: light transport path integrals. Quantum chemistry: electron orbital calculations. GPS satellite orbit prediction.

Key takeaway: FEM, Monte Carlo ML, light transport, quantum chemistry -- all numerical integration.
💡Non-Obvious  Simpson exact for cubics despite using quadratics?

Yes. The error per Simpson panel is O(h^5), giving O(h^4) globally. The error involves the 4th derivative -- zero for cubics. This superconvergence makes Simpson dramatically better than trapezoidal for smooth functions.

Key takeaway: Simpson integrates cubics exactly because error involves f^(4) = 0 for polynomials of degree <= 3.
📐Computational  Simpson for int_0^1 e^x with n=4.

h=0.25. S=(0.25/3)[1 + 4*e^0.25 + 2*e^0.5 + 4*e^0.75 + e] = (0.25/3)*20.620 = 1.71832. Exact: e-1=1.71828. Error~4e-5. Left Riemann n=4 gives ~1.512 with error~0.206. Simpson is ~5500x more accurate.

Key takeaway: Simpson n=4 error ~4e-5. Left n=4 error ~0.21. Factor of ~5500 improvement from 4 subintervals.
🎓Deep  What is the Lebesgue integral?

Riemann partitions the x-axis. Lebesgue partitions the y-axis (values of f): int f d_mu = int_0^inf mu({f>t}) dt (layer-cake). Integrates more functions, has stronger limit theorems (dominated convergence), and works on abstract measure spaces. Foundation of modern probability theory.

Key takeaway: Lebesgue partitions y-axis, integrates more functions, has better limit theorems. Basis of probability theory.
Best resources: 3Blue1Brown -- Essence of Calculus; MIT OCW 18.01; Paul's Online Math Notes.

⚠️ Section 5 -- Misconceptions

A · Conceptual Misconceptions
❌ Misconception: Integral always positive.✅ Correction: Integral = signed area. For f < 0, integral is negative. Total unsigned area = int|f(x)|dx.🔍 Students confuse signed integral with geometric area.📖 Stewart §5.2.
❌ Misconception: Need continuity for Riemann integrability.✅ Correction: Sufficient not necessary. Monotone bounded functions integrable even with jump discontinuities.🔍 Students think any discontinuity prevents integrability.📖 Spivak Ch.13.
❌ Misconception: More n is always better for Simpson's.✅ Correction: Floating-point roundoff cancellation worsens results for very small h. Optimal n balances truncation O(h^4) and roundoff O(eps/h^4). Practically n~1000.🔍 Students ignore floating-point cancellation at very large n.📖 Burden & Faires §4.
B · Common Procedural Errors
❌ Error: Left n=4 on [0,1]: using x=0,0.25,0.5,0.75,1 (5 sample points).✅ Correct: Left sum uses n=4 LEFT endpoints: x=0,0.25,0.5,0.75 only. Not x=1 (that is the right endpoint).🔍 Students use n+1 sample points for n-rectangle left sum.📖 Stewart §5.1.
❌ Error: Applying Simpson's rule with n=3 (odd).✅ Correct: Simpson requires n EVEN. Each application covers 2 subintervals using 3 points. Odd n leaves an unpaired subinterval.🔍 Students apply Simpson's without checking n is even.📖 Burden & Faires §4.
❌ Error: Trapezoidal: f(x0)+f(x1)+...+f(xn) times h (no endpoint halving).✅ Correct: T=(h/2)[f(x0) + 2f(x1) + ... + 2f(x_{n-1}) + f(xn)]. Endpoints have weight 1/2.🔍 Students forget the half-weight on the first and last terms.📖 Burden & Faires §4.
Education research: Tall & Vinner -- ESM 1981.