Integration of secant [duplicate]
$$\begin{align} \int \sec x \, dx &= \int \cos x \left( \frac{1}{\cos^2x} \right) \, dx \\ &= \int \cos x \left( \frac{1}{1-\sin^2x} \right) \, dx \\ & = \int\cos x\cdot\frac{1}{1-\frac{1-\cos2x}{2}} \, dx \\ &= \int \cos x \cdot\frac{2}{1+\cos2x} \, dx \end{align}$$
I am stuck in here. Any help to integrate secant?
\begin{align*}\int\sec x\,\mathrm dx&=\int\frac1{\cos x}\,\mathrm dx\\&=\int\frac{\cos x}{\cos^2x}\,\mathrm dx\\&=\int\frac{\cos x}{1-\sin^2x}\,\mathrm dx.\end{align*} Now, doing $\sin x=t$ and $\cos x\,\mathrm dx=\mathrm dt$, you get $\displaystyle\int\frac{\mathrm dt}{1-t^2}$. But\begin{align*}\int\frac{\mathrm dt}{1-t^2}&=\frac12\int\frac1{1-t}+\frac1{1+t}\,\mathrm dt\\&=\frac12\left(-\log|1-t|+\log|1+t|\right)\\&=\frac12\log\left|\frac{1+t}{1-t}\right|\\&=\frac12\log\left|\frac{(1+t)^2}{1-t^2}\right|\\&=\log\left|\frac{1+t}{\sqrt{1-t^2}}\right|\\&=\log\left|\frac{1+\sin x}{\sqrt{1-\sin^2x}}\right|\\&=\log\left|\frac1{\cos x}+\frac{\sin x}{\cos x}\right|\\&=\log|\sec x+\tan x|.\end{align*}
An alternative method: The trick here is to multiply $\sec{x}$ by $\dfrac{\tan{x}+\sec{x}}{\tan{x}+\sec{x}}$, then substitute $u=\tan{x}+\sec{x}$ and $du=(\sec^2{x}+\tan{x}\sec{x})~dx$:
$$\int \sec{x}~dx=\int \sec{x}\cdot \frac{\tan{x}+\sec{x}}{\tan{x}+\sec{x}}~dx=\int \frac{\sec{x}\tan{x}+\sec^2{x}}{\tan{x}+\sec{x}}~dx=\int \frac{1}{u}~du=\cdots$$
Not obvious, though it is efficient.
After $\int \cos x \left(\frac{1}{1-\sin^2x}\right)dx$ use the transformation $z = \sin x$ and $dz = \cos x \, dx$.
Edit:
$$\int\frac{1}{1-u^2}\,du = \frac{1}{2}\int\frac{(1+u)+(1-u)}{(1+u)(1-u)} = \frac{1}{2} \int \frac{1}{1+u} + \frac{1}{1-u}\,du$$
And use, $\int \frac{1}{u}\,du = \ln|u|$