<s>[INST] Integrate $\int x\sin^2 (x) dx$ Integrate $\int x\sin^2 (x) dx$
My attempt:
$$=\int x\sin^2 (x) dx\\
=x^2\sin^2 (x) - \int 2\sin (x)\cos (x)x^2 dx\\
=x^2\sin^2 (x) - \int \sin (2x) x^2 dx.$$
 [/INST] Take $\int x\sin ^2(x)dx = \int udv$, where $u = x\sin x$ and $dv = \sin (x)dx$. Then by integrating by parts we get
$$ \int x \sin ^2(x) dx = -x\sin (x)\cos x + \int (\sin x + x\cos x)\cos (x)dx =\ldots $$
Now, with $\cos ^2x = 1-\sin ^2x$ we get
$$\ldots = -x\sin (x)\cos x + \int \sin (x)\cos (x) dx + \int x\left (1-\sin ^2x\right )dx +C.$$
Collect same quantities to get
$$2\int x\sin ^2(x) dx = -x\sin (x)\cos x + \frac{\sin ^2x}{2} + \frac{x^2}{2}+C.$$
For a more pretty result, we can multiply both sides by $2$, then
$$4\int x\sin ^2(x)dx  = \sin ^2x + x^2 - x\sin (2x) + C.$$
</s>