Integrating cos² x

$$ \int \cos^2{x}\,dx = \frac{x + \sin{x}\cos{x}}{2} + C $$

Using the Pythagorean identity

Integrate by parts using $u = \cos{x}, du = -\sin{x}$ and $v = \sin{x}, dv = \cos{x}$:

$$ \begin{align}
& \int \cos{x}\cos{x}\,dx = \sin{x}\cos{x} - \int -\sin{x}\sin{x}\,dx \\
& \int \cos^2{x}\,dx = \sin{x}\cos{x} + \int \sin^2{x}\,dx
\end{align} $$

Add $\int \cos{x}^2\,dx$ to both sides:

$$ 2\int \cos^2{x}\,dx = \sin{x}\cos{x} + \int \sin^2{x}\,dx + \int \cos^2{x}\,dx $$

Apply integral linearity:

$$ 2\int \cos^2{x}\,dx = \sin{x}\cos{x} + \int \left(\sin^2{x} + \cos^2{x}\right)\,dx $$

Apply the Pythagorean identity and divide both sides by 2:

$$ \begin{align}
2\int \cos^2{x}\,dx &= \sin{x}\cos{x} + \int 1\,dx \\
&= \sin{x}\cos{x} + x + C \\
\int \cos^2{x}\,dx &= \frac{x + \sin{x}\cos{x}}{2} + C
\end{align} $$

Using the double angle formula

Careful! This derivation differs from the one in Integrating sin² x by just a sign.

Rewrite the integral using the double angle formula for the cosine:

$$ \int \cos^2{x}\,dx = \int \frac{1 + \cos{2x}}{2}\,dx $$

Substitute $u = 2x, du = 2\,dx$:

$$ \begin{align}
\int \frac{1 + \cos{2x}}{2}\,dx &= \int \frac{1 + \cos{u}}{2}\frac{1}{2}\,du \\
 &= \frac{1}{4} \left(\int 1\,du + \int \cos{u}\,du\right) \\
 &= \frac{u + \sin{u} + C}{4}
\end{align} $$

Substitute back and simplify:

$$ \begin{align}
\frac{u + \sin{u} + C}{4} &= \frac{2x + \sin{2x} + C}{4} \\
 &= \frac{x + \frac{\sin{2x}}{2}}{2} + C \\
 &= \frac{x + \sin{x}\cos{x}}{2} + C
\end{align} $$