Integral of $x^4\cos(x)$ I want to solve $\int_0^{2\pi}x^4\cos(x) dx$ without having to apply integration by parts 4 times. My attempt: $$ \int_0^{2\pi} x^4 \cos(x) dx= \int_0^{2\pi} \frac{\partial^4}{\partial a^4} \cos(ax) dx = \frac{\partial^4}{\partial a^4} \int_0^{2\pi} \cos(ax) dx = 0 $$
1) Why is this wrong?  (I guess it's about switching the partial derivations with the integral, but I don't know what I have to show to be allowed to that )
2) Is there a better way than doing integration by parts 4 times?
 A: Following my comment above: the function $f(x,a) = \cos(a x)$ is regular enough (continuously differentiable, at least) for your approach of switching integral and differentiation to be justified. The error is in the last step: $g\colon a\mapsto\int_0^{2\pi} f(x,a)dx = \int_0^{2\pi} \cos ax dx$ is a function of $a$, which is not identically zero. Computing it yields (for $a \neq 0$)
$$
g(a) = \frac{\sin 2\pi a}{a}.
$$
You are interested in $\frac{d^4}{da^4} g(a)\big|_{a=1}$, which is the actual value of the integral: differentiate $g$ four times and evaluate it at $1$ to get this value.
Edit: note however that this repeated differentiation is not that far from what a repetition of integration by part would be effectively doing.
A: Using Feynman trick plus the Real part trick:
$$\Re\lim_{\alpha \to 1}\int_{0}^{2\pi} \frac{\partial^4}{\partial \alpha^4} e^{i\alpha x}\text{d}x = \Re\lim_{\alpha \to 1}\frac{\partial^4}{\partial \alpha^4}\left(\frac{e^{2\pi i\alpha} - 1}{i \alpha}\right) $$
Calculate the derivative, obtaining:
$$\Re\lim_{\alpha \to 1} \left(\frac{8\left(3i + e^{2\pi i \alpha}(-3i - 6\alpha \pi + 6i\alpha^2 \pi^2 + 4\alpha^3 \pi^3 - 2i\alpha^4 \pi^4)\right)}{\alpha^5}\right) = 32\pi^3 - 48\pi$$
which is the correct result of the integration.
A: $$\int x^4\cos x\,\mathrm d\mkern1mu x=\operatorname{Re}\Bigl(\int x^4\mathrm e^{\mathrm i x}\mathrm d\mkern1mu x\Bigr)$$
Now this last integral is standard, and the answer is $\;p(x)\mathrm e^{\mathrm i x}$, where $p(x)\in\mathbf C[x]$ has degree $4$. So write $p(x)=ax^4+bx^3+cx^2+dx+e$, differentiate:
$$\bigl(p(x)\mathrm e^{\mathrm i x}\bigr)'=\bigl(p'(x)+\mathrm ip(x)\bigr)\mathrm e^{\mathrm i x},$$
 and identify with $\;x^4\mathrm e^{\mathrm i x}$. Solving for the coefficients, you should obtain, if I'm not mistaken,
$$(4x^3+24x)\cos x+(x^4+12x^2-24)\sin x.$$
