<s>[INST] Evaluate $\int_{-\pi}^{\pi} x^2 \cos{3x}dx$ Evaluate $$\int_{-\pi}^{\pi} x^2 \cos{3x}dx$$
I applied integration-by-parts twice and finally got a result of $-\frac{4\pi}{9}$ but the back of the book says $+\frac{4\pi}{9}$ .
Which answer is correct?
Also I drew a sketch of the curve with points: $(-\pi,-\pi^2),(-\frac{\pi}{2},0),(0,\pi^2),(\frac{\pi}{2},0),(\pi,-\pi^2)$
Surely this function has an equal area above the x-axis as below it. Should the integral not be zero?
What am I missing here?
 [/INST] The function is not symmetric about the $x$-axis.  It is symmetric about the $y$-axis; that is to say, $f(x) = x^2 \cos 3x$ satisfies $f(-x) = f(x)$ for all $x \in \mathbb R$.
With the choice $u = x^2$, $du = 2x \, dx$, $dv = \cos 3x \, dx$, $v = \frac{1}{3} \sin 3x$, we get $$\int x^2 \cos 3x \, dx = \frac{x^2}{3} \sin 3x - \frac{2}{3} \int x \sin 3x \, dx.$$  Repeating the process with the choice $u = x$, $du = dx$, $dv = \sin 3x \, dx$, $v = -\frac{1}{3}\cos 3x$, we get $$\int x^2 \cos 3x \, dx = \frac{x^2}{3} \sin 3x - \frac{2}{3} \left( -\frac{x}{3} \cos 3x + \frac{1}{3} \int \cos 3x \, dx \right).$$  From this we conclude the indefinite integral equals $$\frac{x^2}{3} \sin 3x + \frac{2x}{9} \cos 3x - \frac{2}{27} \sin 3x + C.$$  Evaluating this at the endpoint $x = \pi$ gives $-2\pi/9$, whereas evaluating at $x = 0$ gives $0$, hence half the definite integral (due to the aforementioned symmetry) is $-2\pi/9$, and the full value is $-4\pi/9$, as you claimed.
</s>