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:
where (\Delta x = (b - a) / n) and (x_i^*) is a sample point in the (i)-th subinterval.
Types of Riemann Sums
| Type | Sample 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:
left_riemann(f, a, b, n)-- left Riemann sumright_riemann(f, a, b, n)-- right Riemann summidpoint_riemann(f, a, b, n)-- midpoint Riemann sum
Pyodide loading...
Loading...
Click "Run" to execute your code.