How to integrate $\int(x\pi-x^2)\cos(kx)dx$ My question is can I solve by integrating by parts if I do $u = (x\pi-x^2)$,or first I have to do $∫[x\pi \cos(kx)-x^2\cos(kx)]dx$ and then split it in two integrals $\int x\pi\cos(kx)dx-\int x^2\cos(kx)dx$ ?
 A: You may directly integrate by parts twice,
$$
\int(\pi x-x^2) \cos (kx)\:dx=\frac1k(\pi x-x^2)\sin (k x)-\frac1k\int(\pi-2x) \sin (kx)\:dx
$$ then
$$
\begin{align}
&\int(\pi x-x^2) \cos (kx)\:dx\\&=\frac1k(\pi x-x^2)\sin (k x)-\frac1k\left((\pi-2x)(-\frac1k \cos (kx))+\int(-2) \frac1k \cos (kx)\:dx\right)
\end{align}
$$ getting

$$
\int(\pi x-x^2) \cos (kx)\:dx=\frac1{k^3}\left(2+k^2\pi  x-k^2x^2\right) \sin (kx)+\frac1{k^2}(\pi -2 x) \cos (kx)+ C
$$

A: $\textbf{Another way:}$
$$
\pi\frac{d}{dk}\int \sin k x dx + \frac{d^2}{dk^2}\int \cos k x dx = \int \left(\pi x-x^2\right)\cos kx dx
$$
A: Here is an approach that does not use integration by parts.  We observe that 
$$\frac{d^2}{dk^2}\int \cos (kx)\,dx=-\int x^2\cos (kx)\,dx$$
and
$$\frac{d}{dk}\int \sin (kx)\,dx=\int x\cos (kx)\,dx$$
Therefore,
$$\int x^2\cos (kx)\,dx=-\frac{d^2}{dk^2}\left(\frac{\sin kx}{k}\right)=\frac{x^2\sin kx}{k}+\frac{2x\cos kx}{k^2}-\frac{2\sin kx}{k^3}$$
and
$$\int x\cos (kx)\,dx=-\frac{d}{dk}\left(\frac{\cos kx}{k}\right)=\frac{x\sin kx}{k}+\frac{x\sin kx}{k^2}$$
