<s>[INST] Finding upper bound of Riemann's sum I have
$$f(x) = -x^2 + 2x + 5,\ x \in [1, 3]$$
Since $f(1) = 6$ and $f(3) = 2$, $f$ is decreasing.
$$\overline{S_n} = \sum_{i=0}^{n-1} f(\frac{i}{n})\Delta x_i,\ \Delta x_i = \frac{b - a}{n} = \frac{2}{n}$$
$$\overline{S_n} = \sum_{i=0}^{n-1} \left(-\left(\frac{i}{n}\right)^2 + 2\frac{i}{n} + 5\right)\frac{2}{n}$$
$$\overline{S_n} = \frac{2}{n}\left(\frac{-1}{n^2}\sum_{i=0}^{n-1} i^2 + \frac{2}{n}\sum_{i=0}^{n-1} i + \sum_{i=0}^{n-1} 5\right)$$
$$\overline{S_n} = \frac{2}{n}\left(\frac{-1}{n^2}\frac{n(n-1)(2n - 1)}{6} + \frac{2}{n}\frac{n(n-1)}{2} + 5n\right)$$
$$\overline{S_n} = \frac{2}{n}\left(\frac{-(n-1)(2n - 1)}{6n} + n - 1 + 5n\right)$$
$$\overline{S_n} = \frac{2}{n}\left(\frac{-(2n^2 - 3n + 1)}{6n} + 6n -
 1\right)$$
$$\overline{S_n} = \frac{2}{n}\left(\frac{-2n^2}{6n} + \frac{3n}{6n} - \frac{1}{6n} + 6n -
 1\right)$$
$$\overline{S_n} = \frac{2}{n}\left(\frac{17n}{3} - \frac{1}{2} - \frac{1}{6n}\right)$$
$$\overline{S_n} = \frac{34}{3} - \frac{1}{n} - \frac{1}{3n^2}$$
But the answer is supposed to be 
$$\overline{S_n} = \frac{28}{3} + \frac{4}{n} - \frac{4}{3n^2}$$
Where is my mistake?
 [/INST] Daniel Fischer's comment to an answer that can be accepted:

$$\overline{S_n} = \sum_{i=0}^{n-1} f(\frac{i}{n})\Delta x_i,\ \Delta x_i = \frac{b - a}{n} = \frac{2}{n}$$

You're evaluating the function in points $i/n$, which are between $0$ and $1$, so your result has no correspondence to the integral from $1$ to $3$. You should instead evaluate in points $a + i\frac{b-a}{n}$.
</s>