<s>[INST] Integral of $x^2 \cos(a x)\; \mathrm{d}x$ I am trying to solve the following problem:

$\int x^2 \cos(a x)\; \mathrm{d}x$

I thought this would be simple and I am pretty sure this is the answer:

$I =\frac{x^2\sin(ax)}{a}+\frac{2x\cos(ax)}{a^2}+\frac{2\sin(ax)}{a^3}$

I have been told that this isn't the correct answer?
I just applied integration by parts twice. Is my answer essentially correct other than typographical errors(sign change) etc, or have I seriously diverged from the correct calculation?
 [/INST] $$\int x^2\cos(ax)dx=|u=x^2\Rightarrow du=2xdx, dv=\cos(ax)dx\Rightarrow v=\frac{1}{a}\sin(ax)|=$$
$$=\frac{x^2}{a}\sin(ax)+\frac{2}{a}\int x\sin(ax)dx=\frac{x^2}{a}\sin(ax)+\frac{2}{a}I_1$$
$$I_1=\int x\sin(ax)dx=|u=x\Rightarrow du=dx, dv=\sin(ax)dx\Rightarrow v=\frac{1}{a}\cos(ax)|=$$
$$=\frac{x}{a}\cos(ax)+\frac{1}{a}\int\cos(ax)dx=\frac{x}{a}\cos(ax)-\frac{1}{a}\cdot\frac{1}{a}\sin(ax)dx=\frac{x}{a}\cos(ax)-\frac{1}{a^2}\sin(ax)dx$$
$$\int x^2\cos(ax)dx=\frac{x^2}{a}\sin(ax)+\frac{2}{a}I_1=\frac{x^2}{a}\sin(ax)+\frac{2}{a}\left(\frac{x}{a}\cos(ax)-\frac{1}{a^2}\sin(ax)dx\right)=$$
$$=\frac{x^2}{a}\sin(ax)+\frac{2x}{a^2}\cos(ax)-\frac{2}{a^3}\sin(ax)$$
i.e.
$$\int x^2\cos(ax)dx=\frac{x^2}{a}\sin(ax)+\frac{2x}{a^2}\cos(ax)-\frac{2}{a^3}\sin(ax)$$
</s>