# The error inherent in a Riemann sum

Suppose we have a monotone, increasing function $f$ defined over an interval $[a,b]$ and we'd like to use a left and right Riemann sums, $L_n$ and $R_n$, to estimate $$\int_a^b f(x)\, dx.$$ If $n$ represents the number of terms in the sum, how large must $n$ be to ensure our error does not exceed some pre-prescribed tolerance?

Since the function is increasing, we certainly know that $$L_n \leq \int_a^b f(x)\, dx \leq R_n.$$ This implies that $$0 \leq \int_a^b f(x)\, dx - L_n \leq R_n - L_n$$ and $$L_n - R_n \leq \int_a^b f(x)\, dx - R_n \leq 0.$$ In both cases, the term in the middle is the actual error and we have that $$\text{error}\leq \left|R_n-L_n\right|.$$

But, there is a very simple interpretation of $R_n-L_n$ - it is the total area of the rectangles shown in red below, which yields $$\text{error}\leq \left|f(b)-f(a)\right|\frac{b-a}{n}.$$

By the mean value theorem, we know that $$\frac{f(b)-f(a)}{b-a} = f'(c)$$ for some $c$ between $a$ and $b$. Thus, if $M$ is an upper bound for $|f'|$ on the interval, then we know that $$\text{error}\leq \frac{\left|f(b)-f(a)\right|}{b-a}\cdot\frac{(b-a)^2}{n} \leq M\frac{(b-a)^2}{n}.$$ The nice thing about this last formulation is that it holds whether $f$ is monotone or not!