Integral of $\sec(x)$ using $u$ sub I've just begun learning how to integrate and I wanted to see if I could integrate $\sec(x)$ by $u$-substitution. After getting my answer, I was told it couldn't be in complex form, but why, and if so, where did I go wrong? Here is how I did it:
$$\int \sec(x) dx$$
$$\int \frac{1}{\cos(x)} dx$$
$$\int \frac{1}{\frac{e^{ix}+e^{-ix}}{2i}}dx$$
$$\int \frac{2i}{e^{2ix}+1}dx$$
$u=2ix,du=2idx$
$$\int \frac{1}{e^u+1}du$$
$$\int \frac{e^u}{e^u(e^u+1)}du$$
$v=e^u,dv=e^udu$
$$\int \frac{1}{v^2+1}dv$$
$[\arctan(v)]$
$[\arctan(e^u)]$
$\arctan(e^{2ix}) + C$
 A: Going from your $3$rd line to the $4$th, you have multiplied the denominator by $e^{ix}$ but not the numerator. Thus, your work after that will not be correct. Also, in general, as the original question is in reals, your final answer should also be only in reals, with this indicating why your final answer can't be correct.
Note I saw that Eevee Trainer just wrote about the mistake in the comments, along with a more detailed explanation.
A: Just in case you were unaware there is another great trick to solving this integral:
\begin{align}
 \int \sec(x)\:dx &= \int \sec(x) \cdot \frac{\sec(x) + \tan(x)}{\sec(x) + \tan(x)}\:dx \\
&= \int \frac{\sec^2(x) + \sec(x)\tan(x)}{\sec(x) + \tan(x)}\:dx
\end{align}
Here let $u = \sec(x) + \tan(x) \rightarrow \frac{du}{dx} = \sec(x)\tan(x) + \sec^2(x)$ and thus:
\begin{align}
 \int \sec(x)\:dx &= \int \frac{\sec^2(x) + \sec(x)\tan(x)}{u}\cdot \frac{du}{\sec(x)\tan(x) + \sec^2(x)}\\
&= \int \frac{1}{u}\:du = \ln|u| + C = \ln\left|\sec(x) + \tan(x) \right| + C
\end{align}
Where $C$ is the constant of integration. 
Personally, for someone new to integrating this is more of a 'special case' method rather than a formal method. But important to be be aware of nonetheless. 
