Maximizing the Integral 
Find the interval $[a,b]$ for which the value of the integral $\int_{a}^{b} (2+x-x^2)dx$ is maximized.

To solve this problem, I believe I need to the largest interval over which the integrand is nonnegative. To that end, $2+x-x^2 \ge 0$ if and only if $(x+1)(x-2) \le 0$. This occurs if $x \ge -1$ and $x \le 2$ or $x \le -1$ and $x \ge 2$. Obviously the latter condition is contradictory in nature, so we conclude that $f(x)$ is nonnegative if and only if  $x \in [-1,2]$. Now we prove that this is the interval over which the integral is maximized.
Let $[a,b] \subseteq \Bbb{R}$ be some other interval. If $[a,b]$ is contained in either $(- \infty, -1]$ or $[2,\infty)$, then the integral is negative and therefore smaller. If $[a,b]$ is strictly contained in $[-1,2]$, then $\int_{-1}^{2} f(x)dx = \int_{-1}^{a} f(x)dx + \int_{a}^{b} f(x) dx + \int_{b}^{2} f(x)dx \ge \int_{a}^{b} f(x) dx$. The only remaining case is when $[a,b]$ and $[-1,2]$ overlap but the latter is not contained in the former. Suppose that $a \le -1 \le b$. Then 
$$\int_{a}^{b} f(x) dx = \int_{a}^{-1}f(x) dx + \int_{-1}^{b} f(x) dx \le \int_{-1}^{b} f(x) dx + \int_{b}^{2} f(x) dx.$$ The $a \le 2 \le b$ case is similar.
Finally, it's possible to have $[-1,2] \subseteq [a,b]$, but that case can be handled in a similar fashion, and so I omit it. 
As one can see, I had to deal with more cases than I cared to. Is there a simpler solution, or have I no such recourse?
 A: The two cases $a, b\leq -1$ and $2\leq a, b$ can be excluded by noting that those integrals can't get positive, since the function is negative on $[a, b]$. All other cases can be covered in one fell swoop by saying that $\int_{-1}^af(x) dx$ and $\int_b^2f(x)dx$ are both non-negative, so
$$
\int_{-1}^2f(x)dx = \int_a^bf(x)dx + \int_{-1}^af(x)dx + \int_b^2f(x)dx
$$
shows that $\int_{-1}^2f(x)dx \geq \int_a^bf(x)dx$ (keeping in mind that $\int_p^qf(x)dx = -\int_q^pf(x)dx$).
A: Your reasoning on the negativity of the integrand is correct. Solving for intersections between $f$ and the x-axis, as well as the fact that $\frac{df}{dx} = 1 - x^2 $ and is strictly increasing for $x < 0$ and decreasing for $x>0$ shows that $f$ is only positive in the region $[-1,2]$. ( A simple plot would confirm this as well, but it is good practice to work out the analytics of it)
Another relatively straight forward solution can be given by defining 
$$g(a,b) = \int_a^bf(x)dx =  \int_a^0 f(x)dx + \int_0^b f(x)dx = \int_0^b f(x)dx - \int_0^a f(x)dx $$
and by the fundamental theorem of calculus 
$$\frac{d}{db}g(b,a) = f(b) = 2 + b - b^2$$
Setting  $f(b) = 0$ and solving for $b$ we get $b = 2$ as a positive solution, so the first integral is maximized at $b=2$. Similarly, we get that the second integral is maximized at $a=-1$, and so their sum is maximized over $[-1,2]$. 
A: How about this:
Let $a$ be a fixed number. Consider the function
$$F(t)= \int_a^t (2+x-x^2) \ \mathrm dx$$
Then, $F'(t)= 2+t-t^2 = - (t+1)(t-2)$.
Observe that $F'$ is positive on $(-1,2)$ and negative on $(2,\infty)$.
This implies that $t=2$ is a local maximum for $F$.
Now similarly, you can consider $$G(t)= \int_t^2(2+x-x^2) \ \mathrm dx = -\int_2^t(2+x-x^2) \ \mathrm dx$$
and observe that $t=-1$ is a local max for $G$.
