Basic Calculus
SLAM back-ends spend most of their time minimizing nonlinear cost functions. Two tools from calculus make that possible: differentiation (Jacobians) and Taylor expansion (linearization).
Differentiation and Jacobians
A scalar function has a gradient . A vector function has a Jacobian matrix:
The Jacobian is the key tool in SLAM optimization: given a residual (for example, a reprojection error), its Jacobian tells us how the residual changes with small perturbations to the state — exactly what Gauss-Newton and Levenberg-Marquardt need.
The chain rule in SLAM residuals
SLAM residuals are almost always compositions of simpler functions, so their Jacobians come from the chain rule. The reprojection error of a map point observed at pixel under pose is
a composition of (1) a rigid transformation, (2) perspective division, and (3) the intrinsic mapping. Its Jacobian factors into a product:
where is the point in the camera frame. Deriving each factor separately and multiplying is far less error-prone than differentiating the whole expression at once — and it is exactly how SLAM libraries structure their analytic Jacobians.
Taylor Expansion
The Taylor series expands a smooth function around a point :
For a multivariate function around :
where is the Jacobian (first order) and is the Hessian matrix (second order). Truncating at first order gives the linear approximation used in Gauss-Newton; truncating at second order gives the quadratic approximation used in Newton’s method.
From Taylor expansion to Gauss-Newton
Consider minimizing a sum of squared residuals . Linearize the residual around the current estimate, , and substitute:
This is a quadratic in ; setting its derivative to zero gives the normal equations:
Gauss-Newton is therefore “Newton’s method with ” — the second-derivative terms of the true Hessian are dropped, which is a good approximation when residuals are small. Levenberg-Marquardt adds a damping term, solving , interpolating between Gauss-Newton () and gradient descent ( large).
Checking Jacobians numerically
Analytic Jacobians are notoriously easy to get wrong (a sign, a transposed block). The standard sanity check is central finite differences: perturb one state dimension at a time and compare
with a small step (e.g., ). Every serious SLAM codebase has a unit test doing exactly this for each residual type.
Common pitfalls
- Sign errors: the residual vs. flips the sign of ; be consistent.
- Differentiating rotations naively: rotation matrices are constrained, so derivatives must be taken with respect to a local perturbation (see Lie groups), not the 9 matrix entries.
- Forgetting a chain-rule factor through normalization or distortion functions — the numeric check above catches this immediately.
Why it matters for SLAM
In bundle adjustment, the reprojection error is linearized around the current estimate. This converts the nonlinear least-squares problem into a sequence of linear systems , solved iteratively. Every optimization-based SLAM system — from pose graph optimization to full bundle adjustment — is built on this linearize-solve-update loop, so being able to derive Jacobians by hand (and check them numerically) is a core skill.