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 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 at is the tangent line
and the linear approximation is for near . It is the best linear fit in a precise sense: the error satisfies
which is just a rewrite of the definition of . No other line through has that property, because any other slope gives .
Classic linearizations at , used constantly in physics and numerics:
| Function | Linearization at 0 |
|---|---|
| (the next term is ) | |
How big is the error?
If exists and for all between and , then
This is the 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.
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 halves, and it stays below the bound. It is negative because is concave: the tangent lies above the graph.
Differentials
Let be an independent variable (any real number) and define the differential
Then is the actual change of , and is the change along the tangent line. For small , . The notation becomes an honest quotient of two differentials.
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 contains only and terms: it vanishes faster than .
Propagating measurement error
If you measure with possible error and compute , the propagated error is about . The relative error is often more meaningful. For power laws there is a neat rule:
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: . That is the logarithmic derivative from Derivatives of Logarithmic Functions in disguise.
In software
- Newton's method replaces by its linearization and solves ; see Newton's Method.
- Small-angle approximations , keep game and robotics code cheap for small rotations; quaternion integration uses .
- Floating-point error analysis: the condition number of at is , 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 , the basis of extended Kalman filters in sensor fusion.
Exercises
Exercise 1: Cube root
Use the linearization of at 27 to estimate .
Answer
(true value 3.0366)
Solution
Exercise 2: Error bound
Bound the error of for using .
Answer
(the true error is even smaller, at most about ).
Solution
Even the crude bound gives . The real error is , because the linearization of 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
; relative error .
Solution
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 of at . What does it say about computing for near 1?
Answer
About 1000.5: a relative input error is amplified about a thousand times.
Solution
This is why libraries offer , which takes the small directly and avoids forming .
Test yourself
What is the linearization of at ?
If near , how does the linear approximation error scale with the distance ?
- Linearly
- It is constant
- Quadratically
- Exponentially
A cube's side has a 2 % measurement error. About what relative error does the computed volume have?
- 2 %
- 6 %
- 8 %
- 4 %