21. Derivatives of the trigonometric functions

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

§1.4 and §1.5 proved two limits and promised they'd pay off. Here's the payoff: every trigonometric derivative, and they all follow from those two.

The derivative of sine

\frac{d}{dx}\sin x = \cos x

Proof. Start from the definition and use the angle-sum identity from §0.4, \sin(x+h) = \sin x\cos h + \cos x\sin h:

\frac{\sin(x+h)-\sin x}{h} = \frac{\sin x\cos h + \cos x\sin h - \sin x}{h}

Group the \sin x terms:

= \sin x\cdot\frac{\cos h - 1}{h} + \cos x\cdot\frac{\sin h}{h}

Both fractions are limits we already own:

\lim_{h\to0}\frac{\cos h - 1}{h} = 0 \quad (\S1.5), \qquad \lim_{h\to0}\frac{\sin h}{h} = 1 \quad (\S1.4)

So the whole thing tends to

\sin x \cdot 0 + \cos x\cdot 1 = \cos x \qquad\blacksquare

Every ingredient was earned. The angle-sum identity came from geometry, the two limits from the squeeze theorem and a conjugate trick, and the split into two terms from the limit laws. And the result is clean — no stray constant — precisely because we're in radians.

Sanity-check the shape: \sin is steepest at x=0, where \cos 0 = 1 ✓; flat at its peak x = \pi/2, where \cos(\pi/2) = 0 ✓; and decreasing on (\pi/2, \pi), where cosine is negative ✓.

The rest of the table

\frac{d}{dx}\cos x = -\sin x

by the identical argument with \cos(x+h) = \cos x\cos h - \sin x\sin h.

The other four come from the quotient rule. For tangent:

\frac{d}{dx}\tan x = \frac{d}{dx}\frac{\sin x}{\cos x} = \frac{\cos x\cos x - \sin x(-\sin x)}{\cos^2 x} = \frac{\cos^2x + \sin^2x}{\cos^2 x} = \frac{1}{\cos^2 x} = \sec^2 x

The Pythagorean identity collapsing the numerator to 1 is the nice moment.

The full table:

f(x) f'(x)
\sin x \cos x
\cos x -\sin x
\tan x \sec^2 x
\csc x -\csc x\cot x
\sec x \sec x\tan x
\cot x -\csc^2 x

The pattern that makes this memorable: every function beginning with "co" (cosine, cosecant, cotangent) picks up a minus sign, and its derivative is the "co-" version of its partner's. Learn the left column and the co-rule and you have all six.

With the chain rule

In practice you almost never differentiate a bare \sin x. The chain rule version is what you'll use:

\frac{d}{dx}\sin(u) = \cos(u)\cdot u', \qquad \frac{d}{dx}\tan(u) = \sec^2(u)\cdot u'

\frac{d}{dx}\sin(5x) = 5\cos(5x), \qquad \frac{d}{dx}\cos(x^2) = -2x\sin(x^2)

The cycle of four

\sin x \xrightarrow{\ d/dx\ } \cos x \xrightarrow{\ d/dx\ } -\sin x \xrightarrow{\ d/dx\ } -\cos x \xrightarrow{\ d/dx\ } \sin x

Four derivatives returns you to the start. So $\frac{d^{4n}}{dx^{4n}}\sin x = \sin x$ for any n, and to find the 100th derivative you only need $100 \bmod 4 = 0$: it's \sin x.

The two-step version is the important one:

\frac{d^2}{dx^2}\sin x = -\sin x

which says y = \sin x solves the differential equation

y'' = -y

That equation is simple harmonic motion, and it's arguably the most important differential equation in physics: a mass on a spring, a pendulum at small amplitude, an LC circuit, a photon's field, a vibrating string. Acceleration proportional to displacement and pointing back toward equilibrium. Its general solution is A\cos(\omega t) + B\sin(\omega t), and §13.5 derives that properly.

Sine and cosine aren't merely convenient here — they are defined by this property in more advanced treatments, with the triangles as an afterthought.

Doing it in Python

The whole table, verified at once:

from math import sin, cos, tan, pi

def numerical(f, x, h=1e-6):
    return (f(x + h) - f(x - h)) / (2 * h)

sec = lambda x: 1 / cos(x)
csc = lambda x: 1 / sin(x)
cot = lambda x: cos(x) / sin(x)

table = [
    ("sin", sin, lambda x: cos(x)),
    ("cos", cos, lambda x: -sin(x)),
    ("tan", tan, lambda x: sec(x)**2),
    ("csc", csc, lambda x: -csc(x)*cot(x)),
    ("sec", sec, lambda x: sec(x)*tan(x)),
    ("cot", cot, lambda x: -csc(x)**2),
]

x = 0.7
print(f"{'f':>5} {'rule':>14} {'numerical':>14} {'match':>8}")
for name, f, df in table:
    r, n = df(x), numerical(f, x)
    print(f"{name:>5} {r:>14.8f} {n:>14.8f} {abs(r-n) < 1e-5!s:>8}")

The two limits doing their work inside the proof:

from math import sin, cos

x = 1.1
print(f"{'h':>10} {'(cos h - 1)/h':>16} {'sin h / h':>14} {'assembled':>14}")
for k in range(1, 8):
    h = 10.0 ** -k
    a = (cos(h) - 1) / h
    b = sin(h) / h
    print(f"{h:>10.0e} {a:>16.10f} {b:>14.10f} {sin(x)*a + cos(x)*b:>14.10f}")

print(f"\ncos({x}) = {cos(x):.10f}")
print("the first limit kills the sin x term; the second delivers cos x intact")

The cycle of four:

import sympy as sp

x = sp.Symbol('x')
expr = sp.sin(x)
for k in range(1, 6):
    expr = sp.diff(expr, x)
    print(f"d^{k}/dx^{k} sin(x) = {expr}")

print(f"\n100th derivative: {sp.diff(sp.sin(x), x, 100)}   (100 mod 4 = 0)")

Simple harmonic motion, checked numerically:

from math import sin, cos, pi

def second_derivative(f, x, h=1e-4):
    return (f(x + h) - 2 * f(x) + f(x - h)) / (h * h)

print(f"{'x':>8} {'y = sin x':>12} {'y\'\'':>14} {'-y':>12}")
for x in (0.3, 1.0, 2.5, 4.2):
    print(f"{x:>8} {sin(x):>12.8f} {second_derivative(sin, x):>14.8f} {-sin(x):>12.8f}")

print("\ny'' = -y: acceleration proportional to displacement, pointing back.")
print("that is a mass on a spring, a pendulum, and an LC circuit.")

Worked example

Differentiate y = x^2\tan(3x) and find the slope at x = 0.

Top level is a product, so product rule leads; the chain rule handles \tan(3x).

\frac{d}{dx}\tan(3x) = \sec^2(3x)\cdot3 = 3\sec^2(3x)

y' = 2x\tan(3x) + x^2\cdot3\sec^2(3x) = 2x\tan(3x) + 3x^2\sec^2(3x)

At x = 0: \tan 0 = 0 and the second term has a factor x^2 = 0, so y'(0) = 0.

Is that right? Near 0, \tan(3x) \approx 3x, so y \approx 3x^3 — a cubic, which is flat at the origin ✓. It also has an inflection there rather than an extremum, which §3.5 would confirm from the sign of y''.

Where does this break down? \tan(3x) blows up when 3x = \frac\pi2 + k\pi, i.e. x = \frac\pi6 + \frac{k\pi}{3}. The derivative formula inherits those same excluded points through \sec^2, which is correct — the function has vertical asymptotes there and no slope.

Your turn

1. \dfrac{d}{dx}\left[\sin x\cos x\right] — two ways.

2. \dfrac{d}{dx}\dfrac{\sin x}{1+\cos x}

3. \dfrac{d}{dx}\sec(x^2+1)

4. Find the 50th derivative of \cos x.

Solutions

1. Product rule.

\cos x\cos x + \sin x(-\sin x) = \cos^2x - \sin^2 x

Double-angle first. \sin x\cos x = \frac12\sin 2x, so the derivative is \frac12\cdot2\cos 2x = \cos 2x.

Both are right, and they agree: \cos 2x = \cos^2x - \sin^2x is exactly the double-angle identity from §0.4. Simplifying first gave a tidier answer with less work — the recurring lesson.

2. Quotient rule:

\frac{\cos x(1+\cos x) - \sin x(-\sin x)}{(1+\cos x)^2} = \frac{\cos x + \cos^2 x + \sin^2 x}{(1+\cos x)^2}

The Pythagorean identity collapses two of those terms:

= \frac{\cos x + 1}{(1+\cos x)^2} = \boxed{\frac{1}{1+\cos x}}

A remarkably clean answer, and worth noticing: the original function is \tan(x/2) in disguise (a half-angle identity), and $\frac{1}{1+\cos x} = \frac12\sec^2(x/2)$ is exactly \frac12\cdot the tangent derivative — consistent with the chain rule on \tan(x/2) ✓.

3. Chain rule, outer \sec:

\sec(x^2+1)\tan(x^2+1)\cdot 2x = \boxed{2x\sec(x^2+1)\tan(x^2+1)}

4. Cosine cycles with period 4 as well:

\cos \to -\sin \to -\cos \to \sin \to \cos

50 \bmod 4 = 2, so two steps in: \boxed{-\cos x}.

Check with a small case: the 2nd derivative of \cos x is -\cos x ✓, and \cos satisfies y'' = -y just as sine does — both solve simple harmonic motion, differing only in phase.

Check yourself in code

Verify all six trigonometric derivative formulas at x = 0.7.

For each of \sin, \cos, \tan, \csc, \sec, \cot, print the formula's value and the central difference (h = 10^{-6}), both to 8 decimals, plus whether they agree to within 10^{-5}.

Print exactly this:

sin     0.76484219      0.76484219  True
cos    -0.64421769     -0.64421769  True
tan     1.70944972      1.70944972  True
csc    -1.84292027     -1.84292027  True
sec     1.10125774      1.10125774  True
cot    -2.40954317     -2.40954317  True
from math import sin, cos, tan

def numerical(f, x, h=1e-6):
    return (f(x + h) - f(x - h)) / (2 * h)

sec = lambda x: 1 / cos(x)
csc = lambda x: 1 / sin(x)
cot = lambda x: cos(x) / sin(x)

table = [
    ("sin", sin, lambda x: cos(x)),
    ("cos", cos, lambda x: -sin(x)),
    ("tan", tan, lambda x: sec(x)**2),
    ("csc", csc, lambda x: -csc(x)*cot(x)),
    ("sec", sec, lambda x: sec(x)*tan(x)),
    ("cot", cot, lambda x: -csc(x)**2),
]
x = 0.7

for name, f, df in table:
    # print the rule value, the numerical value, and whether they match
    print(f"{name:<6} ...")
from math import sin, cos, tan

def numerical(f, x, h=1e-6):
    return (f(x + h) - f(x - h)) / (2 * h)

sec = lambda x: 1 / cos(x)
csc = lambda x: 1 / sin(x)
cot = lambda x: cos(x) / sin(x)

table = [
    ("sin", sin, lambda x: cos(x)),
    ("cos", cos, lambda x: -sin(x)),
    ("tan", tan, lambda x: sec(x)**2),
    ("csc", csc, lambda x: -csc(x)*cot(x)),
    ("sec", sec, lambda x: sec(x)*tan(x)),
    ("cot", cot, lambda x: -csc(x)**2),
]
x = 0.7

for name, f, df in table:
    r, n = df(x), numerical(f, x)
    print(f"{name:<6} {r:>11.8f} {n:>15.8f}  {abs(r - n) < 1e-5}")

\frac{d}{dx}\sin x = \cos x falls out of the angle-sum identity plus the two limits from §1.4 and §1.5, and everything else follows: cosine by the same argument, the other four by the quotient rule, and the "co-" functions all carrying a minus sign. Four derivatives of sine returns you to sine, and the two-step version y'' = -y is simple harmonic motion — the reason these functions describe every oscillation in physics.

Next: e^x, \ln x, and a technique that turns products into sums before you differentiate them.