Approximating $\int_2^4 e^{\frac{1}{x}} dx$ 
Estimate the integral precisely up to the error of $0.001$:$$\int_2^4 e^{\frac{1}{x}} dx$$

I started by dividing the segment $[2,4]$ into some pieces $(n=5)$ as in the following figure:
$\qquad\qquad\quad$

Now, I have $$\Delta x = \frac{4-2}{5} = 0.4$$ and therefore, $$S \approx \sum_{i=1}^5 f(x_i)(x_i - x_{i-1}) = \Delta x \sum_{i=1}^5 e^{\frac{1}{x_i}}$$ where $x_i = 2 + 0.4i$.
Then, approximating the area boils down to approximating the exponential function at $5$ points. What is the best way to proceed? And how do I know that the final result will give the error at most $0.001$?

The Midpoint Rule error is given by
$$\tag 1 |E_n| \le \left|\dfrac{(b-a)^3}{24 n^2}\right | |\max_{2 \le x \le 4}f''(x^*)|$$
The second derivative of $f(x) = e^{1/x}$ is
$$f''(x)= \dfrac{e^{1/x} (2 x + 1)}{x^4}$$
So, we want to find the max of $|f''(x)|$ over the interval $[2,4]$
$$\displaystyle \max_{2 \le x \le 4}\left| \dfrac{e^{1/x} (2 x + 1)}{x^4}\right| = \dfrac{5 \sqrt{e}}{16} ~ \mbox{at}~ x = 2$$
Substituting everything we have into $(1)$
$$|E_n| \le \dfrac{(4-2)^3}{24 n^2} \left(\dfrac{5 \sqrt{e}}{16}\right) \le 0.001$$
Can you continue by solving that for $n$? You should find
$$n \ge 13.105$$
We would choose an integer at $n = 14$.
Note that that is an upper bound and can be way off.
In practice, using trial and error gives eight intervals for an absolute error $< 0.001$
$$2.83456$$
Using WA, the closed form is ugly, and the numerical result is
$$\displaystyle \int_2^4 e^{1/x} dx \approx 2.835422294875796952$$
Update If you want to see the intermediate Midpoint Rule steps above, use this calculator.
