Where did I go wrong in my evaluation of the integral of cosine squared? $$\int{\cos^2(x)}dx$$
Where did I go wrong in my evaluation of this integral?
$$=x\cos^2x - \int-2x\sin(x)\cos(x)\,dx$$
$$=x\cos^2x + \int x\sin(2x)\,dx$$
$$=x\cos^2x + \left(\frac {-x\cos(2x)}2 -\int \frac{-\cos(2x)}2\,dx\right)$$
$$=x\cos^2x + \left(\frac {-x\cos(2x)}2 + \frac 12\cdot\frac{\sin(2x)}2\right)$$
$$x\cos^2x-\frac{x\cos(2x)}2+\frac{\sin(2x)}4 + C$$
And this is clearly wrong, but I don't know where I messed up in my calculations. Would anyone mind correcting me somewhere?

Using the formula $\displaystyle \bullet \; 2\cos^2 x = 1+\cos 2x$
So $$\displaystyle I = \frac{1}{2}\int 2\cos^2 xdx =\frac{1}{2}\int \left[1+\cos 2x\right]$$
So $$\displaystyle I = \frac{1}{2}\int 1 dx + \frac{1}{2}\int \cos 2x dx = \frac{1}{2}x+\frac{1}{4}\sin 2x+\mathcal{C}$$
