Tangent Planes and Linear Approximations
Zoom in far enough on a smooth surface and it looks flat: it becomes its tangent plane. The tangent plane gives the best linear approximation of a function of several variables, and that linearisation is the workhorse behind error propagation, Newton-type solvers and every first-order optimiser. This lesson defines differentiability properly, shows that partial derivatives alone are not enough, and proves when they are.
The one-variable version is Linear Approximations and Differentials.
The tangent plane
Suppose has continuous partial derivatives near . The tangent plane to at is
Why this plane: it passes through , and its traces in the planes and are lines with slopes and , the tangent lines of the two partial-derivative traces. A normal vector is .
Example: at , where , , :
Linearisation
The linear function whose graph is the tangent plane is the linearisation of at :
In vector form, with and a small step , . This is the first-order Taylor polynomial in two variables; adding the second-order (Hessian) term gives the quadratic approximation used in the second-derivative test.
import numpy as np
f = lambda x, y: np.sqrt(x**2 + 3 * y**2)
a, b = 2.0, 1.0
fa = f(a, b) # √7
fx, fy = a / fa, 3 * b / fa
L = lambda x, y: fa + fx * (x - a) + fy * (y - b)
print(f"f(2,1) = {fa:.6f}, f_x = {fx:.6f}, f_y = {fy:.6f}")
for d in [0.5, 0.1, 0.01, 0.001]:
x, y = a + d, b - d
err = abs(f(x, y) - L(x, y))
dist = np.hypot(d, d)
print(f"step {d:<6} error {err:.3e} error/dist {err / dist:.3e}")f(2,1) = 2.645751, f_x = 0.755929, f_y = 1.133893
step 0.5 error 1.890e-01 error/dist 2.673e-01
step 0.1 error 7.385e-03 error/dist 5.222e-02
step 0.01 error 7.300e-05 error/dist 5.162e-03
step 0.001 error 7.290e-07 error/dist 5.155e-04
The error divided by the distance of the step goes to 0: that ratio is exactly what differentiability demands.
Differentiability
In one variable, "the derivative exists" already means "the tangent line approximates well". In two variables, partial derivatives only look along two lines, so we need a stronger definition.
Definition. is differentiable at if , exist and
where as . Equivalently, .
Partials can exist without differentiability. Take with . On both axes , so and the candidate tangent plane is . But along , everywhere except the origin: is not even continuous at , let alone approximated by . A differentiable function is always continuous (let in the definition), so is not differentiable.
Theorem. If and exist near and are continuous at , then is differentiable at .
Proof sketch. Go from to in two legs: first change , then . On each leg apply the one-variable Mean Value Theorem:
Set and . Both points tend to , so continuity of the partials gives .
This is why, in practice, we check that the partial derivatives are continuous (true for any expression built from polynomials, exp, sin, ln … on their domains) and then use the tangent plane freely.
Differentials
Write , for independent increments. The total differential is
It is the change in the linearisation, and approximates the true change . For three variables, .
Error propagation. A cylindrical tank is measured as and , each with error up to . , so
against : a relative error of about 1.6%. Dividing by gives the handy rule : relative errors add, weighted by the exponents.
import numpy as np
V = lambda r, h: np.pi * r**2 * h
r, h, e = 1.5, 4.0, 0.01
dV = 2 * np.pi * r * h * e + np.pi * r**2 * e
worst = max(abs(V(r + s1 * e, h + s2 * e) - V(r, h)) for s1 in (-1, 1) for s2 in (-1, 1))
print(f"V = {V(r, h):.4f} m^3")
print(f"differential bound dV = {dV:.4f} m^3 ({dV / V(r, h):.2%})")
print(f"worst corner, exact = {worst:.4f} m^3")V = 28.2743 m^3
differential bound dV = 0.4477 m^3 (1.58%)
worst corner, exact = 0.4499 m^3
The differential misses the exact worst case only by second-order terms (products of two errors), here about .
Tangent planes to level surfaces
For a surface given implicitly as , the tangent plane at has normal (proved in Directional Derivatives and the Gradient Vector):
The graph is the special case , whose gradient is , matching the normal above.
In software
- First-order optimisers (gradient descent, SGD, Adam) work with the linearisation and pick to decrease it; the learning rate limits to the region where the linear model is trustworthy. See Gradient Descent.
- Gauss–Newton and Kalman filters linearise a nonlinear model around the current estimate using its Jacobian, the matrix of partial derivatives; the extended Kalman filter in robot localisation and GPS is exactly "replace by its tangent plane".
- Uncertainty propagation. Physics, metrology and finance code estimate output error with for independent inputs, the differential with errors combined in quadrature.
- Normals for lighting. A heightmap is shaded with the normal (the same direction as , flipped to point up), estimated from neighbouring samples.
Exercises
Exercise 1: Tangent plane
Find the tangent plane to at .
Answer
(through ).
Solution
Exercise 2: Linear estimate
Use a linearisation of at to estimate , and compare with the true value.
Answer
Estimate 4.988; true value .
Solution
import math
print(round(math.hypot(3.02, 3.97), 6))4.988116
Exercise 3: Relative error
The power dissipated in a resistor is . If is measured with relative error 1% and with 2%, estimate the largest relative error in .
Answer
About 4%.
Solution
Exercise 4: Not differentiable (code)
For (with when ), . Compute for . What does it show?
Answer
The ratios are about 1.52, 3.28, 7.07 and grow without bound, so does not tend to 0: is not differentiable at the origin even though both partials exist.
Solution
The candidate linearisation is , and the step has length , so the ratio .
for t in [0.1, 0.01, 0.001]:
f = (t * t) ** (1 / 3)
print(t, round(f / (2 ** 0.5 * t), 4))0.1 1.5234
0.01 3.2821
0.001 7.0711
Test yourself
The tangent plane to at has which normal vector?
- evaluated anywhere
Which statement is true?
- If and exist at a point, is differentiable there
- If and are continuous near a point, is differentiable there
- Every continuous function is differentiable
- Differentiable functions can be discontinuous
For , a 1% error in and a 1% error in give a relative error in of about…
- 1%
- 2%
- 4%
- 3%