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
&amp;=&amp;\int \frac{\sin x}{\sin^2(x)\cos x} dx\\
&amp;=&amp;\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
&amp;=&amp;\int \frac{-1}{(1-u^2)u} du\\
&amp;=&amp;\int \frac{-1}{(1+u)(1-u)u}du\\ 
&amp;=&amp;\int \left(\frac{-1}{u} - \frac{1}{2(1-u)} + \frac{1}{2(1+u)}\right) du\\
&amp;=&amp;-\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?
If I take the derivative of your second answer (call it $g(x)$), I get:
\begin{eqnarray*}
\frac{dg}{dx}
&amp; = &amp; -\frac{-\sin x}{\cos x} + \frac{\sin x}{2(1-\cos x)} + \frac{-\sin x}{2(1+\cos x)}\\
&amp; = &amp; \frac{\sin x\left(1-\cos^2 x + \frac{1}{2}\cos x(1+\cos x) - \frac{1}{2}\cos x(1-\cos x)\right)}{\cos x(1-\cos x)(1+\cos x)}\\
&amp; = &amp; \frac{\sin x\left( 1- \cos^2 x + \frac{1}{2}\cos x + \frac{1}{2}\cos^2 x - \frac{1}{2}\cos x + \frac{1}{2}\cos^2 x\right)}{\cos x(1-\cos^2 x)}\\
&amp; = &amp; \frac{\sin x}{\cos x\>\sin^2 x} = \frac{1}{\cos x\sin x}.
\end{eqnarray*}
So I'm not sure why Mathematica says the second method is not "the right answer".
$$\int \frac{1}{\sin x\cos x} dx  = \int( \tan x+\cot x)\, dx= \int\frac{\sin x}{\cos x}\, dx+\int\frac{\cos x}{\sin x} \,dx$$ from where it should be fairly simple....(choose correctly the variables though)