III.9 · Calculus
What does a curved map look like up close?
Push a small square through a nonlinear map. Near a point the curved image is almost a parallelogram — the image of the square under one matrix, the Jacobian.
Predict a vector map with its local linear transformation
Input plane: point p, displacement δ and a small square
Input point p = (1, 0.5), displacement δ = (0.25, 0.25) and a square of half-side 0.25 around p.
Output near F(p): actual image versus the Jacobian prediction
F(p) = (0.75, 1). The grey curved shape is the actual image of the input square; the purple parallelogram is its Jacobian image. The orange arrow is the actual change F(p + δ) − F(p); the dashed purple segment ends at the prediction F(p) + Jδ = (1, 1.75).
- Shape: outputs × inputs
- 2 × 2 (input ℝ², output ℝ²)
- Output at p
- (0.75, 1)
- Column 1: response to a unit x-step
- (2, 1)
- Column 2: response to a unit y-step
- (−1, 2)
- Row 1: gradient of the first output
- (2, −1)
- Local area factor
- 5
- Linear prediction
- (1, 1.75)
- Independent evaluation
- (1, 1.875)
- Squared prediction error (exact)
- 0.015625
- Relative error
- 0.353553
- Wrong-shape product
- undefinedShape mismatch: J is 2×2 but the vector has 3 entries; J·v needs exactly 2.
Exact values use =; binary64 approximations use ≈. Undefined values state their reason.
Near p the map acts like the matrix J: the predicted change Jδ = (0.25, 0.75) is close to the actual change; the error is second order.
Evaluate F at p
F(p) = (0.75, 1).
from −2 to 2, up to 2 decimal places
from −2 to 2, up to 2 decimal places
from −1 to 1, up to 2 decimal places
from −1 to 1, up to 2 decimal places
The complex-square map bends the plane. Around the small grey square becomes a slightly curved shape, and the purple parallelogram — its image under the matrix — almost covers it. Try Large displacement: the prediction now misses visibly. Then Singular at the origin: and the square collapses.
Intuition: zoom until it is linear
A differentiable function of one variable looks like a line when you zoom in. A differentiable map of the plane looks like a linear transformation when you zoom in: small grids become grids of parallelograms. That linear transformation is the Jacobian matrix. Its columns say where the two input step directions go; its determinant says how small areas are scaled.
Definition
For with components , the Jacobian at is the matrix
with one row per output and one column per input. Row is the gradient of ; column is the response of all outputs to the -th input. Differentiability means
Mechanics: what the explorer computes
The maps are polynomial, so , , the prediction and the independent evaluation are exact; the squared error is an exact rational. The output plane is a local window centred near . Its curved shape samples the true image of the square’s boundary; the parallelogram and the two column arrows are drawn from . The Lift preset maps : its Jacobian multiplies 2-vectors and returns 3-vectors, so the plane shows only two of the three outputs and says so.
Derivation: from partial derivatives to a matrix
Each component is a scalar function, so by III.8, . Stacking the rows gives the matrix–vector product . Multiplying by combines the columns: . Shapes must agree: an matrix multiplies only an -vector.
Worked example
For at :
so .
. With , , so the prediction is . The independent evaluation is . The error is second order: halving quarters it.
Replay the worked derivation
Evaluate F at p
F(p) = (0.75, 1).
Singular and rectangular Jacobians
At the origin the complex square has : every first-order change vanishes and the square shrinks by a factor of order more than linear scaling predicts. A square Jacobian with is not invertible, so the map cannot be locally inverted there. A rectangular Jacobian has no determinant; for the image of a small square is a small parallelogram tilted in space. Multiplying a Jacobian by a 3-vector is rejected as a shape mismatch.
Executable reference code
The reference builds exact Jacobians from partial derivatives with Fraction, enforces shapes and checks the second-order error. The NumPy version compares with for shrinking and confirms that the error ratio decreases.
"""Exact Jacobian of F(x, y) = (x**2 - y**2, 2xy), shape checks and the second-order error (III.9)."""
from fractions import Fraction as F
F_map = lambda x, y: (x * x - y * y, 2 * x * y)
J = lambda x, y: ((2 * x, -2 * y), (2 * y, 2 * x))
def mat_vec(A, v):
if any(len(row) != len(v) for row in A):
raise ValueError(f"shape mismatch: {len(A)}x{len(A[0])} times a {len(v)}-vector")
return tuple(sum(a * b for a, b in zip(row, v)) for row in A)
p, d = (F(1), F(1, 2)), (F(1, 4), F(1, 4))
pred = tuple(a + b for a, b in zip(F_map(*p), mat_vec(J(*p), d)))
actual = F_map(p[0] + d[0], p[1] + d[1])
assert pred == (1, F(7, 4)) and actual == (1, F(15, 8))
# Halving the displacement quarters the error (it is second order).
def err(scale):
dd = (d[0] * scale, d[1] * scale)
a = F_map(p[0] + dd[0], p[1] + dd[1]); q = tuple(x + y for x, y in zip(F_map(*p), mat_vec(J(*p), dd)))
return sum((x - y) ** 2 for x, y in zip(a, q))
assert err(F(1, 2)) == err(F(1)) / 16 # squared error scales by (1/2)**4
try:
mat_vec(J(*p), (F(1), F(0), F(0)))
except ValueError:
pass
else:
raise AssertionError("a 2x2 Jacobian must reject a 3-vector")"""Linearisation error ratio ||F(p+d) - F(p) - J d|| / ||d|| shrinks with d (III.9)."""
import numpy as np
def F(v):
x, y = v
return np.array([x * x - y * y, 2 * x * y])
def J(v):
x, y = v
return np.array([[2 * x, -2 * y], [2 * y, 2 * x]])
p = np.array([1.0, 0.5])
direction = np.array([1.0, 1.0]) / np.sqrt(2)
ratios = []
for s in 2.0 ** -np.arange(1, 12):
d = s * direction
ratios.append(np.linalg.norm(F(p + d) - F(p) - J(p) @ d) / np.linalg.norm(d))
assert np.all(np.diff(ratios) < 0) and ratios[-1] < 1e-3
assert J(p).shape == (2, 2) and np.isclose(np.linalg.det(J(p)), 5.0)Explore
On Linear map, the prediction is exact for every : the Jacobian of a linear map is the map. On Bend, notice that the second row never changes: has gradient . Move along and watch the orange arrow align with the first column.
Common mistakes
Transposing the Jacobian (rows are outputs, columns are inputs). Multiplying in the wrong order: , not . Expecting a determinant from a non-square Jacobian. Trusting the linear prediction far from .
Numerical considerations
Near-singular Jacobians make local inversion (Newton’s method for systems) sensitive: small output errors become large input errors, as with ill-conditioned matrices in Part II. Finite-difference Jacobians cost one extra evaluation per input column and inherit the step-size trade-off of III.14.
Engineering and ML connections
The Jacobian of each layer maps input perturbations to output perturbations; backpropagation multiplies transposed Jacobians from the loss backward (III.10). Robotics uses manipulator Jacobians to relate joint and hand velocities; change-of-variables formulas in probability use .
Exercises
Summary and checkpoints
The Jacobian is the matrix of all first partial derivatives, for . It is the local linear transformation of the map: , with columns as input responses and rows as output gradients. Next, III.10 shows how a computer obtains such derivatives automatically from the operations of a program.