8. Trigonometric integrals

📖 Reading · 11 min
💡 Every code box below is live — edit it and hit Run.

Substitution needs an inner function with its derivative present. Products of sines and cosines rarely oblige — until you use an identity to manufacture the right shape.

This lesson is a small set of patterns. Recognise which one you're in and the integral falls out.

\int\sin^mx\cos^nx\,dx

Case 1: an odd power. Peel off one factor to become du, and convert the rest with \sin^2+\cos^2=1.

\int\sin^3x\cos^2x\,dx

Sine has the odd power. Split off one \sin x and rewrite the rest:

\sin^3x = \sin^2x\cdot\sin x = (1-\cos^2x)\sin x

\int(1-\cos^2x)\cos^2x\,\sin x\,dx

Now u=\cos x, du = -\sin x\,dx:

= -\int(1-u^2)u^2du = -\int(u^2-u^4)du = -\frac{u^3}{3}+\frac{u^5}{5}+C

= \boxed{\frac{\cos^5x}{5}-\frac{\cos^3x}{3}+C}

The rule: if the sine power is odd, substitute u=\cos x; if the cosine power is odd, substitute u=\sin x. The odd one gets peeled, the other one becomes u. If both are odd, either works.

Case 2: both even. No factor to peel, so use the half-angle identities from §0.4 to lower the powers:

\sin^2x = \frac{1-\cos2x}{2}, \qquad \cos^2x = \frac{1+\cos2x}{2}

\int\sin^2x\,dx = \int\frac{1-\cos2x}{2}dx = \frac x2 - \frac{\sin2x}{4}+C

Note the average value: over a full period, \sin^2 averages exactly \frac12 — the \frac x2 term — which is why RMS voltage is peak over \sqrt2.

Higher even powers need the identity repeatedly. \int\sin^4x\,dx takes two rounds, and produces a \cos^22x that needs the identity again.

\int\tan^mx\sec^nx\,dx

The same idea with a different identity, 1+\tan^2x=\sec^2x, and different derivative pairings:

\frac{d}{dx}\tan x = \sec^2 x, \qquad \frac{d}{dx}\sec x = \sec x\tan x

If the secant power is even: peel off \sec^2x for du, convert the rest, substitute u=\tan x.

If the tangent power is odd: peel off \sec x\tan x for du, convert the rest, substitute u=\sec x.

If neither (odd secant, even tangent) — e.g. \int\sec^3x\,dx — you're in for integration by parts and a circular argument. The result

\int\sec x\,dx = \ln|\sec x+\tan x|+C

is worth memorising rather than deriving; the standard derivation multiplies top and bottom by \sec x + \tan x, which nobody would think of unaided.

Products of different frequencies

\int\sin(mx)\cos(nx)\,dx

Use the product-to-sum identities:

\sin A\cos B = \tfrac12\left[\sin(A-B)+\sin(A+B)\right] \sin A\sin B = \tfrac12\left[\cos(A-B)-\cos(A+B)\right] \cos A\cos B = \tfrac12\left[\cos(A-B)+\cos(A+B)\right]

Products become sums, and sums integrate term by term.

This is the computational heart of Fourier analysis. Over [-\pi,\pi],

\int_{-\pi}^{\pi}\sin(mx)\sin(nx)\,dx = \begin{cases}\pi & m=n\\ 0 & m\ne n\end{cases}

Different frequencies integrate to zero — they're orthogonal. That single fact is what lets you extract one frequency's coefficient from a signal containing all of them, and it's what §8.5 is built on.

Doing it in Python

The patterns, with their answers:

import sympy as sp

x = sp.Symbol('x')

cases = [
    (sp.sin(x)**3 * sp.cos(x)**2, "odd sine -> u = cos x"),
    (sp.sin(x)**2, "both even -> half angle"),
    (sp.sin(x)**4, "both even -> half angle twice"),
    (sp.tan(x)**3 * sp.sec(x)**4, "even secant -> u = tan x"),
    (sp.sec(x), "memorise this one"),
]

for f, hint in cases:
    print(f"int {str(f):<26} = {sp.simplify(sp.integrate(f, x))}")
    print(f"{'':4}[{hint}]\n")

The average value of \sin^2, and where RMS comes from:

from math import sin, pi, sqrt

def integrate(f, a, b, n=200000):
    w = (b - a) / n
    return sum(f(a + (i + 0.5) * w) for i in range(n)) * w

avg = integrate(lambda t: sin(t)**2, 0, 2*pi) / (2*pi)
print(f"average of sin^2 over one period : {avg:.10f}")
print(f"exactly 1/2                      : {0.5:.10f}\n")

peak = 340.0   # volts, mains peak
print(f"peak voltage : {peak:.1f} V")
print(f"RMS voltage  : {peak * sqrt(avg):.1f} V   = peak / sqrt(2)")
print("\nthat is why a '240 V' supply peaks near 340 V")

Orthogonality, the fact Fourier analysis runs on:

from math import sin, pi

def integrate(f, a, b, n=400000):
    w = (b - a) / n
    return sum(f(a + (i + 0.5) * w) for i in range(n)) * w

print(f"{'m':>4} {'n':>4} {'int sin(mx)sin(nx) over [-pi,pi]':>36}")
for m in (1, 2, 3):
    for n in (1, 2, 3):
        v = integrate(lambda t: sin(m*t)*sin(n*t), -pi, pi)
        print(f"{m:>4} {n:>4} {v:>36.8f}")

print(f"\npi = {pi:.8f}: the diagonal gives pi, everything else gives 0.")
print("different frequencies are orthogonal -- that is what makes")
print("Fourier coefficients extractable one at a time.")

The odd-power trick, step by step:

import sympy as sp

x, u = sp.symbols('x u')

original = sp.sin(x)**3 * sp.cos(x)**2
print(f"start          : {original}")

rewritten = (1 - sp.cos(x)**2) * sp.cos(x)**2 * sp.sin(x)
print(f"peel one sine  : {rewritten}")
print(f"same function  : {sp.simplify(original - rewritten) == 0}\n")

in_u = -(1 - u**2) * u**2
print(f"with u = cos x : integral of {in_u} du")
print(f"               = {sp.integrate(in_u, u)}")
print(f"back-substituted: {sp.integrate(in_u, u).subs(u, sp.cos(x))}")
print(f"sympy directly  : {sp.simplify(sp.integrate(original, x))}")

Worked example

Evaluate \displaystyle\int_0^{\pi/2}\sin^2x\cos^3x\,dx.

Cosine has the odd power, so peel one cosine and convert the rest.

\cos^3x = \cos^2x\cdot\cos x = (1-\sin^2x)\cos x

\int_0^{\pi/2}\sin^2x(1-\sin^2x)\cos x\,dx

Substitute u = \sin x, du = \cos x\,dx. Limits: x=0\Rightarrow u=0; x=\frac\pi2\Rightarrow u=1.

= \int_0^1u^2(1-u^2)du = \int_0^1\left(u^2-u^4\right)du

= \left[\frac{u^3}{3}-\frac{u^5}{5}\right]_0^1 = \frac13-\frac15 = \frac{5-3}{15} = \boxed{\frac{2}{15}}

Sanity check. \frac{2}{15}\approx0.133. The integrand is zero at both endpoints and peaks somewhere in between at a value under 0.4, over an interval of length 1.57. A small positive number is right. ✓

What made it work was the odd power. Had it been \sin^2x\cos^2x, no factor peels off cleanly and you'd need half-angle identities twice — considerably more work for a similar-looking problem. Count the parities before choosing a route.

Your turn

1. \displaystyle\int\sin^3x\,dx

2. \displaystyle\int\cos^2x\,dx

3. \displaystyle\int\tan^2x\,dx

4. \displaystyle\int_{-\pi}^{\pi}\sin(2x)\cos(3x)\,dx — think before computing.

Solutions

1. Odd sine power, and no cosine at all — so u=\cos x:

\int\sin^3x\,dx = \int(1-\cos^2x)\sin x\,dx = -\int(1-u^2)du = -u+\frac{u^3}{3}+C

= \boxed{\frac{\cos^3x}{3}-\cos x + C}

2. Both even (cosine squared, sine to the zeroth), so half-angle:

\int\cos^2x\,dx = \int\frac{1+\cos2x}{2}dx = \boxed{\frac x2+\frac{\sin2x}{4}+C}

Same structure as \int\sin^2 but with a plus sign — and the two must sum to \int1\,dx = x, which they do: the \frac{\sin 2x}{4} terms cancel ✓.

3. No peelable factor. Use the identity to convert to something integrable:

\tan^2x = \sec^2x-1

\int(\sec^2x-1)dx = \boxed{\tan x - x + C}

Converting rather than substituting is the move for even tangent powers with no secant. Same trick handles \int\cot^2.

4. By symmetry, zero — no computation needed.

\sin(2x) is odd and \cos(3x) is even, so their product is odd (§0.2). An odd function integrated over the symmetric interval [-\pi,\pi] gives 0.

If you'd rather compute: the product-to-sum identity gives \frac12\left[\sin(-x)+\sin(5x)\right], and both \sin(-x) and \sin(5x) integrate to zero over a symmetric interval about the origin.

This is orthogonality again. \int_{-\pi}^\pi\sin(mx)\cos(nx)\,dx = 0 for all m,n — sines and cosines are orthogonal to each other at every frequency pair, which is why a Fourier series can carry independent sine and cosine coefficients without them interfering.

Check yourself in code

Compute five trigonometric integrals with SymPy.

Print the antiderivative of \sin^2x, \sin^3x, \sin^3x\cos^2x, \tan^2 x, and \sin^3x\cos x.

Print exactly this:

int sin^2(x)           = x/2 - sin(x)*cos(x)/2
int sin^3(x)           = cos(x)**3/3 - cos(x)
int sin^3(x)*cos^2(x)  = cos(x)**5/5 - cos(x)**3/3
int tan^2(x)           = -x + sin(x)/cos(x)
int sin^3(x)*cos(x)    = sin(x)**4/4
import sympy as sp

x = sp.Symbol('x')

cases = [
    ("sin^2(x)", sp.sin(x)**2),
    ("sin^3(x)", sp.sin(x)**3),
    ("sin^3(x)*cos^2(x)", sp.sin(x)**3 * sp.cos(x)**2),
    ("tan^2(x)", sp.tan(x)**2),
    ("sin^3(x)*cos(x)", sp.sin(x)**3 * sp.cos(x)),
]

for name, f in cases:
    print(f"int {name:<18} = ...")
import sympy as sp

x = sp.Symbol('x')

cases = [
    ("sin^2(x)", sp.sin(x)**2),
    ("sin^3(x)", sp.sin(x)**3),
    ("sin^3(x)*cos^2(x)", sp.sin(x)**3 * sp.cos(x)**2),
    ("tan^2(x)", sp.tan(x)**2),
    ("sin^3(x)*cos(x)", sp.sin(x)**3 * sp.cos(x)),
]

for name, f in cases:
    print(f"int {name:<18} = {sp.integrate(f, x)}")

Count the parities first. An odd power peels off one factor to serve as du while the identity converts the rest — sine odd means u=\cos x, cosine odd means u=\sin x. Both even means half-angle identities to lower the powers, and \int\sin^2 = \frac x2 - \frac{\sin2x}{4} is the one that gives RMS its \sqrt2. For tangents and secants the same logic runs on 1+\tan^2=\sec^2. And products of different frequencies become sums, integrating to zero — the orthogonality that Fourier series depend on.

Next: using trigonometry on integrals that contain no trigonometry at all.