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