Lesson 13 of 15

Riemann Sums

Riemann Sums

Integration in real analysis is built on Riemann sums -- approximations of the area under a curve using rectangles.

Definition

A Riemann sum for (f) on ([a, b]) with (n) subintervals is:

Sn=i=1nf(xi)ΔxS_n = \sum_{i=1}^{n} f(x_i^*) \cdot \Delta x

where (\Delta x = (b - a) / n) and (x_i^*) is a sample point in the (i)-th subinterval.

Types of Riemann Sums

TypeSample point
Left(x_i^* = a + (i-1) \Delta x)
Right(x_i^* = a + i \Delta x)
Midpoint(x_i^* = a + (i - 0.5) \Delta x)

Convergence

As (n \to \infty), all three types converge to the same value: the Riemann integral (\int_a^b f(x),dx).

Example

For (f(x) = x^2) on ([0, 1]), the exact integral is (1/3). The left Riemann sum with (n = 1000) gives approximately (0.3332).

Your Task

Implement:

  1. left_riemann(f, a, b, n) -- left Riemann sum
  2. right_riemann(f, a, b, n) -- right Riemann sum
  3. midpoint_riemann(f, a, b, n) -- midpoint Riemann sum
Pyodide loading...
Loading...
Click "Run" to execute your code.