Derivatives of Trig Functions
Sine and cosine describe anything that repeats: waves, rotations, oscillating springs, sound. Their derivatives turn out to be each other (up to a sign), which is why circular motion and vibration are so neat to analyse. All six trig derivatives follow from one limit and the rules you already know.
The two key limits
With angles in radians,
Using :
A similar calculation gives . Everything else comes from the quotient rule.
The table
| Function | Derivative |
|---|---|
A memory aid: the "co-" functions get a minus sign. Differentiating four times brings you back to : .
Numeric evidence and SymPy
import math
print(" x numeric d/dx sin cos x")
h = 1e-5
for x in [0, math.pi / 6, math.pi / 2, 2.0, math.pi]:
numeric = (math.sin(x + h) - math.sin(x - h)) / (2 * h)
print(f"{x:6.4f} {numeric:16.10f} {math.cos(x):13.10f}") x numeric d/dx sin cos x
0.0000 1.0000000000 1.0000000000
0.5236 0.8660254038 0.8660254038
1.5708 0.0000000000 0.0000000000
2.0000 -0.4161468365 -0.4161468365
3.1416 -1.0000000000 -1.0000000000
import sympy as sp
x = sp.symbols('x')
for f in [sp.tan(x), sp.sec(x), sp.atan(x), sp.sin(3 * x) * sp.cos(x), sp.sin(x)**2 + sp.cos(x)**2]:
print(f"d/dx {str(f):<20} = {sp.simplify(sp.diff(f, x))}")d/dx tan(x) = cos(x)**(-2)
d/dx sec(x) = tan(x)*sec(x)
d/dx atan(x) = 1/(x**2 + 1)
d/dx sin(3*x)*cos(x) = cos(2*x) + 2*cos(4*x)
d/dx sin(x)**2 + cos(x)**2 = 0
The last line is a nice sanity check: is constant, so its derivative is 0. SymPy prints the derivative of as cos(x)**(-2), which is ; another equivalent form is .
Why radians?
The limit holds only when is measured in radians. In degrees, , so . Every calculus formula with trig assumes radians, and so do math.sin, np.sin and the trig functions in every game engine.
import math
h = 1e-6
deg_slope = (math.sin(math.radians(30 + h)) - math.sin(math.radians(30 - h))) / (2 * h)
print("slope of sin in degrees at 30°:", round(deg_slope, 8))
print("(π/180)·cos(30°) :", round(math.pi / 180 * math.cos(math.radians(30)), 8))slope of sin in degrees at 30°: 0.01511499
(π/180)·cos(30°) : 0.01511499
Chain rule with trig
The inner derivative becomes a frequency factor:
A wave with angular frequency has velocity amplitude : doubling the frequency doubles the peak speed.
In software
- Circular motion: a point orbiting at radius with angular speed sits at . Its velocity is perpendicular to the radius, with speed . See Curvilinear Motion and radians and trig.
- Oscillation in games and audio: a bobbing pickup has its fastest motion at the middle and stops at the top and bottom, because is 0 exactly where peaks. Synthesizers and spring systems (springs) rely on .
- Positional encodings: transformer models encode token positions with sines and cosines of many frequencies (transformers). Thanks to the angle-addition formulas (the same ones used above to differentiate ), shifting the position is just a rotation of each pair.
Exercises
Exercise 1: Product of trig functions
Differentiate .
Answer
Solution
Exercise 2: Derive tan from the quotient rule
Show that .
Answer
Solution
Exercise 3: Peak speed of a bob
A floating pickup moves as (metres, seconds). What is its maximum vertical speed, and at what height does it occur?
Answer
, at the middle height .
Solution
Exercise 4: Check arctan's derivative
Check numerically that the derivative of at is , and with SymPy.
Answer
Both give 0.2 (SymPy: 1/5).
Solution
import math
import sympy as sp
h = 1e-5
print(round((math.atan(2 + h) - math.atan(2 - h)) / (2 * h), 8))
x = sp.symbols('x')
print(sp.diff(sp.atan(x), x).subs(x, 2))0.2
1/5
Test yourself
What is ?
What is ?
Why must be in radians for ?
- Degrees are not allowed in Python
- Because only holds with in radians
- Radians are always larger
- It works in degrees too