Integrals of Powers of Trigonometric Functions

Yesterday, while working on an optimization problem, I ran into an integral of the following form:

$$\int \frac{1}{\cos^3 \theta} d\theta$$

That gave me an excuse to look into integrals of this general type. Broadly speaking, such integrals can be written as $\int cos^n \theta d\theta$ or $\int sin^n \theta d\theta$, where n is an integer.

Let's start with the case n=1, for which we readily get $\int cos\theta d\theta=sin\theta +C$ or $\int sin\theta d\theta=-cos\theta +C$ — a basic, well-known result.

If n is a positive integer greater than 1, we can handle it via a recursive approach: more

$$\begin{aligned}\int \cos^n \theta d\theta=\int \cos^{n-1} \theta d(\sin\theta)=\cos^{n-1} \theta \sin\theta-\int \sin\theta d(\cos^{n-1}\theta) \\ =\cos^{n-1} \theta \sin\theta+(n-1)\int \sin^2\theta \cos^{n-2}\theta d\theta \\ =\cos^{n-1} \theta \sin\theta+(n-1)\int (1-\cos^2\theta) \cos^{n-2}\theta d\theta \\ =\cos^{n-1} \theta \sin\theta+(n-1)\int \cos^{n-2}\theta d\theta-(n-1)\int \cos^n\theta d\theta\end{aligned}$$

(Here integration by parts is used.)

That is, $n\int cos^n \theta d\theta=cos^{n-1} \theta sin\theta+(n-1)\int cos^{n-2}\theta d\theta$

$$\int \cos^n \theta d\theta=\frac{1}{n}[\cos^{n-1} \theta \sin\theta+(n-1)\int \cos^{n-2}\theta d\theta]$$

This completes the recursion. A similar formula holds for sine, which I'll just state directly:

$$\int \sin^n \theta d\theta=\frac{1}{n}[-\sin^{n-1} \theta \cos\theta+(n-1)\int \sin^{n-2}\theta d\theta]$$

Last night, though, it occurred to me to instead turn this into a polynomial integral to work it out:

$$\int \cos^n \theta d\theta=\int \cos^{n-1} \theta d(\sin\theta)$$

If we let $sin\theta=x$, the integral becomes

$$\int (1-x^2)^{\frac{n-1}{2}} dx$$

If n is odd (whether positive or negative), this integral is quite manageable. If n is even, or some other rational number, we'd need to express the result using the hypergeometric function (Hypergeometric Function). Here I'll only discuss the case where n is odd.

When n is positive, we can just expand the polynomial directly and integrate — nothing more to discuss there. When n is negative, this amounts to considering the integral

$$\int \frac{1}{(1-x^2)^k} dx$$

where k is a positive integer. When k=1, we have

$$\int \frac{1}{1-x^2} dx=\frac{1}{2} ln|\frac{1+x}{1-x}|$$

When k > 1, setting $\int \frac{1}{(1-x^2)^k} dx=I_k$, we get

$$\begin{aligned}I_k=\int \frac{1-x^2+x^2}{(1-x^2)^k} dx=I_{k-1}+\int \frac{x^2}{(1-x^2)^k} dx \\ =I_{k-1}-\frac{1}{2}\int \frac{x}{(1-x^2)^k} d(1-x^2) \\ =I_{k-1}+\frac{1}{2(k-1)}\int x d[(1-x^2)^{1-k}] \\ =I_{k-1}+\frac{1}{2(k-1)}[x (1-x^2)^{1-k}-\int (1-x^2)^{1-k}dx] \\ =(\frac{2k-3}{2k-2})I_{k-1}+\frac{x}{2(k-1)(1-x^2)^{k-1}}\end{aligned}$$

which completes the recursion.

For reference, here are the results I might end up using:

$$\int \frac{1}{\cos^3 \theta} d\theta=\frac{1}{4}(\frac{2\sin \theta}{\cos^2 \theta}+ln|\frac{1+\sin \theta}{1-\sin \theta}|)$$

$\int \frac{1}{sin^3 \theta} d\theta=-\frac{1}{4}(\frac{2cos \theta}{sin^2 \theta}+ln|\frac{1+cos \theta}{1-cos \theta}|)$

English translation of a post from 科学空间 | Scientific Spaces by 苏剑林. Original: https://kexue.fm/archives/1422
Translated automatically with claude-sonnet-5; all equations are reproduced verbatim from the source. Copyright remains with the original author.