Lesson 8 of 18

Left Riemann Sum

The Definite Integral

The definite integral ∫abf(x) dx\int_a^b f(x)\, dx is the signed area between ff and the x-axis from aa to bb.

It is defined as the limit of Riemann sums — sums of rectangle areas:

∫abf(x) dx=lim⁡n→∞∑if(xi)⋅Δx\int_a^b f(x)\, dx = \lim_{n \to \infty} \sum_{i} f(x_i) \cdot \Delta x

where Δx=b−an\Delta x = \frac{b-a}{n} and xix_i is some point in the ii-th subinterval.

Left Riemann Sum

Use the left endpoint of each subinterval:

∑i=0n−1f(a+i⋅h)⋅hwhere h=b−an\sum_{i=0}^{n-1} f(a + i \cdot h) \cdot h \quad \text{where } h = \frac{b-a}{n}

a    a+h  a+2h       b
|----|----|----...---|
^    ^    ^
left endpoints used

Accuracy

For an increasing function, the left sum underestimates the integral (the rectangles don't reach the curve). For a decreasing function, it overestimates. Error is O(h)O(h) — halving nn halves the error.

Example

∫01x2 dx\int_0^1 x^2\, dx with n=4n=4, h=0.25h=0.25:

  • 0.25⋅(f(0)+f(0.25)+f(0.5)+f(0.75))0.25 \cdot (f(0) + f(0.25) + f(0.5) + f(0.75))
  • =0.25⋅(0+0.0625+0.25+0.5625)= 0.25 \cdot (0 + 0.0625 + 0.25 + 0.5625)
  • =0.25⋅0.875=0.21875= 0.25 \cdot 0.875 = 0.21875
  • Exact: 13≈0.3333\frac{1}{3} \approx 0.3333 — the left sum underestimates

Your Task

Implement double riemann_left(double (*f)(double), double a, double b, int n).

TCC compiler loading...
Loading...
Click "Run" to execute your code.