Calculus/Integration techniques/Tangent Half Angle

Another useful change of variables is the Weierstrass substitution, named after Karl Weierstrass:
 * $$t=\tan\left(\tfrac{x}{2}\right)$$

With this transformation, using the double-angle trigonometric identities,
 * $$\sin(x)=\frac{2t}{1+t^2}\quad\cos(x)=\frac{1-t^2}{1+t^2}\quad\tan(x)=\frac{2t}{1-t^2}\quad dx=\frac{2\ dt}{1+t^2}$$

This transforms a trigonometric integral into an algebraic integral, which may be easier to integrate.

For example, if the integrand is $$\frac{1}{1+\sin(x)}$$ then
 * $$\int\limits_0^\frac{\pi}{2}\frac{dx}{1+\sin(x)}=\int\limits_0^1\frac{\left(\frac{2\ dt}{1+t^2}\right)}{1+\left(\frac{2t}{1+t^2}\right)}=\int\limits_0^1 \frac{2\ dt}{(t+1)^2}$$

This method can be used to further simplify trigonometric integrals produced by the changes of variables described earlier.

For example, if we are considering the integral
 * $$I=\int\limits_{-1}^1 \frac{\sqrt{1-x^2}}{1+x^2}dx$$

we can first use the substitution $$x=\sin(\theta)$$, which gives
 * $$I=\int\limits_{-\frac{\pi}{2}}^\frac{\pi}{2} \frac{\cos^2(\theta)}{1+\sin^2(\theta)}d\theta$$

then use the tan-half-angle substition to obtain
 * $$I=\int\limits_{-1}^1\frac{(1-t^2)^2}{1+6t^2+t^4}\cdot\frac{2\ dt}{1+t^2}$$

In effect, we've removed the square root from the original integrand. We could do this with a single change of variables, but doing it in two steps gives us the opportunity of doing the trigonometric integral another way.

Having done this, we can split the new integrand into partial fractions, and integrate.


 * $$\begin{align}

I &=\int\limits_{-1}^1 \frac{2-\sqrt2}{t^2+3-2\sqrt2}dt+\int\limits_{-1}^1 \frac{2+\sqrt2}{t^2+3+2\sqrt2}dt-\int\limits_{-1}^1 \frac{2}{1+t^2}dt \\[8pt] &=\frac{4-2\sqrt2}{\sqrt{3-2\sqrt2}}\cdot\arctan\left(\sqrt{3+2\sqrt2}\right)+\frac{4+2\sqrt2}{\sqrt{3+2\sqrt2}}\cdot\arctan\left(\sqrt{3-2\sqrt2}\right)-\pi\end{align}$$

This result can be further simplified by use of the identities
 * $$3\pm2\sqrt2=\left(\sqrt2\pm1\right)^2\quad\arctan\left(\sqrt2\pm 1\right)=\left(\frac{1}{4}\pm\frac{1}{8}\right)\pi$$

ultimately leading to
 * $$I=\left(\sqrt2-1\right)\pi$$

In principle, this approach will work with any integrand which is the square root of a quadratic multiplied by the ratio of two polynomials. However, it should not be applied automatically.

E.g., in this last example, once we deduced
 * $$I=\int\limits_{-\frac{\pi}{2}}^\frac{\pi}{2}\frac{\cos^2(\theta)}{1+\sin^2(\theta)}d\theta$$

we could have used the double angle formula, since this contains only even powers of cos and sin. Doing that gives
 * $$I=\int\limits_{-\frac{\pi}{2}}^\frac{\pi}{2} \frac{1+\cos(2\theta)}{3-\cos(2\theta)}d\theta=\frac{1}{2}\int\limits_{-\pi}^\pi\frac{1+\cos(\phi)}{3-\cos(\phi)}d\phi$$

Using tan-half-angle on this new, simpler, integrand gives
 * $$\begin{align}

I &=\int\limits_{-\infty}^\infty \frac{1}{1+2t^2}\cdot\frac{dt}{1+t^2} \\ &=\int\limits_{-\infty}^\infty\frac{2\ dt}{1+2t^2}-\int\limits_{-\infty}^\infty \frac{dt}{1+t^2} \end{align}$$

This can be integrated on sight to give
 * $$I=\frac{4}{\sqrt2}\cdot\frac{\pi}{2}-2\frac{\pi}{2}=\left(\sqrt2-1\right)\pi$$

This is the same result as before, but obtained with less algebra, which shows why it is best to look for the most straightforward methods at every stage.

A more direct way of evaluating the integral I is to substitute $$t=\tan(\theta)$$ right from the start, which will directly bring us to the line
 * $$I=\int\limits_{-\infty}^\infty \frac{1}{1+2t^2}\cdot\frac{dt}{1+t^2}$$

above. More generally, the substitution $$t=\tan(x)$$ gives us
 * $$\sin(x)=\frac{t}{\sqrt{1+t^2}}\quad\cos(x)=\frac{1}{\sqrt{1+t^2}}\quad dx=\frac{dt}{1+t^2}$$

so this substitution is the preferable one to use if the integrand is such that all the square roots would disappear after substitution, as is the case in the above integral.

Using the trigonometric substitution $$t=a\tan(x)$$, then $$dt=a\sec^2(x)dx$$ and $$\sqrt{t^2+a^2}=a\sec(x)$$ when $$-\frac{\pi}{2}<x<\frac{\pi}{2}$$. So,
 * Example




 * $$\int\frac{dt}{(t^2+a^2)\sqrt{t^2+a^2}}$$
 * $$=\int\frac{a\sec^2(x)}{a^3\sec^3(x)}dx$$
 * $$=\frac{1}{a^2}\int\cos(x)dx$$
 * $$=\frac{\sin(x)}{a^2}+C$$
 * $$=\frac{1}{a^2}\cdot\frac{a\tan(x)}{a\sec(x)}+C$$
 * $$=\frac{t}{a^2\sqrt{t^2+a^2}}+C$$
 * }
 * $$=\frac{\sin(x)}{a^2}+C$$
 * $$=\frac{1}{a^2}\cdot\frac{a\tan(x)}{a\sec(x)}+C$$
 * $$=\frac{t}{a^2\sqrt{t^2+a^2}}+C$$
 * }
 * $$=\frac{t}{a^2\sqrt{t^2+a^2}}+C$$
 * }
 * $$=\frac{t}{a^2\sqrt{t^2+a^2}}+C$$
 * }

Alternate Method
In general, to evaluate integrals of the form


 * $$\int\frac{A+B\cos(x)+C\sin(x)}{a+b\cos(x)+c\sin(x)}\ dx$$ ,

it is extremely tedious to use the aforementioned "tan half angle" substitution directly, as one easily ends up with a rational function with a 4th degree denominator. Instead, we may first write the numerator as


 * $${A+B\cos(x)+C\sin(x)\equiv p\Big(a+b\cos(x)+c\sin(x)\Big)+q\frac{d}{dx}\Big(a+b\cos(x)+c\sin(x)\Big)+r}$$.

Then the integral can be written as


 * $$\begin{align}\int\left(p+q\cdot\frac{\frac{d}{dx}\bigl(a+b\cos(x)+c\sin(x)\bigr)}{a+b\cos(x)+c\sin(x)}+\frac{r}{a+b\cos(x)+c\sin(x)}\right)dx\end{align}$$

which can be evaluated much more easily.

Example
Evaluate $$\int\frac{\cos(x)+2}{\cos(x)+\sin(x)}dx$$ ,

Let


 * $$\cos(x)+2\equiv p\Big(\cos(x)+\sin(x)\Big)+q\frac{d}{dx}\Big(\cos(x)+\sin(x)\Big)+r$$.

Then


 * $$\cos(x)+2\equiv p\Big(\cos(x)+\sin(x)\Big)+q\Big(\cos(x)-\sin(x)\Big)+r$$
 * $$\cos(x)+2\equiv (p+q)\cos(x)+(p-q)\sin(x)+r$$

Comparing coefficients of cos(x), sin(x) and the constants on both sides, we obtain


 * $$\begin{cases} p+q&=1 \\ p-q&=0 \\ r&=2 \end{cases}$$

yielding p = q = 1/2, r = 2. Substituting back into the integrand,


 * $$\begin{align}\int\frac{\cos(x)+2}{\cos(x)+\sin(x)}dx=\int\frac{dx}{2}+\frac{1}{2}\int\frac{d\bigl(\cos(x)+\sin(x)\bigr)}{\cos(x)+\sin(x)}+\int\frac{2}{\cos(x)+\sin(x)}dx\end{align}$$

The last integral can now be evaluated using the "tan half angle" substitution described above, and we obtain


 * $$\int\frac{2}{\cos(x)+\sin(x)}dx=\sqrt2\ln\left|\frac{\tan\bigl(\frac{x}{2}\bigr)-1+\sqrt2}{\tan\bigl(\frac{x}{2}\bigr)-1-\sqrt2}\right|+C$$.

The original integral is thus


 * $${\int\frac{\cos(x)+2}{\cos(x)+\sin(x)}dx=\frac{x+\ln\Big|\cos(x)+\sin(x)\Big|}{2}+\sqrt2\ln\left|\frac{\tan\bigl(\frac{x}{2}\bigr)-1+\sqrt2}{\tan\bigl(\frac{x}{2}\bigr)-1-\sqrt2}\right|+C}$$.