How to integrate $\int{\frac{1}{\cos(x)}}dx$ using the substitution $u=\tan\left(\frac{x}2\right)$?
So far, I've tried out to reformulate: $$\int{\frac{1}{\cos(x)}}dx$$ to: $$\int{\frac{\sin(x)}{\cos(x)\sin(x)}}dx$$
which is basically: $$\int{\frac{\tan(x)}{\sin(x)}}dx$$ But I'm not sure if this is the right way to go, or if I try something else.
Any tips or methods would be very helpful.
$\endgroup$ 19 Answers
$\begingroup$This substitution is to be used as a last resort? Bioche's rules say in this case the correct substitution is $u=\sin x$, $\mathrm d\mkern1mu u=\cos x\,\mathrm d\mkern1mu x$. Indeed $$\int\frac{\mathrm d\mkern1mu x}{\cos x}=\int\frac{\cos x\,\mathrm d\mkern1mu x}{\cos^2 x}=\int\frac{\mathrm d\mkern1mu u}{1-u^2}=\frac12\ln\Bigl(\frac{1+u}{1-u}\Bigr)=\frac12\ln\Bigl(\frac{1+\sin x}{1-\sin x}\Bigr).$$
Note:
Using some trigonometry formulae, this may be rewritten as $$\ln\Bigl(\tan\Bigl(\frac x2+\frac\pi 4\Bigr)\Bigr).$$
$\endgroup$ 1 $\begingroup$Hint:
If $u=\tan\left(x\over2\right)$, then $\cos x={1-u^2\over1+u^2}$ and $dx={2\ du\over1+u^2}$. Hence
\begin{equation} \int {1\over\cos x}\ dx=\int{2\over1-u^2}\ du=\int\left[\frac{1}{1+u}+\frac{1}{1-u}\right]\ du \end{equation}
$\endgroup$ 2 $\begingroup$$\displaystyle\int\frac{1}{\cos x}dx=\int\frac{1}{\sin(x+\frac{\pi}{2})}dx=\int\frac{1}{\sin t}dt\;\;$ with $t=x+\frac{\pi}{2}.\;\;$ Now let $u=\tan\frac{t}{2}$ to get
$\displaystyle\int\frac{1}{\frac{2u}{1+u^2}}\cdot\frac{2}{1+u^2}du=\int\frac{1}{u}du=\ln|u|+C=\ln\big|\tan\left(\frac{x}{2}+\frac{\pi}{4}\right)\big|+C$,
which can be rewritten as $\displaystyle\ln\left\vert\frac{1+\tan\frac{x}{2}}{1-\tan\frac{x}{2}}\right\vert+C=\ln\left\vert\frac{\cos\frac{x}{2}+\sin\frac{x}{2}}{\cos\frac{x}{2}-\sin\frac{x}{2}}\right\vert+C=\ln\left\vert\sec x+\tan x\right\vert+C$
$\endgroup$ $\begingroup$When I learned how to do this, I used a much different substitution method. Sure, I'm subbing something, but not $tan(\frac x2)$.
$$\int\frac{1}{\cos(x)}\ dx=\int \sec(x)\ dx = \int \sec(x)\ \frac{\sec(x)+\tan(x)}{\sec(x)+\tan(x)}\ dx$$
Let $u = \sec(x)+\tan(x)$, and so $du = \sec(x)\ \tan(x) + {\sec}^2(x)\ dx$.
Substituting this back into the equation yields
$$\int \frac{{\sec}^2(x) + \sec (x)\ \tan (x)\ dx}{\sec(x) + \tan (x)} = \int \frac{du}u = \ln\ |\ u\ | + C$$
Substituting back for u yields $ln\ |\ \sec (x) + \tan (x)\ | + C$.
$\endgroup$ 1 $\begingroup$$$\int { \frac { 1 }{\cos(x) } } dx=\int { \frac { \cos { x }\, dx }{ \cos ^{ 2 }{ x } } } =\int { \frac { d\left( \sin { x } \right) }{ 1-\sin^{ 2 }{ x } } } =\frac { 1 }{ 2 } \int { \left( \frac { 1 }{ 1-\sin { x } } +\frac { 1 }{ 1+\sin { x } } \right) d\left( \sin { x } \right) } =\frac { 1 }{ 2 } \ln { C\left| \frac { 1+\sin { x } }{ 1-\sin { x } } \right| } $$
$\endgroup$ $\begingroup$These are the things I would try. I would find $\cos(x)$ in terms of $x/2$ because I would have to do that eventually anyway, here $\cos(x) = 2\cos^2(x/2) - 1$.
Then I would replace the $dx$ with an expression in $du$ as that also must be done eventually. \begin{align*} du = & 0.5 \sec^2(x/2)\, dx\\ dx = & 2 \cos^2(x/2)\, du \end{align*} Thus the integral becomes $$\int \frac{2 \cos^2(x/2)}{1 - 2 \cos^2(x/2)} du$$ This reminds me of the rule $\sec^2(x/2) = 1 + \tan^2(x/2)$, thus I divide the top and the bottom by $\cos^2(x/2)$, I rewrite it in terms of $\sec^2(x/2)$ and then in terms of $\tan^2(x/2)$ and then in terms of $u$ and I solve it.
$\endgroup$ $\begingroup$You can certainly do it with the substitution $t=\tan(x/2)$: you have $$ \int\frac{1}{\cos x}\,dx= \int\frac{1+t^2}{1-t^2}\frac{2}{1+t^2}\,dt= \int\left(\frac{1}{1+t}+\frac{1}{1-t}\right)\,dt= \log\left|\frac{1+t}{1-t}\right|+c $$ The back substitution gives $$ \log\left| \frac{\cos\frac{x}{2}+\sin\frac{x}{2}} {\cos\frac{x}{2}-\sin\frac{x}{2}} \right|+c=\log\left|\frac{1+\sin x}{\cos x}\right|+c $$
$\endgroup$ $\begingroup$\begin{align} I&=\int\frac{dx}{\cos x}=\int\frac{1-\sin x}{\cos x}\frac{dx}{1-\sin x}=\int\frac{1-\sin x}{\cos x}d\left(\frac{\cos x}{1-\sin x}\right)=\ln\left|\frac{\cos x}{1-\sin x}\right|+C \end{align}
$\endgroup$ $\begingroup$Here is yet another alternative.
As already shown in other answers we can compute $\int \frac {1}{\cos(t)} \thinspace {\rm {d}} t$ by computing $\int \frac {1}{\sin(x)} \thinspace {\rm {d}} x$ upon making use of the substitution $x=t+\frac{\pi}{2}$ and ${\rm {d}} x = {\rm {d}} t$.
By using the trigonometric addition formula
$$\sin(a+b)=\sin(a)\cos(b)+\cos(a)sin(b)$$
for $a=b=\frac{x}{2}$ we get $\sin(x)=\sin(\frac{x}{2}+\frac{x}{2})=2\sin(\frac{x}{2})\cos(\frac{x}{2})$. Using the substitution $u = \frac{x}{2}$ and ${\rm {d}} u = \frac {1}{2}\thinspace {\rm {d}} x$ we get
$$\begin{align} \int \frac {1}{\sin (x)} \thinspace {\rm {d}} x &= \int \frac {1}{2\sin \left (\frac {x}{2}\right )\cos \left (\frac {x}{2}\right )}\thinspace {\rm {d}} x = \int \frac {1}{\tan (u) \cos ^2(u)} \thinspace {\rm {d}} u \\&= \log \left| \tan(u) \right| + C = \log \left | \tan \left (\frac {x}{2}\right ) \right |+ C \end{align}$$
The last integral was easy to solve, because $\frac{1}{\cos^2(u)}$ is the derivative of $\tan(u)$. Alternatively you can substitute again $v = \tan(u)$ and ${\rm {d}} v = \frac {1}{\cos ^2(u)}\thinspace {\rm {d}} u$ to see this.
So we have
$$\int \frac {1}{\cos(t)} \thinspace {\rm {d}} t = \log \left | \tan \left (\frac {t}{2} + \frac {\pi}{4}\right ) \right |+ C \quad \text{and} \quad \int \frac {1}{\sin(x)} \thinspace {\rm {d}} x = \log \left | \tan \left (\frac {x}{2}\right ) \right |+ C$$
$\endgroup$