Unbloated Reveal.js Example
Approximate an integral by sampling the midpoint of each subinterval.
This is the same example used in the Unbloated technical book.
def midpoint(f, a, b, n):
if n < 1:
raise ValueError("n must be positive")
h = (b - a) / n
return h * sum(f(a + (k + 0.5) * h) for k in range(n))
For the integral of on :
| Estimate | Absolute error | |
|---|---|---|
| 1 | 0.250000 | 0.083333 |
| 2 | 0.312500 | 0.020833 |
| 4 | 0.328125 | 0.005208 |
Note
These values check one integrand. They do not establish an error bound for arbitrary continuous functions.
Use the arrow keys or the slide controls to move through this presentation.
Unbloated for Quarto