Riemann Sum such that $R_n - A < 0.0001$ If $A$ is the area under the curve $y = e^x$ from $1$ to $3$, find a value of $n$ such that $R_n - A < 0.0001$.
$R_n$ is the Riemann sum using the right-hand endpoints of the partition intervals of an equidistant partition into $n$ subintervals.
My (incorrect) solution is below.
I realize that $R_n - A < R_n - L_n$. Therefore, $R_n - A < \frac{b-a}{n} \cdot (f(b) - f(a))$.
Setting $\frac{b-a}{n}\cdot (f(b) - f(a)) = 0.0001$ and solving for $n$:
$$\frac{3-1}{n}\cdot (e^3 - e^1) = 0.0001\\
n = \frac{2}{0.0001}(e^3-e^1) = 347345$$
Therefore, $R_n - A < 0.0001$ when $n \geqslant 347345$.
But the answer is supposed to be $n \geqslant 34735$.
Any ideas? Thank you.
 A: Looking at the error without replacing the integral by the left-endpoint-sum, we find
$$R_n - A = \sum_{k=1}^n \int_{x_{k-1}}^{x_k} f(x_k) - f(t)\,dt.$$
For differentiable $f$, we have $f(x_k) - f(t) = f'(\xi_t)\cdot (x_k-t)$ for a $\xi_t\in (t,x_k)$ by the mean value theorem, and for a continuously differentiable $f$ we then obtain
$$\begin{align}
R_n - A &= \sum_{k=1}^n f'(\xi_k)\int_{x_{k-1}}^{x_k}x_k-t\,dt + \sum_{k=1}^n \int_{x_{k-1}}^{x_k}\left(f'(\xi_t)-f'(\xi_k)\right)(x_k-t)\,dt\\
&= \sum_{k=1}^n \frac{f'(\xi_k)}{2}(x_k-x_{k-1})^2 + \sum_{k=1}^n \int_{x_{k-1}}^{x_k}\left(f'(\xi_t)-f'(\xi_k)\right)(x_k-t)\,dt.
\end{align}$$
For an equidistant partition of the interval $[a,b]$, we have $x_k-x_{k-1} = \frac{b-a}{n}$, and the first sum is
$$\frac{b-a}{2n}\sum_{k=1}^n f'(\xi_k)(x_k-x_{k-1}),$$
a constant times a Riemann sum for the integral of $f'$. In the second sum we estimate the integrands with a modulus of continuity of $f'$, using $\lvert f'(\xi_k) - f'(\xi_t)\rvert \leqslant \omega_{f'}\left(\frac{b-a}{n}\right)$ and obtain
$$\left\lvert \sum_{k=1}^n \int_{x_{k-1}}^{x_k}\left(f'(\xi_t)-f'(\xi_k)\right)(x_k-t)\,dt\right\rvert \leqslant \omega_{f'}\left(\tfrac{b-a}{n}\right)\sum_{k=1}^n \int_{x_{k-1}}^{x_k} x_k-t\,dt = \omega_{f'}\left(\tfrac{b-a}{n}\right) \frac{(b-a)^2}{2n}.$$
Overall, for a continuously differentiable $f$, we find
$$R_n - A = \frac{(b-a)(f(b)-f(a))}{2n} + o(n^{-1}).$$
For a twice continuously differentiable $f$, the $o(n^{-1})$ term can be determined to belong to $O(n^{-2})$.
Here, we have a smooth convex integrand, so $f'(x_{k-1})(x_k-t) \leqslant f(x_k) - f(t) \leqslant f'(x_k)(x-t)$, and from that we can bound the error above and below
$$\sum_{k=1}^n f'(x_{k-1})\int_{x_{k-1}}^{x_k} x_k-t\,dt \leqslant R_n - A \leqslant \sum_{k=1}^n f'(x_k)\int_{x_{k-1}}^{x_k} x_k-t\,dt,$$
which for an equidistant partition yields
$$\frac{b-a}{2n} L'_n \leqslant R_n - A \leqslant \frac{b-a}{2n}R'_n$$
with the left- resp. right-endpoint Riemann sums for the integral of $f'$.
For $f(x) = e^x$ in particular, we have $f' = f$, and with
$$L_n = R_n - \frac{(b-a)(f(b)-f(a))}{n}$$
we have
$$\frac{b-a}{2n}R_n - \frac{(b-a)^2(f(b)-f(a))}{2n^2} \leqslant R_n - A \leqslant \frac{b-a}{2n}R_n.$$
Plugging in $a = 1$, $b = 3$ to obtain simpler expressions,
$$\frac{1}{n}R_n - \frac{2(e^3-e)}{n^2} \leqslant R_n - (e^3-e) \leqslant \frac{1}{n}R_n,$$
from which we get the upper bound
$$R_n \leqslant \frac{n}{n-1}(e^3-e)$$
and the lower bound
$$\frac{n^2-2}{n(n-1)}(e^3-e) \leqslant R_n.$$
Therefore to have $\lvert R_n - A\rvert < \varepsilon$, it is sufficient that
$$n > \frac{e^3-e}{\varepsilon}+1,$$
and [assuming $n \geqslant 4$] necessary that
$$\frac{\varepsilon}{e^3-e} > \frac{n^2-2}{n^2(n-1)}- \frac{2}{n^2}
= \frac{n^2-2n}{n^2(n-1)} = \frac{n-2}{n(n-1)} \geqslant \frac{1}{n+2},$$
so $n > \frac{e^3-e}{\varepsilon}-2$. For $\varepsilon = 10^{-4}$, we obtain the necessary condition
$$n \geqslant 173\,671$$
for $R_n - A < 10^{-4}$, so the given solution is not correct for $\varepsilon = 10^{-4}$. It fits well, however, for $\varepsilon = 10^{-3}$ and the coarser estimate $R_n - L_n < \varepsilon$.
A: See this Wikipedia article, section Error. We have that the difference between the integral and the Riemann sum for $e^x$ with respect to a partition of $[0,3]$ in $n$ equal subintervals is:
$$ \frac{9}{8n^2}e^{\xi},\quad \xi\in[0,3] $$
hence it is sufficient to take $n$ such that
$$ \frac{9e^3}{8n^2}<0.0001,$$
so $n\geq 476$ is enough.
