# Trouble integrating $\sec x$

I have to evaluate the integral of the $\sec x$ function and I do it as follows $$\int\sec xdx=\int\frac{dx}{\cos x}=\int\frac{\cos^2 x+\sin^2 x}{\cos x}dx=\sin x+\int\frac{\sin^2x}{\cos x}dx$$ Now we make a change of variables $\cos x=t$ so our integral becomes $$\sin x-\int\frac{\sqrt{1-t^2}}{t}dt$$ Now we make another change of variable $\sqrt{1-t^2}=z$ so our integral becomes $$\sin x-\int\frac{z^2-1+1}{z^2-1}dz=\sin x-\int\left(1+\frac{1}{z^2-1}\right)dz=$$ $$=\sin x-\sqrt{1-\cos^2x}+\frac12\ln\left|\frac{1+\sqrt{1-\cos^2x}{}}{1-\sqrt{1-\cos^2x}}\right|+C=\frac12\ln|\tan^2x+\sec^2x|+C$$ The calculator however evaluates this integral as $$\ln|\tan x+\sec x|+C$$ but I can't figure out where I made a mistake in my calculations.

• Can you explain the final step in your derivation ? Notice that $(1+s)/(1-s)=(1+s)^2/(1-s^2)=(1/c+s/c)^2$. – Yves Daoust Mar 19 '17 at 9:42
• Thank you very much! I mistakenly wrote $\sqrt{1-\cos^2 x}=\sin^2 x$. – ahra Mar 19 '17 at 9:50
• I think you forgot to change the differentials when you substitute variables.. first one $cos(x)=t$ implies $x=arccos(t)$ and $dx= arccos(t)'dt$, and aslo the second one..Did i miss something? – user94719 Mar 19 '17 at 9:52
• $t=\cos x$ and $dt=-\sin x dx\Rightarrow dx=-dt/\sin x$ – ahra Mar 19 '17 at 9:54

$$\int\frac{dx}{\cos x}=\int\frac{\cos x\,dx}{\cos^2x}=\int\frac{\sin'x\,dx}{1-\sin^2x}=\text{artanh}(\sin x).$$
Hint: Use the trick \begin{align} \sec x= \frac{\sec x+\tan x}{\sec x+\tan x} \sec x. \end{align} then $u$-sub.
Just another approach: $\frac{1}{cosx}=\frac{cosx}{cos^2x}=\frac{cosx}{1-sin^2x}$.And performing a substitution $cosx=t$ in $\int\frac{{\cos}xdx}{1-sin^2x}$ results in a doable integral.