HomeMathematicsWind Farm: A Riemann Integral Simulation

∫ Wind Farm: A Riemann Integral Simulation

Visualise Riemann sums converging to the true integral. Compare Left, Right, Midpoint, and Trapezoid rules. Animate rectangles filling in under the curve, track error vs N, and see how each method converges.

Mathematics3DModerate60 FPS
riemann-integral ↗ Open standalone

About this simulation

This simulator visualises Riemann sums converging to the exact definite integral of five functions — sin x, x², eˣ, |x|, and √x — over an adjustable interval [a, b]. Each of the N subintervals has a fixed width Δx = (b−a)/N, and its rectangle's height is sampled per one of four classic rules — Left endpoint f(x₀), Right endpoint f(x₁), Midpoint f((x₀+x₁)/2), or Trapezoid ½(f(x₀)+f(x₁)) — then summed and multiplied by Δx. The canvas draws these N shapes beneath the true curve, while a lower strip re-plots the absolute error |sum−exact| for every n from 1 up to min(N+1, 50), so you can watch first-order and second-order convergence side by side.

🔬 What it shows

The main canvas overlays N Left/Right/Midpoint rectangles or Trapezoid panels against the true function curve (drawn in white) between the dashed bounds a and b; the strip beneath it plots how the approximation error shrinks as N grows, letting you compare how quickly each rule converges.

🎮 How to use it

Pick a function (sin x, x², eˣ, |x|, or √x), choose a summation rule, then drag the Subintervals slider (1–200) and the a/b sliders to reshape the interval. The stats bar below the canvas updates the Riemann sum, exact integral, error, and Δx live as you move any control.

💡 Did you know?

The simulator recomputes the whole error-vs-N curve every frame by re-running riemannSum() for n = 1 up to min(N+1, 50). Averaging Midpoint and Trapezoid two-to-one — (2×Midpoint + Trapezoid)/3 — reproduces Simpson's Rule, whose error shrinks as O(Δx⁴), far faster than either rule alone.

Frequently asked questions

Why does the Trapezoid rule draw slanted tops instead of flat rectangles?

In the draw() function, method === "trap" is the only branch that fills a quadrilateral connecting (x₀,0) → (x₀,f(x₀)) → (x₁,f(x₁)) → (x₁,0), instead of a single sampled height like Left, Right, and Midpoint. That slanted top is exactly the average ½(f(x₀)+f(x₁)) used by riemannSum() for the trapezoid method.

Why is the plotted error so much larger for eˣ than for sin x at the same N?

The theoretical bound |error| ≤ M·(b−a)³/(12N²) depends on M = max|f″| over [a,b]. Since sin x has |f″| bounded by 1 everywhere, while eˣ's second derivative is eˣ itself and grows without bound as b increases, the same N produces a visibly larger error curve for eˣ in the lower panel.

Why does √x behave oddly when the lower bound a is negative?

FUNS.sqrt.f returns 0 for any x < 0 (x ≥ 0 ? Math.sqrt(x) : 0), and its exact() clamps both limits to max(0,·) before integrating. So dragging a below zero doesn't extrapolate a negative square root — the simulator simply treats the integrand as zero on that portion of the interval, matching √x's real domain restriction.

What exactly does the lower error panel plot, and why does it stop at 50?

For every n from 1 up to min(N+1, 50), the script calls riemannSum(fn, a, b, n, method), takes the absolute difference from the exact integral, and plots the resulting curve. The cap at 50 points keeps the per-frame recomputation cheap even when the Subintervals slider N is pushed up to its maximum of 200.

Why do Midpoint and Trapezoid errors shrink faster than Left and Right as N increases?

Left and Right sample only one endpoint of each subinterval, so their local error per panel is O(Δx) and the total error scales as O(Δx); Midpoint and Trapezoid effectively average out the curvature of f across the panel, giving O(Δx²) local error and total error — the same second-order convergence guaranteed by the |error| ≤ M(b−a)³/(12N²) bound shown in the info panel.

⚙ Under the hood

Observe how kinetic energy is converted into electricity by a wind farm, visualized through the lens of Riemann sums. Manipulate turbine blade angles and wind speed to understand their effect on power generation.

Riemann IntegralRiemann SumsTrapezoid Rules

3D · Three.js / WebGL renderer · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)