# Evaluting: $\int\frac{1}{(1+\tan x)^2} dx$

I can solve this integral $$\int\frac{1}{(1+\tan x)^2} dx$$ using the substitution $t=\tan x$ i.e $x=\arctan t$. Does anyone know another way to solve this integral?

• Would you know what to do with $$\frac12\int \frac{1+\cos\,2x}{1+\sin\,2x} \mathrm dx$$? Jun 15, 2012 at 10:10
• This isn't any better than what you have, but the substitution $u=\tan(x/2)$ turns any rational expression in trig functions into a rational expression in $u$. Jun 15, 2012 at 10:46
• Ask Wolfram, but this only gives a result (and not a good(!) explanation)... Jun 15, 2012 at 10:48

$$\frac{1}{(1+\tan x)^{2}} = \frac{(\cos x)^{2}}{(\sin x+\cos x)^{2}}$$ $$= \frac{(\cos x)^{2}(\sin x - \cos x)^{2}}{(\cos 2x)^{2}}$$ $$= \frac{(\cos 2x - 1)(1-\sin 2x)}{2(\cos 2x)^{2}}$$ $$= 1/2 \left[(\sec 2x)-(\sec 2x)^{2}-(\tan 2x)+(\sec 2x)(\tan 2x)\right]$$ $$\int (\sec 2x) = 1/2\ln (\sec 2x + \tan 2x)$$ $$\int(\sec 2x)^{2}=1/2\cdot \tan 2x$$ $$\int(\tan 2x) = 1/2 \ln (\cos 2x)$$ $$\int (\sec 2x)(\tan 2x)=1/2 \sec 2x$$

Using J.M.'s suggestion $$\int \frac{1}{( 1 + \tan x)^2} dx = \int \frac{\frac 12 (1 + \cos 2x)}{ \sin ^2x +2 \sin x \cos 2 + \cos ^2 x} dx = \frac 12 \int \frac{1 + \cos 2x}{1 + \sin 2x}dx$$ $$= \frac 12 \left [ \int \frac 1 {1 + \sin 2x} dx + \int \frac{\cos 2x}{1 + \sin 2x}dx\right ]$$

$$= \frac 1 2 \frac{\sin x}{\sin x + \cos x} + \frac 1 4 \ln (1 + \sin 2x) + C$$

$$= \frac 12 \left [ \frac{-1}{1 + \tan x} + \ln(\sin x + \cos x)\right ] + C$$

EDIT:: first half of split up integral $$\int \frac{1}{1 + \sin 2x} dx = \frac 1 2 \int \frac{1}{1 + \sin u} du$$ and Weierstrass substitution $$\frac 12 \int \frac{1}{1 + \frac{2t}{1 + t^2}}\frac{2dt}{1 + t^2} = \int \frac{1}{(1 + t)^2} dt$$ $$\implies \frac{-1}{1 + t} = \frac{-1}{1 + \tan x} = \frac{-\cos x}{\sin x + \cos x}$$

From wolfram I got $\int \frac{\sin x}{ \sin x + \cos x}$ Using Weierstrass substitution I got $\frac{-\cos x}{\sin x + \cos x}$ And it seems $$\frac{\sin x}{ \sin x + \cos x} - \frac{-\cos x}{\sin x + \cos x} = 1$$ Hence both are vaid :D :D

And by clicking show steps at Wolframalpha

• Maybe the OP can follow all the steps you skipped, but I can't. How did you solve the first half of that split-up integral?
– Mike
Jun 15, 2012 at 14:18
• Sorry :( ... i got that result from wolframalpha, I updated .. above
– S L
Jun 15, 2012 at 17:15
• @experimentX $$\frac{\sin x}{ \sin x + \cos x} - \frac{-\cos x}{\sin x + \cos x} = 1 \neq 2$$ ;) Jun 15, 2012 at 19:02
• Hmm ... thanks for correction :)
– S L
Jun 15, 2012 at 19:03

Here's a similar substitution to $$t=\tan x$$ that circumvents partial fraction expansion:

$$y = \frac{1-\tan x}{1+\tan x} \implies x=\arctan \frac{1-y}{1+y} = \begin{cases}\dfrac\pi4 - \arctan y & y>-1 \\ -\dfrac{3\pi}4 - \arctan y & y<-1\end{cases}$$

\begin{align*} & \int \frac{dx}{(1+\tan x)^2} \\ &= \int \frac{-\frac{dy}{1+y^2}}{\left(1 + \frac{1-y}{1+y}\right)^2} \\ &= -\frac14 \int \left(1 + \frac{2y}{1+y^2}\right) \, dy \\ &= -\frac14 \left(y + \log\left(1+y^2\right)\right) + C \\ &= - \frac14 \left(\frac{1-\tan x}{1+\tan x} + \log\left(1 + \frac{(1-\tan x)^2}{(1+\tan x)^2}\right)\right) + C \\ &= - \frac12 \left(\frac1{1+\tan x} + \log\frac{\sec x}{1+\tan x}\right) + C \end{align*}

let $$t = \tan x$$ , $$dx = \frac{dt}{1+t^2}$$

$$I:= \int \frac{dx}{(1+x^2)} = \int \frac{1}{(1+t^2) (1+t)^2}dt$$

by partial fractions $$\displaystyle\frac{1}{(1+t^2) (1+t)^2} = \frac{at+b}{1+t^2} +\frac{ct+d}{(1+t)^2}$$ by cover up method

$$at+b +(a+t^2)\frac{ct+d}{(1+t)^2}= \frac{1}{(1+t)^2}$$ let $$t=i:= \sqrt{-1}$$ $$ai +b= \frac{1}{\sqrt2 e^{\frac\pi 2 i}}= \frac{\sqrt{2}e^{-i \frac\pi 2 }}{2} = -\frac i 2$$ $$b=0 , a= \frac {- 1} 2$$

$$ct +d + (t+1)^2\frac{at+b}{1+t^2}=\frac{1}{1+t^2}$$ $$d-c= \frac{1}{2}$$ substitute $$t=0$$ $$d=1, c =\frac{1}{2}$$

$$I = \frac{1}2 \int \frac{-t}{1+t^2}+\frac{t+1}{(t+1)^2} + \frac{1}{(1+t)^2}dt$$

$$=\frac 1 2 \left(\frac{-1}{2} \ln |t^2 +1| + \ln|t+1|- \frac{1}{t+1} \right)+C$$ $$= \frac 1 2 \left(\ln|\tan(x)+1|- \ln |\cos(x)|-\frac{1}{\tan x+1} \right)+C$$

• The OP clearly mentioned "I can solve this integral......using the substitution $t=\tan x$" Dec 4, 2023 at 18:45
• @DheerajGujrathi somehow I read it "I cann't solve this integral"
– pie
Dec 4, 2023 at 18:54

We first split the integral into two as: \begin{aligned} I&=\int \frac{\cos ^2 x}{(\sin x+\cos x)^2} d x \\& =\int \frac{\cos ^2 x}{1+\sin 2 x} d x \\ & =\frac{1}{2} \int \frac{1+\cos 2 x}{1+\sin 2 x} d x\\&=\frac{1}{2} \underbrace{\int \frac{d x}{1+\sin 2 x}}_J+\frac{1}{4} \ln |1+\sin 2 x| \end{aligned} For the first one, we use ‘rationalisation’ and get \begin{aligned} J&=\frac{1}{2} \int \frac{d y}{1+\sin y} \quad \textrm{ where }y=2x \\ & =\frac{1}{2} \int \frac{1-\sin y}{\cos ^2 y} d y\\&=\frac{1}{2} \int\left(\sec ^2 y-\tan y \sec y \right)d y \\ & =\frac{1}{2}(\tan y-\sec y)\\&=\frac{1}{2}(\tan 2 x-\sec 2 x)+c \end{aligned} We now can conclude that $$\int \frac{1}{(1+\tan x)^2} d x= \frac{1}{4}(\tan 2 x-\sec 2 x)+\frac{1}{4} \ln |1+\sin 2 x|+C$$

$$\frac{1}{(1+\tan x)^2} = \frac{1}{1+\tan x} -\frac{\tan(x)}{(1+ \tan x)^2}= \frac{1- \tan x}{1+ \tan x}+ \frac{\tan x}{1+\tan x } -\frac{1}{2}\left(\frac{\sin(2x)}{1+ \sin(2x)}\right)$$

note :- $$\displaystyle \tan(x+y )= \frac{\tan(x)+ \tan(y) }{1- \tan(x)\tan(y)} , \tan\left(\frac{\pi}{4} =1 \right)$$

$$=\cot(x+\frac \pi 4) +\frac{\sin(x)}{\sin(x)+ \cos(x)} -\frac{1}{2}\left(1- \frac{1}{1+ \sin(2x)}\right)$$

note:- $$\displaystyle 1+ \sin(2x) = 1+ \sin(\frac \pi 2 - 2(\frac \pi 4 - x))= 1+ \cos(2(x- \frac{\pi}{4})) =2\cos^2(x -\frac{\pi}{4})$$ why? $$\cos(2t) = 2\cos^2(t)-1$$

$$=\cot(x+\frac \pi 4) + \frac{\csc^2(x)}{((\cot x +1) (1+ \cot^2(x)) )}- \frac{1}{2} +\frac{1}{4 \cos^2(x -\frac{\pi}{4})}$$

here I will use partial fractions with $$\frac{1}{(1+ \cot x)(1+ \cot^2 x)}$$

$$=\cot(x+\frac \pi 4) + \frac 1 2 - \frac{ \cot(x)}{2}+ \frac{\csc^2(x)}{2(\cot x +1 )}- \frac{1}{2} +\frac{1}{4 \cos^2(x -\frac{\pi}{4})}$$

all of these are easy to find an anti-derivative to them $$\int \frac{1}{(1+\tan x)^2}dx = \ln\left|\sin \left( x+\frac \pi 4\right)\right| -\frac{\ln|\sin(x)|}{2} -\frac{\ln|\cot x +1|}{2} +\frac{1}{4} \tan \left(x -\frac{\pi}{4} \right) +C$$