# Other ways to calculate this indefinite integral ($\int \frac{2dx}{(\cos(x) - \sin(x))^2}$)?

I came across the following indefinite integral $$\int \frac{2dx}{(\cos(x) - \sin(x))^2}$$ and was able to solve it by doing the following: First I wrote \begin{align*} \int \frac{2dx}{(\cos(x) - \sin(x))^2} &= \int \frac{2dx}{1 - 2\cos(x)\sin(x)} \\ &= \int \frac{2dx}{1 - \sin(2x)} \\ \end{align*}

Then setting $2x = z$, \begin{align*} &= \int \frac{dz}{1-\sin(z)}\\ &= \int \frac{1+\sin(z)}{\cos^2(z)}dz \\ &= \int \sec^2(z) + \tan(z)\sec(z) dz \\ &= \tan(z) + \sec(z) \\ &= \tan(2x) + \sec(2x). \end{align*}

The solutions to the problem were given as $\tan(x + \pi/2)$ or $\frac{\cos(x) + \sin(x)}{\cos(x) - \sin(x)}$. I checked that these solutions are in face equivalent to my solution of $\tan(2x) + \sec(2x)$.

My question is, are there other ways to calculate this integral that more "directly" produce these solutions? Actually, any elegant calculation methods in general would be interesting.

## 3 Answers

$$\int\frac{dx}{(\cos x-\sin x)^2}=\int\frac{dx}{(\sqrt2\cos(x+\frac\pi4))^2}$$ where you recognize the derivative of a tangent.

A very general and useful method is the use of the exponential representation

$$\cos x:=\frac{e^{ix}+e^{-ix}}2,\\\sin x:=\frac{e^{ix}-e^{-ix}}{2i}$$ together with the change of variable $z:=e^{ix}$ such that $dx=dz/iz$.

In your case

$$\int\frac{dx}{(\cos x-\sin x)^2} =\int \frac{4\,dz}{(z+z^{-1}+iz-iz^{-1})^2iz} =\int \frac{2\,d(z^2)}{((1+i)z^2+(1-i))^2i}$$ which is elementary.

HINT:

$$1-\sin2x=1-\cos2\left(\dfrac\pi4-x\right)=2\sin^2\left(\dfrac\pi4-x\right)=\dfrac2{\csc^2\left(\dfrac\pi4-x\right)}$$

As $\csc(-A)=-\csc A,$

$$\csc^2\left(\dfrac\pi4-x\right)=\csc^2\left(x-\dfrac\pi4\right)$$

$$\int\csc^2y\ dy=-\cot y+K$$

Alternatively,

$$1-\sin2x=\dfrac{(1-\tan x)^2}{1+\tan^2x}$$

see my nice answer:

$$\int \frac{2\ dx}{(\cos x-\sin x)^2}=\int \frac{2\ dx}{\cos^2 x\left(1-\frac{\sin x}{\cos x}\right)^2}$$ $$=2\int \frac{\sec^2 x\ dx}{\left(1-\tan x\right)^2}$$ $$=-2\int \frac{d(1-\tan x)}{\left(1-\tan x\right)^2}$$ $$=-2 \frac{-1}{\left(1-\tan x\right)}+C$$$$=\frac{2\cos x}{\cos x-\sin x}+C$$