Fields, Seen Through Local Derivatives · Chapter 1
The Jacobian and the gradient: the derivative as a local linear map
Extend the one-variable derivative to several variables and it turns from a number into a matrix, the Jacobian; the transpose of a scalar field's Jacobian is the gradient. This chapter derives why the gradient points uphill fastest and is normal to level sets, and works out the Jacobians of camera projection and pose optimization.
Series contentsChapter 1 of 3
Series
Fields, Seen Through Local Derivatives- 01The Jacobian and the gradient: the derivative as a local linear map
- 02Divergence and curl: what they extract from the Jacobian
- 03Hessian, Laplacian and Poisson reconstruction
The question
What kind of object is the “derivative” of a multivariable function? Why is the derivative of a scalar field a vector, while the derivative of a vector field is a matrix?
This looks like a question about notation, but it fixes the place of every later operator. Divergence, curl, the Hessian and the Laplacian are all obtained from one object, the Jacobian matrix. This chapter makes that object precise.
Intuition
The derivative of a one-variable function answers: if the input changes a little, how much does the output change? Zoom in on the graph near a point and the curve looks like a line; the derivative is its slope.
The multivariable case is the same, except that the slope becomes a matrix. Zoom in on a map near a point and the curved map looks like a linear transformation: a tiny square goes to a tiny parallelogram. The matrix of that linear transformation is the Jacobian at that point.
Each column of the Jacobian answers “how do all outputs change when I move along one input direction?”. Each row answers “how sensitive is one output component to every input direction?”.
A scalar field has one output, so its Jacobian is a single row. Stand that row up as a column vector and you have the gradient.
Formalism
From the derivative to the Jacobian
The first-order expansion of a one-variable function near is
A map is differentiable at if there is a matrix with
and is its Jacobian. Setting and letting reads off each entry:
The Jacobian has shape “output dimension × input dimension” and need not be square. Only when does its determinant, the local volume scaling factor, make sense.
The chain rule is matrix multiplication
Let and . A small change in gives , and then . Hence
The local linear approximation of a composition is the product of the local linear approximations. The long derivative chains of robotics, such as “pose → 3D point → pixel → residual”, are this formula applied repeatedly.
The gradient is the transposed Jacobian of a scalar field
For a scalar field , the Jacobian is a row. The gradient is defined as its transpose:
The first-order expansion then reads , and the directional derivative along a unit vector is
Why the gradient points uphill fastest
By the Cauchy–Schwarz inequality (see Inner products, covariance and correlation), for every unit vector ,
with equality exactly when points along . Wherever , the direction gives the fastest increase, at rate , and the opposite direction the fastest decrease. This is what justifies gradient descent.
For example, has . At the steepest ascent is along the unit vector of , not along the position vector . The function is steeper in some coordinates than others, and the gradient leans towards the steeper ones.
The gradient is normal to level sets
Let be any smooth curve in the level set with . Since for all , differentiating with the chain rule gives
can be any tangent vector of the level set at , so is orthogonal to the whole tangent plane: the gradient is the normal of the level set.
An inner product sits between the derivative and the gradient
Strictly speaking, the derivative is a linear function: it takes a direction and returns the rate of change . The gradient is the vector that represents this linear function through an inner product: for every .
With Cartesian coordinates and the standard inner product the two have identical components, so this step is easy to overlook. With a general inner product ( symmetric positive definite), the gradient becomes , no longer the vector of partial derivatives. Gradient formulas in curvilinear coordinates and on manifolds all stem from this.
In robotics
The Jacobian of camera projection
For an undistorted pinhole camera, a point in the camera frame () projects to the pixel
Differentiating term by term gives , , , and likewise for :
This matrix predicts how far a pixel moves when the 3D point moves slightly. Two things can be read straight off it:
- every entry carries a , so the same 3D displacement moves near points further in the image;
- the third column describes motion along the optical axis, which moves the image point along the ray from the principal point. Chapter 2 uses this when deriving the divergence of optical flow.
Normals of implicit surfaces
If a surface is the zero set of an implicit function, the level-set result gives the unit normal at smooth points with :
For an exact Euclidean signed distance function (SDF), in smooth regions (the Eikonal equation), so the gradient itself is the unit normal.
A truncated SDF (TSDF) fused from RGB-D data, however, usually stores a projective distance along the viewing ray, together with noise, interpolation error and truncation. It cannot be treated as an exact SDF everywhere; gradient-based normals should be computed only in well-observed voxels near the surface.
The gradient in pose optimization
Let a residual vector depend on local pose parameters , with objective . The chain rule gives
is and the gradient is . Gauss–Newton approximates the Hessian by and solves at each step; Chapter 3 shows where this approximation comes from.
The variable here is the local pose parameter, not a 3D world coordinate. The Jacobian with respect to a six-dimensional pose also depends on whether perturbations are applied on the left or the right, and formulas from different conventions must not be mixed. The Jacobians and gradients of ICP, RGB-D odometry and bundle adjustment all belong to this language.
Experiment
The script checks four things in turn: the projection Jacobian from SymPy; agreement with finite differences; the least-squares gradient equal to ; and the unit gradient norm of an SDF.
import numpy as np
import sympy as sp
# 1. Jacobian of pinhole projection (symbolic)
X, Y, Z, fx, fy, cx, cy = sp.symbols("X Y Z f_x f_y c_x c_y", positive=True)
proj = sp.Matrix([fx * X / Z + cx, fy * Y / Z + cy])
J_sym = proj.jacobian([X, Y, Z])
sp.pprint(J_sym)
# 2. compare with central differences
J_fn = sp.lambdify((X, Y, Z, fx, fy), J_sym)
p_fn = sp.lambdify((X, Y, Z, fx, fy, cx, cy), proj)
P0 = np.array([0.4, -0.2, 3.0])
intr = (500.0, 500.0, 320.0, 240.0)
eps = 1e-6
J_num = np.zeros((2, 3))
for j in range(3):
d = np.zeros(3); d[j] = eps
J_num[:, j] = ((p_fn(*(P0 + d), *intr) - p_fn(*(P0 - d), *intr)) / (2 * eps)).ravel()
print(np.abs(J_num - np.array(J_fn(*P0, 500.0, 500.0))).max()) # about 1e-8
# 3. least squares: grad E = J^T r, for R^6 -> R^100
rng = np.random.default_rng(0)
A = rng.standard_normal((100, 6))
b = rng.standard_normal(100)
r = lambda xi: np.sin(A @ xi) - b
J_r = lambda xi: np.cos(A @ xi)[:, None] * A
E = lambda xi: 0.5 * r(xi) @ r(xi)
xi0 = rng.standard_normal(6)
g_analytic = J_r(xi0).T @ r(xi0)
g_numeric = np.array([(E(xi0 + eps * e) - E(xi0 - eps * e)) / (2 * eps) for e in np.eye(6)])
print(J_r(xi0).shape, g_analytic.shape, np.abs(g_analytic - g_numeric).max())
# (100, 6) (6,) about 1e-8
# 4. SDF of the unit sphere: f(p) = |p| - 1, gradient p/|p| always has norm 1
p = rng.standard_normal((5, 3))
grad = p / np.linalg.norm(p, axis=1, keepdims=True)
print(np.linalg.norm(grad, axis=1)) # [1. 1. 1. 1. 1.]
References
- Hartley, R., & Zisserman, A. (2004). Multiple View Geometry in Computer Vision (2nd ed.). Cambridge University Press.
- Barfoot, T. D. (2017). State Estimation for Robotics. Cambridge University Press.
- Strang, G. (2016). Introduction to Linear Algebra (5th ed.). Wellesley-Cambridge Press.
- OpenStax. Calculus Volume 3, Chapter 4 (Differentiation of Functions of Several Variables). https://openstax.org/details/books/calculus-volume-3
- Khan Academy. Derivatives of multivariable functions (videos on the Jacobian matrix and the gradient). https://www.khanacademy.org/math/multivariable-calculus/multivariable-derivatives