Calculus · Indefinite integrals

Integrating Trigonometric Functions

Trigonometric integrals are everywhere: areas bounded by curves in polar coordinates, arc lengths, Fourier series, oscillations in physics. There is one substitution that handles them all, and a toolbox of shortcuts that handles most of them faster. This post explains both: when the heavy machinery is needed, and how to avoid it when it is not.

1. The universal substitution \(t = \tan\frac x2\)

As in the previous post, \(R(u, v)\) denotes a rational function: an expression built from \(u\), \(v\) and constants using \(+, -, \times, \div\). Here \(u = \sin x\), \(v = \cos x\), e.g. \( \frac{1 + \sin x}{\sin x(1 + \cos x)} \).

Case 1° Integrals \( \int R(\sin x, \cos x)\,dx \) are reduced to integrals of rational functions of \(t\) by the substitution \[ \tan\frac x2 = t, \qquad\text{whence}\qquad \sin x = \frac{2t}{1 + t^2}, \qquad \cos x = \frac{1 - t^2}{1 + t^2}, \qquad dx = \frac{2\,dt}{1 + t^2}. \]

Where the formulas come from. Using the double-angle formulas and dividing by \( 1 = \cos^2\frac x2 + \sin^2\frac x2 \):

\[ \sin x = \frac{2\sin\frac x2\cos\frac x2}{\cos^2\frac x2 + \sin^2\frac x2} = \frac{2\tan\frac x2}{1 + \tan^2\frac x2}, \qquad \cos x = \frac{\cos^2\frac x2 - \sin^2\frac x2}{\cos^2\frac x2 + \sin^2\frac x2} = \frac{1 - \tan^2\frac x2}{1 + \tan^2\frac x2}, \]

and from \( x = 2\arctan t \), \( dx = \frac{2\,dt}{1 + t^2} \). All three are rational in \(t\), so the whole integrand becomes rational, and partial fractions finish the job. That is why the substitution is called universal: it always works.

(−1, 0) P(cos x, sin x) t x x/2 O
Figure 1. The geometry behind \(t = \tan\frac x2\). The angle at \((-1, 0)\) is half the central angle \(x\) (inscribed angle theorem), so the line through \((-1, 0)\) and \(P\) has slope \(t\), and meets the \(y\)-axis at height \(t\). Each \(t\) gives one point of the circle, and the coordinates of that point turn out to be rational in \(t\).
Example 1 \( \displaystyle\int\frac{dx}{2 + \cos x} \): \[ \int\frac{\frac{2\,dt}{1 + t^2}}{2 + \frac{1 - t^2}{1 + t^2}} = \int\frac{2\,dt}{3 + t^2} = \frac{2}{\sqrt3}\arctan\frac{t}{\sqrt3} = \frac{2}{\sqrt3}\arctan\Big(\frac{1}{\sqrt3}\tan\frac x2\Big) + C. \]
Example 2 \( \displaystyle\int\frac{dx}{\sin x} = \int\frac{\frac{2\,dt}{1 + t^2}}{\frac{2t}{1 + t^2}} = \int\frac{dt}{t} = \ln\Big|\tan\frac x2\Big| + C. \)
Watch the points \(x = \pi + 2k\pi\) At \(x = \pi\), \(\tan\frac x2\) is undefined, so the substitution is valid only on intervals \( (-\pi + 2k\pi, \pi + 2k\pi) \). The antiderivative in Example 1 jumps at \(x = \pm\pi\), even though \( \frac{1}{2 + \cos x} \) is continuous everywhere. For a definite integral across such a point, split the interval there.

2. Shortcuts: when a simpler substitution works

The universal substitution often leads to unpleasant rational functions of high degree. In many common cases a simpler substitution does the job, and the symmetry of \(R\) tells you which:

IfSubstituteTypical example
\(R(-\sin x, \cos x) = -R(\sin x, \cos x)\) (odd in \(\sin\))\(t = \cos x\)\(\sin^3 x\), \(\frac{\sin x}{1 + \cos^2 x}\)
\(R(\sin x, -\cos x) = -R(\sin x, \cos x)\) (odd in \(\cos\))\(t = \sin x\)\(\sin^2 x\cos^3 x\)
\(R(-\sin x, -\cos x) = R(\sin x, \cos x)\)\(t = \tan x\)\(\frac{1}{1 + \sin^2 x}\), \(\frac{1}{\sin x\cos x}\)

Why the first one works: if \(R\) is odd in \(\sin x\), then \( R(\sin x, \cos x) = \sin x\cdot R_1(\sin^2 x, \cos x) \) for a rational \(R_1\). With \(t = \cos x\), \( \sin x\,dx = -dt \) and \( \sin^2 x = 1 - t^2 \): everything is rational in \(t\). The other two cases are similar (for the third, \(\sin^2 x = \frac{t^2}{1 + t^2}\), \(\cos^2 x = \frac{1}{1 + t^2}\), \(dx = \frac{dt}{1 + t^2}\)).

Example 3 \( \displaystyle\int\sin^3 x\,dx = \int(1 - \cos^2 x)\sin x\,dx \overset{t = \cos x}{=} -\int(1 - t^2)\,dt = -\cos x + \frac{\cos^3 x}{3} + C. \)
Example 4 \( \displaystyle\int\frac{dx}{1 + \sin^2 x} \): the integrand does not change when both \(\sin\) and \(\cos\) change sign, so \(t = \tan x\): \[ \int\frac{\frac{dt}{1 + t^2}}{1 + \frac{t^2}{1 + t^2}} = \int\frac{dt}{1 + 2t^2} = \frac{1}{\sqrt2}\arctan\big(\sqrt2\tan x\big) + C. \]

3. Powers of sine and cosine: reduction formulas

For odd powers the shortcut of Section 2 is quickest. For even powers, there are two options: lower the power with \( \sin^2 x = \frac{1 - \cos 2x}{2} \), \( \cos^2 x = \frac{1 + \cos 2x}{2} \), or use a reduction formula.

Case 2° · Reduction formulas For a natural number \(n\): \[ \int\sin^n x\,dx = -\frac1n\sin^{n-1}x\cos x + \frac{n - 1}{n}\int\sin^{n-2}x\,dx, \] \[ \int\cos^n x\,dx = \frac1n\cos^{n-1}x\sin x + \frac{n - 1}{n}\int\cos^{n-2}x\,dx. \]

Derivation (for the sine). Write \( \sin^n x = \sin^{n-1}x\cdot\sin x \) and integrate by parts with \( u = \sin^{n-1}x \), \( dv = \sin x\,dx \):

\[ I_n = -\sin^{n-1}x\cos x + (n - 1)\int\sin^{n-2}x\cos^2 x\,dx. \]

Replace \( \cos^2 x = 1 - \sin^2 x \): the last integral is \( I_{n-2} - I_n \). So \( I_n = -\sin^{n-1}x\cos x + (n - 1)I_{n-2} - (n - 1)I_n \), and solving for \(I_n\) gives the formula. The trick of "the integral reappearing on the right" is worth remembering; it comes up again and again.

Each application lowers the power by \(2\), until \( \int dx = x \) or \( \int\sin x\,dx = -\cos x \) is reached.

Example 5 \[ \int\sin^4 x\,dx = -\frac14\sin^3 x\cos x + \frac34\int\sin^2 x\,dx = -\frac14\sin^3 x\cos x + \frac34\Big(\frac x2 - \frac12\sin x\cos x\Big) + C. \]

Wallis's formula

On \([0, \frac\pi2]\) the boundary term \( \sin^{n-1}x\cos x \) vanishes at both ends, so the reduction formula becomes simply \( W_n = \frac{n - 1}{n}W_{n-2} \) for \( W_n = \int_0^{\pi/2}\sin^n x\,dx \) (and the same for cosine). Starting from \( W_0 = \frac\pi2 \), \( W_1 = 1 \):

\[ \int_0^{\pi/2}\sin^n x\,dx = \begin{cases}\dfrac{(n - 1)(n - 3)\cdots 1}{n(n - 2)\cdots 2}\cdot\dfrac\pi2, & n \text{ even},\\[2ex] \dfrac{(n - 1)(n - 3)\cdots 2}{n(n - 2)\cdots 3}, & n \text{ odd}.\end{cases} \]

For example \( \int_0^{\pi/2}\sin^4 x\,dx = \frac34\cdot\frac12\cdot\frac\pi2 = \frac{3\pi}{16} \) and \( \int_0^{\pi/2}\sin^5 x\,dx = \frac45\cdot\frac23 = \frac{8}{15} \).

4. Reciprocal powers: \(\int\frac{dx}{\sin^n x}\), \(\int\frac{dx}{\cos^n x}\)

Case 3° · Reduction formulas For a natural number \(n \ge 2\): \[ \int\frac{dx}{\sin^n x} = -\frac{1}{n - 1}\,\frac{\cos x}{\sin^{n-1}x} + \frac{n - 2}{n - 1}\int\frac{dx}{\sin^{n-2}x}, \] \[ \int\frac{dx}{\cos^n x} = \frac{1}{n - 1}\,\frac{\sin x}{\cos^{n-1}x} + \frac{n - 2}{n - 1}\int\frac{dx}{\cos^{n-2}x}. \]

These are the formulas of Section 3 run "backwards": put \(n \to -n + 2\) into the formula for \(\int\sin^n x\,dx\) and solve for the integral with the more negative power. The chain ends at

\[ \int\frac{dx}{\sin x} = \ln\Big|\tan\frac x2\Big|, \qquad \int\frac{dx}{\cos x} = \ln\Big|\tan\Big(\frac x2 + \frac\pi4\Big)\Big|, \qquad \int\frac{dx}{\sin^2 x} = -\cot x, \qquad \int\frac{dx}{\cos^2 x} = \tan x. \]
Example 6 · The integral of \(\sec^3\) This one appears when computing the arc length of a parabola: \[ \int\frac{dx}{\cos^3 x} = \frac12\,\frac{\sin x}{\cos^2 x} + \frac12\int\frac{dx}{\cos x} = \frac{\sin x}{2\cos^2 x} + \frac12\ln\Big|\tan\Big(\frac x2 + \frac\pi4\Big)\Big| + C. \]

5. Products \(\sin^m x\cos^n x\)

Case 4° Integrals \( \int\sin^m x\cos^n x\,dx \), with integers \(m\) and \(n\), are computed with suitable transformations or with the reduction formulas \[ \int\sin^m x\cos^n x\,dx = \frac{\sin^{m+1}x\cos^{n-1}x}{m + n} + \frac{n - 1}{m + n}\int\sin^m x\cos^{n-2}x\,dx, \] \[ \int\sin^m x\cos^n x\,dx = -\frac{\sin^{m-1}x\cos^{n+1}x}{m + n} + \frac{m - 1}{m + n}\int\sin^{m-2}x\cos^n x\,dx, \] valid for \(m + n \ne 0\).

The first formula lowers the power of the cosine by 2, the second the power of the sine. In practice, it is usually faster to choose by parity:

Example 7 · One odd power \( \displaystyle\int\sin^2 x\cos^3 x\,dx = \int\sin^2 x(1 - \sin^2 x)\cos x\,dx \overset{t = \sin x}{=} \int(t^2 - t^4)\,dt = \frac{\sin^3 x}{3} - \frac{\sin^5 x}{5} + C. \)
Example 8 · Both even \( \displaystyle\int\sin^2 x\cos^2 x\,dx = \frac14\int\sin^2 2x\,dx = \frac18\int(1 - \cos 4x)\,dx = \frac x8 - \frac{\sin 4x}{32} + C. \)

6. Products of sines and cosines of different arguments

Case 5° For integrals such as \( \int\sin px\cos qx\,dx \), \( \int\sin px\sin qx\,dx \), \( \int\cos px\cos qx\,dx \) (\(p, q\) real constants), turn the product into a sum: \[ \sin\alpha\sin\beta = \tfrac12\big[\cos(\alpha - \beta) - \cos(\alpha + \beta)\big], \] \[ \cos\alpha\cos\beta = \tfrac12\big[\cos(\alpha - \beta) + \cos(\alpha + \beta)\big], \] \[ \sin\alpha\cos\beta = \tfrac12\big[\sin(\alpha - \beta) + \sin(\alpha + \beta)\big]. \]

These follow by adding or subtracting the addition formulas, e.g. \( \cos(\alpha - \beta) - \cos(\alpha + \beta) = 2\sin\alpha\sin\beta \). After the conversion, each term is a single sine or cosine, which integrates immediately.

Example 9 \[ \int\sin 3x\cos 5x\,dx = \frac12\int\big[\sin(-2x) + \sin 8x\big]dx = \frac{\cos 2x}{4} - \frac{\cos 8x}{16} + C. \]
Why this matters: orthogonality For integers \(m, n \ge 1\), the same identities give \[ \int_{-\pi}^{\pi}\sin mx\sin nx\,dx = \int_{-\pi}^{\pi}\cos mx\cos nx\,dx = \begin{cases}0, & m \ne n,\\ \pi, & m = n,\end{cases} \qquad \int_{-\pi}^{\pi}\sin mx\cos nx\,dx = 0. \] This is exactly what makes the Fourier coefficients formulas work (see the post on Fourier series).

7. Summary

IntegralMethod
\( \int R(\sin x, \cos x)\,dx \)\( t = \tan\frac x2 \) (always works), or the shortcuts \( t = \cos x \), \( t = \sin x \), \( t = \tan x \)
\( \int\sin^n x\,dx \), \( \int\cos^n x\,dx \)odd \(n\): \(t = \cos x\) / \(t = \sin x\); even \(n\): halve the angle or reduction formula
\( \int_0^{\pi/2}\sin^n x\,dx \)Wallis: \( W_n = \frac{n - 1}{n}W_{n-2} \)
\( \int\frac{dx}{\sin^n x} \), \( \int\frac{dx}{\cos^n x} \)reduction formulas, ending at \( \ln|\tan\frac x2| \) or \( \ln|\tan(\frac x2 + \frac\pi4)| \)
\( \int\sin^m x\cos^n x\,dx \)an odd power: split off one factor; both even: double angle; or reduction formulas
\( \int\sin px\cos qx\,dx \) etc.product-to-sum identities

8. Practice problems

Try each one before opening the solution. More solved problems from this topic are in Integrals.

Problem 1: \( \displaystyle\int\cos^5 x\,dx \)

\( \int(1 - \sin^2 x)^2\cos x\,dx \), \(t = \sin x\): \( \int(1 - 2t^2 + t^4)\,dt = \sin x - \frac23\sin^3 x + \frac15\sin^5 x + C \).

Problem 2: \( \displaystyle\int\frac{dx}{\sin x\cos x} \)

The integrand is unchanged under \( (\sin, \cos) \to (-\sin, -\cos) \), so \(t = \tan x\): \( \int\frac{dt}{t} = \ln|\tan x| + C \). (Or: \( \frac{1}{\sin x\cos x} = \frac{2}{\sin 2x} \).)

Problem 3: \( \displaystyle\int_0^{\pi/2}\cos^6 x\,dx \)

Wallis: \( \frac56\cdot\frac34\cdot\frac12\cdot\frac\pi2 = \frac{5\pi}{32} \).

Problem 4: \( \displaystyle\int\frac{dx}{1 + \sin x + \cos x} \)

\(t = \tan\frac x2\): the denominator becomes \( \frac{(1 + t^2) + 2t + (1 - t^2)}{1 + t^2} = \frac{2(1 + t)}{1 + t^2} \), so the integral is \( \int\frac{dt}{1 + t} = \ln\big|1 + \tan\frac x2\big| + C \).

Problem 5: \( \displaystyle\int\cos x\cos 2x\cos 3x\,dx \)

\( \cos x\cos 3x = \frac12(\cos 2x + \cos 4x) \), so the integrand is \( \frac12(\cos^2 2x + \cos 2x\cos 4x) = \frac14(1 + \cos 4x) + \frac14(\cos 2x + \cos 6x) \). Integral: \( \frac x4 + \frac{\sin 2x}{8} + \frac{\sin 4x}{16} + \frac{\sin 6x}{24} + C \).

Problem 6: Derive the reduction formula for \( \int\cos^n x\,dx \).

Parts with \( u = \cos^{n-1}x \), \( dv = \cos x\,dx \): \( I_n = \cos^{n-1}x\sin x + (n - 1)\int\cos^{n-2}x\sin^2 x\,dx = \cos^{n-1}x\sin x + (n - 1)(I_{n-2} - I_n) \). Solve for \(I_n\).

Final thoughts

For trigonometric integrals, the universal substitution \(t = \tan\frac x2\) is the guarantee: it turns any rational expression in \(\sin x\) and \(\cos x\) into a rational function. But the guarantee is expensive, so check the cheaper routes first. Is the integrand odd in \(\sin\) or \(\cos\)? Can the powers be halved by the double-angle formulas? Is it a product of different frequencies, ready for product-to-sum? Reduction formulas, all derived by the same parts-and-solve trick, cover the rest, and on \([0, \frac\pi2]\) they give Wallis's formula almost for free.

Related posts: integrating irrational functions, Fourier series (where orthogonality is used), and Euler integrals (where Wallis-type integrals reappear through the beta function).