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?
 A: As explained by other users: You have made a typographical error. Specifically the second sign below should be a minus, as seen below:

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

Note, the error would likely have occured when you were applying the minus form the first integration by parts, onto the second one. E.g:
$\int uv =u(\int v\;\mathrm{d}x)-\int u'(\int v \;\mathrm{d}x) \;\mathrm{d}x \Rightarrow$ $$u(\int v \;\mathrm{d}x) - (u'\int v \;\mathrm{d}x -\int u''(\int\int v \;\mathrm{d}x\;\mathrm{d}x)\;\mathrm{d}x)$$
$$u(\int v \;\mathrm{d}x) - u'\int v \;\mathrm{d}x +\int u''(\int\int v \;\mathrm{d}x\;\mathrm{d}x)\;\mathrm{d}x$$
Note the bracket removal in the last step.
A: $$\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)$$
