Question: Evaluate the integral $I = \int_{-2}^{1} |x^2 - x - 2| \, dx$.
1. **State the problem:** We need to evaluate the integral $$I = \int_{-2}^{1} |x^2 - x - 2| \, dx.$$ This integral involves the absolute value of a quadratic expression.
2. **Analyze the expression inside the absolute value:** The quadratic is $$x^2 - x - 2.$$ We factor it:
$$x^2 - x - 2 = (x - 2)(x + 1).$$
3. **Find the roots:** The roots are $$x = 2$$ and $$x = -1.$$ These points divide the real line into intervals where the quadratic changes sign.
4. **Determine the sign of the quadratic on the interval $$[-2,1]$$:**
- For $$x < -1$$ (e.g., $$x = -2$$), $$x^2 - x - 2 = (-2)^2 - (-2) - 2 = 4 + 2 - 2 = 4 > 0$$.
- For $$-1 < x < 2$$ (e.g., $$x = 0$$), $$0^2 - 0 - 2 = -2 < 0$$.
Since our integration limits are from $$-2$$ to $$1$$, the quadratic is positive on $$[-2, -1]$$ and negative on $$[-1, 1]$$.
5. **Rewrite the integral without absolute value by splitting at $$x = -1$$:**
$$I = \int_{-2}^{-1} (x^2 - x - 2) \, dx + \int_{-1}^{1} -(x^2 - x - 2) \, dx.$$
6. **Calculate each integral separately:**
- First integral:
$$\int (x^2 - x - 2) \, dx = \frac{x^3}{3} - \frac{x^2}{2} - 2x + C.$$
Evaluate from $$-2$$ to $$-1$$:
$$\left[ \frac{x^3}{3} - \frac{x^2}{2} - 2x \right]_{-2}^{-1} = \left( \frac{(-1)^3}{3} - \frac{(-1)^2}{2} - 2(-1) \right) - \left( \frac{(-2)^3}{3} - \frac{(-2)^2}{2} - 2(-2) \right).$$
Calculate each term:
$$\frac{-1}{3} - \frac{1}{2} + 2 = -\frac{1}{3} - \frac{1}{2} + 2 = \frac{-2 - 3 + 12}{6} = \frac{7}{6}.$$
$$\frac{-8}{3} - 2 + 4 = -\frac{8}{3} - 2 + 4 = -\frac{8}{3} + 2 = \frac{-8 + 6}{3} = -\frac{2}{3}.$$
So the first integral is:
$$\frac{7}{6} - \left(-\frac{2}{3}\right) = \frac{7}{6} + \frac{2}{3} = \frac{7}{6} + \frac{4}{6} = \frac{11}{6}.$$
- Second integral:
$$\int -(x^2 - x - 2) \, dx = \int (-x^2 + x + 2) \, dx = -\frac{x^3}{3} + \frac{x^2}{2} + 2x + C.$$
Evaluate from $$-1$$ to $$1$$:
$$\left[-\frac{x^3}{3} + \frac{x^2}{2} + 2x \right]_{-1}^{1} = \left(-\frac{1}{3} + \frac{1}{2} + 2 \right) - \left(-\frac{-1}{3} + \frac{1}{2} - 2 \right).$$
Calculate each term:
$$-\frac{1}{3} + \frac{1}{2} + 2 = \frac{-2 + 3 + 12}{6} = \frac{13}{6}.$$
$$\frac{1}{3} + \frac{1}{2} - 2 = \frac{2 + 3 - 12}{6} = -\frac{7}{6}.$$
So the second integral is:
$$\frac{13}{6} - \left(-\frac{7}{6}\right) = \frac{13}{6} + \frac{7}{6} = \frac{20}{6} = \frac{10}{3}.$$
7. **Add the two results:**
$$I = \frac{11}{6} + \frac{10}{3} = \frac{11}{6} + \frac{20}{6} = \frac{31}{6}.$$
**Final answer:**
$$\boxed{\frac{31}{6}}.$$