TExcelTAD
Home › Calculus in Depth › Linear Approximations and Differentials

Linear Approximations and Differentials

Near a point where a function is differentiable, its graph looks almost like its tangent line. Replacing the function by that line is the linear approximation, and the differential dy=f′(x)⋅dxdy = f'(x) \cdot dx is the same idea written for small changes. This lesson defines both, bounds the error, and uses them to propagate measurement errors.

For a first look see The Derivative and Approximation Error.

The tangent line approximation

The linearization of ff at aa is the tangent line

L(x)=f(a)+f′(a)(x−a)L(x) = f(a) + f'(a)(x - a)

and the linear approximation is f(x)≈L(x)f(x) \approx L(x) for xx near aa. It is the best linear fit in a precise sense: the error E(x)=f(x)−L(x)E(x) = f(x) - L(x) satisfies

E(x)x−a→0as x→a\frac{E(x)}{x - a} \to 0 \quad \text{as } x \to a

which is just a rewrite of the definition of f′(a)f'(a). No other line through (a,f(a))(a, f(a)) has that property, because any other slope mm gives E(x)/(x−a)→f′(a)−m≠0E(x)/(x - a) \to f'(a) - m \ne 0.

Classic linearizations at a=0a = 0, used constantly in physics and numerics:

Function Linearization at 0
sin⁡x\sin x xx
tan⁡x\tan x xx
cos⁡x\cos x 11 (the next term is −x2/2-x^2/2)
exe^x 1+x1 + x
ln⁡(1+x)\ln(1 + x) xx
(1+x)k(1 + x)^k 1+kx1 + kx
1+x\sqrt{1 + x} 1+x/21 + x/2

How big is the error?

If f′′f'' exists and ∣f′′(t)∣≤M\lvert f''(t) \rvert \le M for all tt between aa and xx, then

∣f(x)−L(x)∣≤M2⋅(x−a)2\lvert f(x) - L(x) \rvert \le \frac{M}{2} \cdot (x - a)^2

This is the n=1n = 1 case of Taylor's inequality, proved in Taylor and Maclaurin Series. The key message: the error is quadratic in the distance. Halve the step, quarter the error.

python · try it yourself
import math

a = 4.0                         # linearize sqrt at 4
L = lambda x: 2 + (x - a) / 4   # f(4) = 2, f'(4) = 1/4
M = 1 / (4 * 3.5**1.5)          # max |f''| = 1/(4 t^(3/2)) on [3.5, 4.5]
for dx in [0.5, 0.25, 0.125]:
    x = a + dx
    err = math.sqrt(x) - L(x)
    print(f"dx = {dx:<5}  sqrt = {math.sqrt(x):.6f}  L = {L(x):.6f}  "
          f"error = {err:.2e}  bound = {M / 2 * dx**2:.2e}")
dx = 0.5    sqrt = 2.121320  L = 2.125000  error = -3.68e-03  bound = 4.77e-03
dx = 0.25   sqrt = 2.061553  L = 2.062500  error = -9.47e-04  bound = 1.19e-03
dx = 0.125  sqrt = 2.031010  L = 2.031250  error = -2.40e-04  bound = 2.98e-04

The error falls by roughly a factor 4 each time dxdx halves, and it stays below the bound. It is negative because x\sqrt{x} is concave: the tangent lies above the graph.

Differentials

Let dxdx be an independent variable (any real number) and define the differential

dy=f′(x)⋅dxdy = f'(x) \cdot dx

Then Δy=f(x+dx)−f(x)\Delta y = f(x + dx) - f(x) is the actual change of yy, and dydy is the change along the tangent line. For small dxdx, Δy≈dy\Delta y \approx dy. The notation dydx\frac{dy}{dx} becomes an honest quotient of two differentials.

python · try it yourself
import sympy as sp

x, dx = sp.symbols('x dx')
f = x**3 - 2*x
dy = sp.diff(f, x) * dx
Dy = sp.expand(f.subs(x, x + dx) - f)
print("dy     =", dy)
print("Δy     =", Dy)
print("Δy − dy =", sp.factor(sp.expand(Dy - dy)))
h = sp.Rational(1, 20)
print("at x = 2, dx = 1/20:  Δy =", Dy.subs({x: 2, dx: h}), "=", float(Dy.subs({x: 2, dx: h})), " dy =", dy.subs({x: 2, dx: h}))
dy     = dx*(3*x**2 - 2)
Δy     = dx**3 + 3*dx**2*x + 3*dx*x**2 - 2*dx
Δy − dy = dx**2*(dx + 3*x)
at x = 2, dx = 1/20:  Δy = 4121/8000 = 0.515125  dy = 1/2

The gap Δy−dy\Delta y - dy contains only dx2dx^2 and dx3dx^3 terms: it vanishes faster than dxdx.

Propagating measurement error

If you measure xx with possible error Δx\Delta x and compute y=f(x)y = f(x), the propagated error is about dy=f′(x)⋅Δxdy = f'(x) \cdot \Delta x. The relative error dy/ydy/y is often more meaningful. For power laws there is a neat rule:

y=c⋅xn  ⟹  dyy=n⋅dxxy = c \cdot x^n \quad\implies\quad \frac{dy}{y} = n \cdot \frac{dx}{x}

So a 1 % error in a radius gives about a 3 % error in the volume of a sphere.

Note: For products and quotients, relative errors (to first order) add: d(uv)uv=duu+dvv\frac{d(uv)}{uv} = \frac{du}{u} + \frac{dv}{v}. That is the logarithmic derivative from Derivatives of Logarithmic Functions in disguise.

In software

  • Newton's method replaces ff by its linearization and solves L(x)=0L(x) = 0; see Newton's Method.
  • Small-angle approximations sin⁡θ≈θ\sin\theta \approx \theta, cos⁡θ≈1\cos\theta \approx 1 keep game and robotics code cheap for small rotations; quaternion integration uses q(1+12ω dt)q(1 + \tfrac{1}{2}\omega\, dt).
  • Floating-point error analysis: the condition number of ff at xx is ∣xf′(x)/f(x)∣\lvert x f'(x) / f(x) \rvert, the factor by which a relative input error is amplified. It comes straight from differentials.
  • Machine learning: gradient descent assumes the loss is close to its linearization for a small enough step, which is why too large a learning rate diverges. Neural-network quantization error is estimated with the same first-order rule.
  • Jacobians: in many variables the linearization becomes f(a)+J(a)(x−a)f(a) + J(a)(x - a), the basis of extended Kalman filters in sensor fusion.

Exercises

Exercise 1: Cube root

Use the linearization of x3\sqrt[3]{x} at 27 to estimate 283\sqrt[3]{28}.

Answer

3+1/27≈3.03703 + 1/27 \approx 3.0370 (true value 3.0366)

Solution
f(x)=x1/3,f′(x)=13x−2/3,f′(27)=127L(28)=3+127(1)≈3.03704\begin{aligned} &f(x) = x^{1/3}, \quad f'(x) = \tfrac{1}{3}x^{-2/3}, \quad f'(27) = \tfrac{1}{27} \\ &L(28) = 3 + \tfrac{1}{27}(1) \approx 3.03704 \end{aligned}

Exercise 2: Error bound

Bound the error of sin⁡x≈x\sin x \approx x for ∣x∣≤0.1\lvert x \rvert \le 0.1 using ∣f′′∣≤M\lvert f'' \rvert \le M.

Answer

∣error∣≤0.0005\lvert \text{error} \rvert \le 0.0005 (the true error is even smaller, at most about 0.0001670.000167).

Solution
f′′(x)=−sin⁡x,∣f′′∣≤sin⁡0.1<0.1=M∣error∣≤M2⋅x2≤0.05⋅0.01=0.0005\begin{aligned} &f''(x) = -\sin x, \quad \lvert f'' \rvert \le \sin 0.1 < 0.1 = M \\ &\lvert \text{error} \rvert \le \tfrac{M}{2} \cdot x^2 \le 0.05 \cdot 0.01 = 0.0005 \end{aligned}

Even the crude bound M=1M = 1 gives 0.0050.005. The real error is x−sin⁡x≈x3/6≤0.000167x - \sin x \approx x^3/6 \le 0.000167, because the linearization of sin⁡\sin at 0 is also its quadratic approximation.

Exercise 3: Sphere volume

A sphere's radius is measured as 10 cm with a maximum error of 0.05 cm. Estimate the maximum error in the computed volume and the relative error.

Answer

dV=20π≈62.83 cm3dV = 20\pi \approx 62.83\ \text{cm}^3; relative error 1.5%1.5\%.

Solution
V=43πr3,dV=4πr2⋅dr=4π⋅100⋅0.05=20π≈62.83 cm3dV/V=3⋅dr/r=3⋅0.005=0.015\begin{aligned} &V = \tfrac{4}{3}\pi r^3, \quad dV = 4\pi r^2 \cdot dr = 4\pi \cdot 100 \cdot 0.05 = 20\pi \approx 62.83\ \text{cm}^3 \\ &dV/V = 3 \cdot dr/r = 3 \cdot 0.005 = 0.015 \end{aligned}
python · try it yourself
import math

r, dr = 10, 0.05
V = 4 / 3 * math.pi * r**3
dV = 4 * math.pi * r**2 * dr
true = 4 / 3 * math.pi * (r + dr)**3 - V
print(f"dV = {dV:.4f}, actual ΔV = {true:.4f}, relative = {dV / V:.4f}")
dV = 62.8319, actual ΔV = 63.1465, relative = 0.0150

Exercise 4: Condition number

Compute the condition number ∣xf′(x)/f(x)∣\lvert x f'(x)/f(x) \rvert of f(x)=ln⁡xf(x) = \ln x at x=1.001x = 1.001. What does it say about computing ln⁡x\ln x for xx near 1?

Answer

About 1000.5: a relative input error is amplified about a thousand times.

Solution
x⋅f′(x)/f(x)=x⋅(1/x)/ln⁡x=1/ln⁡x=1/ln⁡(1.001)≈1000.5x \cdot f'(x)/f(x) = x \cdot (1/x)/\ln x = 1/\ln x = 1/\ln(1.001) \approx 1000.5

This is why libraries offer log1p⁡(u)=ln⁡(1+u)\operatorname{log1p}(u) = \ln(1 + u), which takes the small uu directly and avoids forming 1+u1 + u.

Test yourself

What is the linearization of exe^x at a=0a = 0?

  1. xx
  2. 1+x1 + x
  3. e⋅xe \cdot x
  4. 1+x+x2/21 + x + x^2/2

If ∣f′′∣≤M\lvert f'' \rvert \le M near aa, how does the linear approximation error scale with the distance x−ax - a?

  1. Linearly
  2. It is constant
  3. Quadratically
  4. Exponentially

A cube's side has a 2 % measurement error. About what relative error does the computed volume have?

  1. 2 %
  2. 6 %
  3. 8 %
  4. 4 %