Evaluate $\int \frac{1}{\sin x\cos x} dx $ Question: How to evaluate $\displaystyle \int \frac{1}{\sin x\cos x} dx $
I know that the correct answer can be obtained by doing:
$\displaystyle\frac{1}{\sin x\cos x} = \frac{\sin^2(x)}{\sin x\cos x}+\frac{\cos^2(x)}{\sin x\cos x} = \tan(x) + \cot(x)$ and integrating.
However, doing the following gets a completely different answer:
\begin{eqnarray*}
\int \frac{1}{\sin x\cos x} dx
&=&\int \frac{\sin x}{\sin^2(x)\cos x} dx\\
&=&\int \frac{\sin x}{(1-\cos^2(x))\cos x} dx.
\end{eqnarray*}
let $u=\cos x, du=-\sin x dx$; then
\begin{eqnarray*}
\int \frac{1}{\sin x\cos x} dx
&=&\int \frac{-1}{(1-u^2)u} du\\
&=&\int \frac{-1}{(1+u)(1-u)u}du\\ 
&=&\int \left(\frac{-1}{u} - \frac{1}{2(1-u)} + \frac{1}{2(1+u)}\right) du\\
&=&-\ln|\cos x|+\frac{1}{2}\ln|1-\cos x|+\frac{1}{2}\ln|1+\cos x|+C
\end{eqnarray*}  
I tested both results in Mathematica, and the first method gets the correct answer, but the second method doesn't. Is there any reason why this second method doesn't work?

The second method gives the same answer as the first. By the first method, the answer you get is $-\log(\cos x) + \log(\sin x)$. The first term is the same as what you get by the second method.
What you need to show is that $\log(\sin x) = \frac{1}{2}\log(1-\cos x) + \frac{1}{2}\log(1+\cos x)$.
\begin{equation}
\begin{split}
\frac{1}{2}\log(1-\cos x) + \frac{1}{2}\log(1+\cos x) &= \frac{1}{2}\left( \log(2 \sin^2 \frac{x}{2}) + \log(2 \cos^2 \frac{x}{2})\right)\\ & =  \log(2 \sin \frac{x}{2} \cos \frac{x}{2})
\end{split}
\end{equation}
