9. Trigonometric substitution

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

\int\sqrt{4-x^2}\,dx

No inner-function-and-its-derivative, so substitution fails. Not a product, so parts fails. Nothing to peel, so §4.7 fails.

The way in is to introduce trigonometry that isn't there, chosen so a Pythagorean identity annihilates the root.

The three patterns

Expression Substitute Because Becomes
\sqrt{a^2-x^2} x = a\sin\theta 1-\sin^2=\cos^2 a\cos\theta
\sqrt{a^2+x^2} x = a\tan\theta 1+\tan^2=\sec^2 a\sec\theta
\sqrt{x^2-a^2} x = a\sec\theta \sec^2-1=\tan^2 a\tan\theta

In every case the root disappears. That's the entire purpose — the trig is a vehicle, not the destination.

Recognising which pattern you're in is a matter of the signs: minus-then-x^2 is sine, plus is tangent, x^2-then-minus is secant.

The full procedure

\int\sqrt{4-x^2}\,dx

Pattern 1 with a=2.

Substitute. x = 2\sin\theta, so dx = 2\cos\theta\,d\theta.

Simplify the root.

\sqrt{4-x^2} = \sqrt{4-4\sin^2\theta} = 2\sqrt{1-\sin^2\theta} = 2\sqrt{\cos^2\theta} = 2\cos\theta

The last step needs \cos\theta\ge0, which holds because we take \theta\in\left[-\frac\pi2,\frac\pi2\right] — the range where \arcsin lives (§2.7). The domain restriction is what removes the absolute value, and it's why the restricted inverse trig functions exist.

Integrate.

\int2\cos\theta\cdot2\cos\theta\,d\theta = 4\int\cos^2\theta\,d\theta

which is §4.7's half-angle case:

= 4\left[\frac\theta2+\frac{\sin2\theta}{4}\right] = 2\theta+\sin2\theta + C

Convert back — the step people forget. Use \sin2\theta = 2\sin\theta\cos\theta and a reference triangle: \sin\theta = \frac x2, so the opposite side is x, the hypotenuse 2, and the adjacent side \sqrt{4-x^2}. Hence \cos\theta = \frac{\sqrt{4-x^2}}{2}.

\sin2\theta = 2\cdot\frac x2\cdot\frac{\sqrt{4-x^2}}{2} = \frac{x\sqrt{4-x^2}}{2}

\theta = \arcsin\frac x2

\boxed{\int\sqrt{4-x^2}\,dx = 2\arcsin\frac x2+\frac{x\sqrt{4-x^2}}{2}+C}

The reference triangle

Converting back is the mechanical part, and drawing the triangle makes it automatic.

For x=a\sin\theta: \sin\theta = \frac xa means opposite =x, hypotenuse =a, so adjacent =\sqrt{a^2-x^2} by Pythagoras. Every trig function of \theta can then be read off.

For x=a\tan\theta: opposite =x, adjacent =a, hypotenuse =\sqrt{a^2+x^2}.

For x=a\sec\theta: hypotenuse =x, adjacent =a, opposite =\sqrt{x^2-a^2}.

Draw it every time. It takes ten seconds and eliminates the guesswork.

Completing the square first

The patterns need a^2 \pm x^2 exactly. Real integrands often hide it:

\int\frac{dx}{\sqrt{x^2+6x+13}}

Complete the square:

x^2+6x+13 = (x+3)^2+4

Now substitute w = x+3 to get \sqrt{w^2+4} — pattern 2 with a=2. Complete the square before deciding which pattern applies, or you'll conclude wrongly that none does.

When you don't need it

\int\frac{x\,dx}{\sqrt{4-x^2}}

That looks like pattern 1, but the numerator x is (up to a constant) the derivative of 4-x^2. Plain substitution u = 4-x^2 handles it in two lines:

= -\frac12\int u^{-1/2}du = -\sqrt u + C = -\sqrt{4-x^2}+C

Always check for ordinary substitution first. Trig substitution is heavier machinery, and reaching for it when u-substitution works is a common time-waster.

Definite integrals

Convert the limits to \theta and skip the back-substitution entirely — the same advantage as §4.5, and here it saves the reference triangle too.

\int_0^2\sqrt{4-x^2}\,dx

x=2\sin\theta: x=0\Rightarrow\theta=0; x=2\Rightarrow\theta=\frac\pi2.

= \int_0^{\pi/2}4\cos^2\theta\,d\theta = 4\left[\frac\theta2+\frac{\sin2\theta}{4}\right]_0^{\pi/2} = 4\cdot\frac\pi4 = \pi

Check geometrically: y=\sqrt{4-x^2} is the upper half of a circle of radius 2, and [0,2] is one quarter of it. A quarter of \pi r^2 = 4\pi is \pi ✓ — §0.1's formula, confirming a §4 computation.

Doing it in Python

The three patterns:

import sympy as sp

x = sp.Symbol('x')
a = 2

cases = [
    (sp.sqrt(a**2 - x**2), "x = 2 sin t"),
    (1/sp.sqrt(a**2 + x**2), "x = 2 tan t"),
    (1/sp.sqrt(x**2 - a**2), "x = 2 sec t"),
    (1/(a**2 + x**2), "x = 2 tan t"),
]

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

Watching the root vanish:

import sympy as sp

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

expr = sp.sqrt(4 - x**2)
substituted = expr.subs(x, 2*sp.sin(t))
print(f"start                      : {expr}")
print(f"after x = 2 sin(t)         : {substituted}")
print(f"simplified (|cos| -> cos)  : "
      f"{sp.simplify(substituted.rewrite(sp.cos))}")

# on the arcsin range, cos is non-negative, so the absolute value drops
t_range = sp.Symbol('t', real=True)
print(f"\nwith t in [-pi/2, pi/2]    : 2*cos(t), no absolute value needed")
print(f"check at t = 0.7           : {float(substituted.subs(t, 0.7)):.8f} "
      f"vs 2cos(0.7) = {float(2*sp.cos(0.7)):.8f}")

The quarter circle, three ways:

import sympy as sp
from math import pi, sqrt

x = sp.Symbol('x')

symbolic = sp.integrate(sp.sqrt(4 - x**2), (x, 0, 2))

def numeric(n=2_000_000):
    w = 2 / n
    return sum(sqrt(max(0.0, 4 - ((i + 0.5) * w)**2)) for i in range(n)) * w

print(f"symbolic          : {symbolic} = {float(symbolic):.8f}")
print(f"numeric           : {numeric():.8f}")
print(f"geometry (pi r^2/4): {pi * 4 / 4:.8f}")
print("\nthree independent routes, one answer -- section 0.1's formula")
print("confirming a section 4 computation")

Completing the square to reveal the pattern:

import sympy as sp

x = sp.Symbol('x')

for quad in (x**2 + 6*x + 13, x**2 - 4*x + 1, 3 - 2*x - x**2):
    completed = sp.simplify(sp.factor(sp.expand(quad)))
    # sympy's own completion
    w = sp.Symbol('w')
    print(f"{str(quad):<20} -> {sp.factor_terms(quad)}")
    print(f"{'':22} integral of 1/sqrt: "
          f"{sp.simplify(sp.integrate(1/sp.sqrt(quad), x))}\n")

When plain substitution beats it:

import sympy as sp

x = sp.Symbol('x')

pairs = [
    (sp.sqrt(4 - x**2), "trig substitution needed"),
    (x/sp.sqrt(4 - x**2), "plain u = 4 - x^2 suffices"),
    (x*sp.sqrt(4 - x**2), "plain u = 4 - x^2 suffices"),
]

for f, note in pairs:
    print(f"int {str(f):<22} = {str(sp.simplify(sp.integrate(f, x))):<38} [{note}]")

print("\nan x in the numerator usually means ordinary substitution works.")
print("check for that before reaching for the heavy machinery.")

Worked example

Evaluate \displaystyle\int\frac{dx}{x^2\sqrt{x^2+9}}.

Pattern 2, a=3: substitute x = 3\tan\theta, dx = 3\sec^2\theta\,d\theta.

The root:

\sqrt{x^2+9} = \sqrt{9\tan^2\theta+9} = 3\sqrt{\tan^2\theta+1} = 3\sec\theta

Assemble:

\int\frac{3\sec^2\theta\,d\theta}{9\tan^2\theta\cdot3\sec\theta} = \frac19\int\frac{\sec\theta}{\tan^2\theta}d\theta

Convert to sines and cosines — usually the fastest way to simplify a mess of secants and tangents:

\frac{\sec\theta}{\tan^2\theta} = \frac{1/\cos\theta}{\sin^2\theta/\cos^2\theta} = \frac{\cos\theta}{\sin^2\theta}

\frac19\int\frac{\cos\theta}{\sin^2\theta}d\theta

Now substitute w = \sin\theta, dw = \cos\theta\,d\theta:

= \frac19\int w^{-2}dw = -\frac{1}{9w}+C = -\frac{1}{9\sin\theta}+C

Back to x. Reference triangle for x=3\tan\theta: opposite =x, adjacent =3, hypotenuse =\sqrt{x^2+9}. So \sin\theta = \frac{x}{\sqrt{x^2+9}}:

\boxed{-\frac{\sqrt{x^2+9}}{9x}+C}

Check by differentiating — worth doing, because this one had four steps to go wrong in. Quotient rule on -\frac{(x^2+9)^{1/2}}{9x}:

-\frac{1}{9}\cdot\frac{\frac{x}{\sqrt{x^2+9}}\cdot x - \sqrt{x^2+9}}{x^2} = -\frac{1}{9}\cdot\frac{x^2 - (x^2+9)}{x^2\sqrt{x^2+9}} = \frac{1}{x^2\sqrt{x^2+9}} \quad\checkmark

The technique stack here was: trig substitution → convert to sin/cos → ordinary substitution → reference triangle. Non-trivial integrals routinely need three or four moves, and the skill is knowing what to try next when the current form is still stuck.

Your turn

1. \displaystyle\int\frac{dx}{\sqrt{9-x^2}}

2. \displaystyle\int\frac{dx}{x^2+16}

3. \displaystyle\int_0^3\sqrt{9-x^2}\,dx — and check geometrically.

4. Which substitution for \displaystyle\int\frac{dx}{\sqrt{x^2-25}}?

Solutions

1. Pattern 1 with a=3: x=3\sin\theta, dx=3\cos\theta\,d\theta, and \sqrt{9-x^2}=3\cos\theta:

\int\frac{3\cos\theta\,d\theta}{3\cos\theta} = \int d\theta = \theta+C = \boxed{\arcsin\frac x3+C}

Which you could also have read straight off §2.7's table as \int\frac{dx}{\sqrt{a^2-x^2}} = \arcsin\frac xa. The substitution derives the table entry rather than needing it.

2. Pattern 2 with a=4: x=4\tan\theta, dx=4\sec^2\theta\,d\theta, and x^2+16=16\sec^2\theta:

\int\frac{4\sec^2\theta\,d\theta}{16\sec^2\theta} = \frac14\int d\theta = \boxed{\frac14\arctan\frac x4+C}

Note there was no root at all — trig substitution works on a^2+x^2 whether or not it's under a radical.

3. From the lesson's method with a=3: x=3\sin\theta, limits \theta: 0\to\frac\pi2:

\int_0^{\pi/2}9\cos^2\theta\,d\theta = 9\left[\frac\theta2+\frac{\sin2\theta}{4}\right]_0^{\pi/2} = 9\cdot\frac\pi4 = \boxed{\frac{9\pi}{4}}

Geometric check: the curve is the upper half of a circle of radius 3, and [0,3] is a quarter of the full disc. Quarter of \pi(9) = 9\pi is \frac{9\pi}{4} ✓.

4. Pattern 3: \boxed{x = 5\sec\theta}, since the form is \sqrt{x^2-a^2} with a=5.

Then \sqrt{x^2-25} = 5\tan\theta and dx = 5\sec\theta\tan\theta\,d\theta, giving

\int\frac{5\sec\theta\tan\theta\,d\theta}{5\tan\theta} = \int\sec\theta\,d\theta = \ln|\sec\theta+\tan\theta|+C

= \ln\left|\frac{x}{5}+\frac{\sqrt{x^2-25}}{5}\right|+C = \ln\left|x+\sqrt{x^2-25}\right|+C'

absorbing the \ln 5 into the constant. And that expression is exactly \cosh^{-1}\frac x5 up to a constant — the hyperbolic inverse from §2.8, which is why hyperbolic substitutions are an equally valid alternative route for this pattern.

Check yourself in code

Compute four integrals that need trigonometric substitution.

Print SymPy's antiderivative for \sqrt{4-x^2}, \frac{1}{\sqrt{4+x^2}}, \frac{1}{4+x^2}, and \frac{1}{\sqrt{1-x^2}}.

Print exactly this:

int sqrt(4-x^2)      = x*sqrt(4 - x**2)/2 + 2*asin(x/2)
int 1/sqrt(4+x^2)    = asinh(x/2)
int 1/(4+x^2)        = atan(x/2)/2
int 1/sqrt(1-x^2)    = asin(x)
import sympy as sp

x = sp.Symbol('x')

cases = [
    ("sqrt(4-x^2)", sp.sqrt(4 - x**2)),
    ("1/sqrt(4+x^2)", 1/sp.sqrt(4 + x**2)),
    ("1/(4+x^2)", 1/(4 + x**2)),
    ("1/sqrt(1-x^2)", 1/sp.sqrt(1 - x**2)),
]

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

x = sp.Symbol('x')

cases = [
    ("sqrt(4-x^2)", sp.sqrt(4 - x**2)),
    ("1/sqrt(4+x^2)", 1/sp.sqrt(4 + x**2)),
    ("1/(4+x^2)", 1/(4 + x**2)),
    ("1/sqrt(1-x^2)", 1/sp.sqrt(1 - x**2)),
]

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

Three patterns, each chosen so a Pythagorean identity kills the root: \sqrt{a^2-x^2} takes x=a\sin\theta, \sqrt{a^2+x^2} takes a\tan\theta, and \sqrt{x^2-a^2} takes a\sec\theta. Complete the square first if the quadratic is disguised, and check whether ordinary substitution works before committing — an x in the numerator usually means it does. Draw the reference triangle to convert back, or convert the limits and skip that entirely.

Next: rational functions, where the technique is algebra rather than cleverness.