TExcelTAD
Home › Calculus in Depth › Trigonometric Integrals

Trigonometric Integrals

Integrals of powers and products of sines, cosines, tangents and secants follow a small number of patterns, each built on a Pythagorean identity or a double-angle formula plus a substitution. This lesson collects those patterns, proves the orthogonality relations they lead to, and shows why those relations are the foundation of Fourier analysis: audio codecs, JPEG and signal processing all rely on them.

Powers of sine and cosine: ∫sin⁡mxcos⁡nx dx\int \sin^m x \cos^n x\,dx

Case Strategy Identity used
nn odd save one cos⁡x\cos x, convert the rest to sines, u=sin⁡xu = \sin x cos⁡2x=1−sin⁡2x\cos^2 x = 1 - \sin^2 x
mm odd save one sin⁡x\sin x, convert the rest to cosines, u=cos⁡xu = \cos x sin⁡2x=1−cos⁡2x\sin^2 x = 1 - \cos^2 x
both even lower the powers with half-angle formulas sin⁡2x=1−cos⁡2x2\sin^2 x = \frac{1 - \cos 2x}{2}, cos⁡2x=1+cos⁡2x2\cos^2 x = \frac{1 + \cos 2x}{2}

Odd power.

∫sin⁡2xcos⁡3x dx=∫sin⁡2x (1−sin⁡2x)cos⁡x dxu=sin⁡x, du=cos⁡x dx=∫(u2−u4) du=sin⁡3x3−sin⁡5x5+C\begin{aligned} \int \sin^2 x \cos^3 x\,dx &= \int \sin^2 x\,(1 - \sin^2 x) \cos x\,dx && u = \sin x,\ du = \cos x\,dx \\ &= \int (u^2 - u^4)\,du = \frac{\sin^3 x}{3} - \frac{\sin^5 x}{5} + C \end{aligned}

Both even.

∫cos⁡4x dx=∫(1+cos⁡2x2)2dx=14∫(1+2cos⁡2x+cos⁡22x) dx=14∫(1+2cos⁡2x+1+cos⁡4x2) dx=3x8+sin⁡2x4+sin⁡4x32+C\begin{aligned} \int \cos^4 x\,dx &= \int \Big(\frac{1 + \cos 2x}{2}\Big)^2 dx = \frac{1}{4}\int (1 + 2\cos 2x + \cos^2 2x)\,dx \\ &= \frac{1}{4}\int \Big(1 + 2\cos 2x + \frac{1 + \cos 4x}{2}\Big)\,dx \\ &= \frac{3x}{8} + \frac{\sin 2x}{4} + \frac{\sin 4x}{32} + C \end{aligned}
python · try it yourself
import sympy as sp

x = sp.symbols('x')
mine = {
    sp.sin(x)**2 * sp.cos(x)**3: sp.sin(x)**3 / 3 - sp.sin(x)**5 / 5,
    sp.cos(x)**4: 3*x/8 + sp.sin(2*x)/4 + sp.sin(4*x)/32,
}
for f, F in mine.items():
    print(f"∫ {f} dx")
    print("   SymPy :", sp.integrate(f, x))
    print("   ours  :", F, "   derivative matches:", sp.simplify(sp.diff(F, x) - f) == 0)
∫ sin(x)**2*cos(x)**3 dx
   SymPy : -sin(x)**5/5 + sin(x)**3/3
   ours  : -sin(x)**5/5 + sin(x)**3/3    derivative matches: True
∫ cos(x)**4 dx
   SymPy : 3*x/8 + sin(x)*cos(x)**3/4 + 3*sin(x)*cos(x)/8
   ours  : 3*x/8 + sin(2*x)/4 + sin(4*x)/32    derivative matches: True

For cos⁡4x\cos^4 x SymPy writes its answer with powers of sin⁡\sin and cos⁡\cos instead of multiple angles. Both are antiderivatives (here they are in fact equal), and in general any two differ by a constant.

Tangent and secant: ∫tan⁡mxsec⁡nx dx\int \tan^m x \sec^n x\,dx

The identities are ddxtan⁡x=sec⁡2x\frac{d}{dx} \tan x = \sec^2 x, ddxsec⁡x=sec⁡xtan⁡x\frac{d}{dx} \sec x = \sec x \tan x and sec⁡2x=1+tan⁡2x\sec^2 x = 1 + \tan^2 x.

Case Strategy
nn even (n≥2n \ge 2) save sec⁡2x\sec^2 x, convert the rest to tangents, u=tan⁡xu = \tan x
mm odd save sec⁡xtan⁡x\sec x \tan x, convert the rest to secants, u=sec⁡xu = \sec x
otherwise identities plus parts; often needs ∫sec⁡x dx\int \sec x\,dx

Two integrals to know:

∫tan⁡x dx=ln⁡∣sec⁡x∣+C∫sec⁡x dx=ln⁡∣sec⁡x+tan⁡x∣+C(multiply and divide by sec⁡x+tan⁡x, then u=sec⁡x+tan⁡x)\begin{aligned} \int \tan x\,dx &= \ln\lvert \sec x \rvert + C \\ \int \sec x\,dx &= \ln\lvert \sec x + \tan x \rvert + C && \text{(multiply and divide by } \sec x + \tan x, \text{ then } u = \sec x + \tan x) \end{aligned}

∫sec⁡3x dx\int \sec^3 x\,dx is the classic case that needs parts and solving for the integral: ∫sec⁡3x dx=12(sec⁡xtan⁡x+ln⁡∣sec⁡x+tan⁡x∣)+C\int \sec^3 x\,dx = \frac{1}{2}(\sec x \tan x + \ln\lvert \sec x + \tan x \rvert) + C.

Products with different frequencies

For ∫sin⁡mxcos⁡nx dx\int \sin mx \cos nx\,dx and similar, the product-to-sum identities turn a product into a sum:

sin⁡Acos⁡B=12[sin⁡(A−B)+sin⁡(A+B)]sin⁡Asin⁡B=12[cos⁡(A−B)−cos⁡(A+B)]cos⁡Acos⁡B=12[cos⁡(A−B)+cos⁡(A+B)]\begin{aligned} \sin A \cos B &= \frac{1}{2}[\sin(A - B) + \sin(A + B)] \\ \sin A \sin B &= \frac{1}{2}[\cos(A - B) - \cos(A + B)] \\ \cos A \cos B &= \frac{1}{2}[\cos(A - B) + \cos(A + B)] \end{aligned}

Orthogonality

For integers m,n≥1m, n \ge 1, integrating over a full period:

∫−ππsin⁡mx⋅sin⁡nx dx=0 if m≠n,π if m=n∫−ππcos⁡mx⋅cos⁡nx dx=0 if m≠n,π if m=n∫−ππsin⁡mx⋅cos⁡nx dx=0 always\begin{aligned} \int_{-\pi}^{\pi} \sin mx \cdot \sin nx\,dx &= 0 \text{ if } m \ne n,\quad \pi \text{ if } m = n \\ \int_{-\pi}^{\pi} \cos mx \cdot \cos nx\,dx &= 0 \text{ if } m \ne n,\quad \pi \text{ if } m = n \\ \int_{-\pi}^{\pi} \sin mx \cdot \cos nx\,dx &= 0 \text{ always} \end{aligned}

Proof (first line, m≠nm \ne n). By product-to-sum, the integrand is 12[cos⁡((m−n)x)−cos⁡((m+n)x)]\frac{1}{2}[\cos((m - n)x) - \cos((m + n)x)]. For any nonzero integer kk, ∫−ππcos⁡kx dx=[sin⁡kxk]−ππ=0\int_{-\pi}^{\pi} \cos kx\,dx = \Big[\frac{\sin kx}{k}\Big]_{-\pi}^{\pi} = 0. For m=nm = n, the first term is 12cos⁡0=12\frac{1}{2}\cos 0 = \frac{1}{2}, contributing π\pi. The third line holds because sin⁡mxcos⁡nx\sin mx \cos nx is odd. ∎

Treat functions on [−π,π][-\pi, \pi] as vectors with the "dot product" ⟨f,g⟩=∫−ππfg dx\langle f, g \rangle = \int_{-\pi}^{\pi} f g\,dx. Then the sines and cosines are mutually perpendicular, just like the axes of Rn\mathbb{R}^n. A numerical check of the Gram matrix:

python · try it yourself
import numpy as np
from scipy.integrate import quad

basis = [("sin x", lambda x: np.sin(x)), ("sin 2x", lambda x: np.sin(2 * x)),
         ("cos x", lambda x: np.cos(x)), ("cos 3x", lambda x: np.cos(3 * x))]
print(" " * 8 + "".join(f"{n:>9}" for n, _ in basis))
for n1, f in basis:
    row = [quad(lambda x: f(x) * g(x), -np.pi, np.pi)[0] for _, g in basis]
    print(f"{n1:>8}" + "".join(f"{v + 0.0:9.4f}" for v in np.round(row, 10)))
            sin x   sin 2x    cos x   cos 3x
   sin x   3.1416   0.0000   0.0000   0.0000
  sin 2x   0.0000   3.1416   0.0000   0.0000
   cos x   0.0000   0.0000   3.1416   0.0000
  cos 3x   0.0000   0.0000   0.0000   3.1416

The diagonal is π≈3.1416\pi \approx 3.1416 and everything else is 0.

Fourier coefficients

Because of orthogonality, the coefficients of f(x)=∑bnsin⁡nxf(x) = \sum b_n \sin nx can be read off one at a time: multiply both sides by sin⁡kx\sin kx and integrate; every term with n≠kn \ne k vanishes, leaving

bk=1π∫−ππf(x)sin⁡kx dxb_k = \frac{1}{\pi} \int_{-\pi}^{\pi} f(x) \sin kx\,dx

For the square wave f(x)=sign⁡(x)f(x) = \operatorname{sign}(x), this gives bk=4kπb_k = \frac{4}{k\pi} for odd kk and 0 for even kk:

python · try it yourself
import numpy as np
from scipy.integrate import quad

sq = lambda x: np.sign(x)
for k in range(1, 7):
    bk = quad(lambda x: sq(x) * np.sin(k * x), -np.pi, np.pi, points=[0])[0] / np.pi
    print(f"b_{k} = {round(bk, 6) + 0.0:.6f}    4/(kπ) = {4 / (k * np.pi) if k % 2 else 0:.6f}")

x0 = np.pi / 2
partial = sum(4 / (k * np.pi) * np.sin(k * x0) for k in range(1, 200, 2))
print("100-term Fourier series at x = π/2:", round(float(partial), 4))
b_1 = 1.273240    4/(kπ) = 1.273240
b_2 = 0.000000    4/(kπ) = 0.000000
b_3 = 0.424413    4/(kπ) = 0.424413
b_4 = 0.000000    4/(kπ) = 0.000000
b_5 = 0.254648    4/(kπ) = 0.254648
b_6 = 0.000000    4/(kπ) = 0.000000
100-term Fourier series at x = π/2: 0.9968

In software

  • Audio and compression. MP3, AAC and Opus transform short windows of sound into cosine coefficients (the MDCT); JPEG does the same for 8×8 pixel blocks with the DCT. Orthogonality is what makes each coefficient independent, so small ones can be dropped.
  • The FFT computes all the discrete Fourier coefficients of nn samples in O(nlog⁡n)O(n \log n) time; the integrals above are its continuous counterpart (Fourier analysis).
  • Positional encodings. Transformer models encode token positions with sines and cosines of geometric frequencies; their near-orthogonality lets the model separate positions.

Exercises

Exercise 1: Odd power of sine

Compute ∫sin⁡3x dx\int \sin^3 x\,dx.

Answer

−cos⁡x+cos⁡3x3+C-\cos x + \frac{\cos^3 x}{3} + C.

Solution

∫(1−cos⁡2x)sin⁡x dx\int (1 - \cos^2 x) \sin x\,dx, u=cos⁡xu = \cos x, du=−sin⁡x dxdu = -\sin x\,dx: −∫(1−u2) du=−u+u33+C-\int (1 - u^2)\,du = -u + \frac{u^3}{3} + C.

Exercise 2: Even powers

Compute ∫0πsin⁡2xcos⁡2x dx\int_0^{\pi} \sin^2 x \cos^2 x\,dx.

Answer

π8\frac{\pi}{8}.

Solution
sin⁡xcos⁡x=12sin⁡2x ⇒ sin⁡2xcos⁡2x=14sin⁡22x=18(1−cos⁡4x)∫0π18(1−cos⁡4x) dx=π8−0\begin{aligned} &\sin x \cos x = \frac{1}{2} \sin 2x \ \Rightarrow\ \sin^2 x \cos^2 x = \frac{1}{4} \sin^2 2x = \frac{1}{8}(1 - \cos 4x) \\ &\int_0^{\pi} \frac{1}{8}(1 - \cos 4x)\,dx = \frac{\pi}{8} - 0 \end{aligned}
python · try it yourself
import sympy as sp
x = sp.symbols('x')
print(sp.integrate(sp.sin(x)**2 * sp.cos(x)**2, (x, 0, sp.pi)))
pi/8

Exercise 3: Tangent and secant

Compute ∫tan⁡2xsec⁡4x dx\int \tan^2 x \sec^4 x\,dx.

Answer

tan⁡3x3+tan⁡5x5+C\frac{\tan^3 x}{3} + \frac{\tan^5 x}{5} + C.

Solution

Save sec⁡2x\sec^2 x, convert sec⁡2x=1+tan⁡2x\sec^2 x = 1 + \tan^2 x: ∫tan⁡2x (1+tan⁡2x)sec⁡2x dx\int \tan^2 x\,(1 + \tan^2 x) \sec^2 x\,dx, u=tan⁡xu = \tan x: ∫(u2+u4) du\int (u^2 + u^4)\,du.

Exercise 4: A Fourier coefficient

Find b1b_1 for f(x)=xf(x) = x on [−π,π][-\pi, \pi].

Answer

b1=2b_1 = 2.

Solution

b1=1π∫−ππxsin⁡x dxb_1 = \frac{1}{\pi}\int_{-\pi}^{\pi} x \sin x\,dx. By parts, ∫xsin⁡x dx=−xcos⁡x+sin⁡x\int x \sin x\,dx = -x \cos x + \sin x, so the integral is [−xcos⁡x+sin⁡x]−ππ=π−(−π)=2π\Big[-x \cos x + \sin x\Big]_{-\pi}^{\pi} = \pi - (-\pi) = 2\pi. Divide by π\pi.

Test yourself

For ∫sin⁡4xcos⁡5x dx\int \sin^4 x \cos^5 x\,dx, what is the best first step?

  1. Use half-angle formulas
  2. Substitute u=cos⁡xu = \cos x
  3. Save one cos⁡x\cos x, write cos⁡4x=(1−sin⁡2x)2\cos^4 x = (1 - \sin^2 x)^2, substitute u=sin⁡xu = \sin x
  4. Integrate by parts

What is ∫−ππsin⁡3x⋅sin⁡5x dx\int_{-\pi}^{\pi} \sin 3x \cdot \sin 5x\,dx?

  1. 0
  2. π\pi
  3. 2π2\pi
  4. −π-\pi

Which identity reduces even powers of cosine?

  1. cos⁡2x=1−sin⁡2x\cos^2 x = 1 - \sin^2 x
  2. sec⁡2x=1+tan⁡2x\sec^2 x = 1 + \tan^2 x
  3. cos⁡2x=2sin⁡xcos⁡x\cos 2x = 2 \sin x \cos x
  4. cos⁡2x=1+cos⁡2x2\cos^2 x = \frac{1 + \cos 2x}{2}