TExcelTAD
Home › Calculus Essentials › Higher Derivatives

Higher Derivatives

The derivative of a function is itself a function, so you can differentiate it again. The second derivative measures how the slope changes: acceleration is the second derivative of position, and curvature of a graph shows up as the sign of f′′f''. Games, animation and physics engines work with position, velocity and acceleration every frame.

Notation

Order Prime notation Leibniz notation Physics name (for position s(t)s(t))
1st f′(x)f'(x) dydx\frac{dy}{dx} velocity vv
2nd f′′(x)f''(x) d2ydx2\frac{d^2y}{dx^2} acceleration aa
3rd f′′′(x)f'''(x) d3ydx3\frac{d^3y}{dx^3} jerk
nth f(n)(x)f^{(n)}(x) dnydxn\frac{d^ny}{dx^n} (4th: snap)

Example with a polynomial: each derivative lowers the degree by one, until it hits zero.

f(x)=x4−3x2+2xf′(x)=4x3−6x+2f′′(x)=12x2−6f′′′(x)=24xf(4)(x)=24f(5)(x)=0\begin{aligned} f(x) &= x^4 - 3x^2 + 2x \\ f'(x) &= 4x^3 - 6x + 2 \\ f''(x) &= 12x^2 - 6 \\ f'''(x) &= 24x \\ f^{(4)}(x) &= 24 \\ f^{(5)}(x) &= 0 \end{aligned}

Some functions never run out: exe^x is its own derivative at every order, and sin⁡x\sin x cycles with period 4.

python · try it yourself
import sympy as sp

x = sp.symbols('x')
f = x**4 - 3 * x**2 + 2 * x
for n in range(1, 6):
    print(f"f^({n}) =", sp.diff(f, x, n))
print("10th derivative of sin(2x):", sp.diff(sp.sin(2 * x), x, 10))
print("3rd derivative of x*exp(x):", sp.factor(sp.diff(x * sp.exp(x), x, 3)))
f^(1) = 4*x**3 - 6*x + 2
f^(2) = 6*(2*x**2 - 1)
f^(3) = 24*x
f^(4) = 24
f^(5) = 0
10th derivative of sin(2x): -1024*sin(2*x)
3rd derivative of x*exp(x): (x + 3)*exp(x)

sp.diff(f, x, n) takes the nn-th derivative directly. Each derivative of sin⁡(2x)\sin(2x) brings out a factor 2, so the 10th has 210=10242^{10} = 1024.

Position, velocity, acceleration

A ball thrown upwards at 15 m/s from 2 m height (gravity 9.8 m/s29.8\ \text{m/s}^2):

s(t)=2+15t−4.9t2position (m)v(t)=s′(t)=15−9.8tvelocity (m/s)a(t)=s′′(t)=−9.8acceleration (m/s2), constant\begin{aligned} s(t) &= 2 + 15t - 4.9t^2 && \text{position (m)} \\ v(t) &= s'(t) = 15 - 9.8t && \text{velocity (m/s)} \\ a(t) &= s''(t) = -9.8 && \text{acceleration (m/s}^2\text{), constant} \end{aligned}

The ball is highest when v=0v = 0, at t=15/9.8≈1.53 st = 15/9.8 \approx 1.53\ \text{s}. The acceleration is negative the whole time, even on the way up: velocity is decreasing throughout.

Numeric evidence: second differences

The second derivative can be estimated from three samples:

f′′(x)≈f(x+h)−2f(x)+f(x−h)h2f''(x) \approx \frac{f(x + h) - 2f(x) + f(x - h)}{h^2}

This is exactly what you do with positions recorded every frame. Here it recovers a=−9.8a = -9.8 from sampled positions:

python · try it yourself
def s(t):
    return 2 + 15 * t - 4.9 * t**2

t0 = 1.0
for h in [0.5, 0.1, 0.01, 0.001]:
    v = (s(t0 + h) - s(t0 - h)) / (2 * h)
    a = (s(t0 + h) - 2 * s(t0) + s(t0 - h)) / h**2
    print(f"h = {h:<6}  v ≈ {v:.6f}   a ≈ {a:.6f}")
for h in [1e-5, 1e-6, 1e-7]:
    a = (s(t0 + h) - 2 * s(t0) + s(t0 - h)) / h**2
    print(f"h = {h:<6}  a ≈ {a:.6f}   (rounding noise / h² takes over)")
h = 0.5     v ≈ 5.200000   a ≈ -9.800000
h = 0.1     v ≈ 5.200000   a ≈ -9.800000
h = 0.01    v ≈ 5.200000   a ≈ -9.800000
h = 0.001   v ≈ 5.200000   a ≈ -9.800000
h = 1e-05   a ≈ -9.799983   (rounding noise / h² takes over)
h = 1e-06   a ≈ -9.803713   (rounding noise / h² takes over)
h = 1e-07   a ≈ -9.414691   (rounding noise / h² takes over)

For a quadratic the formula is exact for any reasonable hh, but notice the bottom rows: dividing by h2h^2 makes the floating-point problem much worse than for first derivatives.

Concavity: what f′′f'' says about shape

Sign of f′′f'' on an interval Shape Picture
f′′>0f'' > 0 concave up holds water, like x2x^2
f′′<0f'' < 0 concave down spills water, like −x2-x^2
sign changes at cc inflection point at cc x3x^3 at 0

This is used in Maxima, Minima and Curve Shape to tell maxima from minima.

In software: velocity and acceleration in games

A game loop stores position and velocity for each object and updates them every frame with the acceleration (from gravity, thrust, springs). The simplest scheme, semi-implicit Euler, is:

text
v ← v + a·dt
x ← x + v·dt

That is "velocity is the derivative of position, acceleration is the derivative of velocity", turned into code with a finite time step.

python · try it yourself
dt, g = 1 / 60, -9.8
y, vy = 2.0, 15.0
t = 0.0
peak = (0.0, y)
while y >= 0:
    vy += g * dt          # acceleration changes velocity
    y += vy * dt          # velocity changes position
    t += dt
    if y > peak[1]:
        peak = (t, y)
print(f"simulated peak:  t = {peak[0]:.3f} s, height = {peak[1]:.3f} m")
print(f"exact peak:      t = {15 / 9.8:.3f} s, height = {2 + 15**2 / (2 * 9.8):.3f} m")
print(f"lands after about {t:.3f} s")
simulated peak:  t = 1.517 s, height = 13.355 m
exact peak:      t = 1.531 s, height = 13.480 m
lands after about 3.183 s

The small differences come from the finite step dtdt; how to shrink them is the topic of Numerical Solutions: Euler and RK4 and of integrators in game physics.

  • Jerk (3rd derivative) matters for comfort: camera rigs, elevators and robot arms use motion profiles with limited jerk so that acceleration does not change abruptly. Cubic and quintic easing curves are chosen for smooth higher derivatives (easing curves).
  • Second-order optimisation: Newton-type optimisers use the second derivative (the Hessian in many dimensions, Jacobian and Hessian) to choose step sizes.

Exercises

Exercise 1: Keep differentiating

Find f′′(x)f''(x) and f′′′(x)f'''(x) for f(x)=2x5−x3+4f(x) = 2x^5 - x^3 + 4.

Answer

f′′(x)=40x3−6xf''(x) = 40x^3 - 6x, f′′′(x)=120x2−6f'''(x) = 120x^2 - 6

Solution
f′=10x4−3x2f′′=40x3−6xf′′′=120x2−6\begin{aligned} f' &= 10x^4 - 3x^2 \\ f'' &= 40x^3 - 6x \\ f''' &= 120x^2 - 6 \end{aligned}

Exercise 2: Second derivative of a bell curve

Find g′′(x)g''(x) for g(x)=e−x2g(x) = e^{-x^2}.

Answer

g′′(x)=(4x2−2)e−x2g''(x) = (4x^2 - 2) e^{-x^2}

Solution
g′=−2xe−x2g′′=−2e−x2+(−2x)(−2x)e−x2=(4x2−2)e−x2\begin{aligned} g' &= -2x e^{-x^2} \\ g'' &= -2 e^{-x^2} + (-2x)(-2x) e^{-x^2} = (4x^2 - 2) e^{-x^2} \end{aligned}

So the bell curve changes concavity where 4x2=24x^2 = 2, at x=±1/2x = \pm 1/\sqrt{2}.

Exercise 3: A car braking

A car's position is s(t)=20t−t2s(t) = 20t - t^2 metres for 0≤t≤100 \le t \le 10. When does it stop, how far has it gone, and what is its acceleration?

Answer

Stops at t=10 st = 10\ \text{s} after 100 m100\ \text{m}; acceleration −2 m/s2-2\ \text{m/s}^2 throughout.

Solution
v=20−2t=0  ⟹  t=10s(10)=200−100=100 ma=v′=−2 m/s2\begin{aligned} v &= 20 - 2t = 0 \implies t = 10 \\ s(10) &= 200 - 100 = 100\ \text{m} \\ a &= v' = -2\ \text{m/s}^2 \end{aligned}

Exercise 4: Acceleration from recorded frames

These heights were logged every 0.1 s0.1\ \text{s}: [10.0, 10.951, 11.804, 12.559, 13.216]. Estimate the acceleration at each interior frame with the second-difference formula.

Answer

About −9.8 m/s2-9.8\ \text{m/s}^2 at every interior frame.

Solution
python · try it yourself
ys = [10.0, 10.951, 11.804, 12.559, 13.216]
dt = 0.1
for i in range(1, len(ys) - 1):
    a = (ys[i + 1] - 2 * ys[i] + ys[i - 1]) / dt**2
    print(f"frame {i}: a ≈ {a:.2f}")
frame 1: a ≈ -9.80
frame 2: a ≈ -9.80
frame 3: a ≈ -9.80

Test yourself

If s(t)s(t) is position, what is s′′(t)s''(t)?

  1. Velocity
  2. Jerk
  3. Acceleration
  4. Distance travelled

What is the 4th derivative of cos⁡x\cos x?

  1. sin⁡x\sin x
  2. −cos⁡x-\cos x
  3. cos⁡x\cos x
  4. −sin⁡x-\sin x

f′′(x)>0f''(x) > 0 on an interval means the graph is …

  1. increasing
  2. concave up
  3. concave down
  4. linear