1.2.5 · D4Calculus & Optimization Basics

Exercises — The Jacobian matrix

2,166 words10 min readBack to topic

Quick reminder of the one rule everything rests on. For a function that eats a vector and returns a vector, , the Jacobian is the table of partial derivatives

with ==rows = outputs, columns = inputs==. It is the best linear approximation: .


Level 1 — Recognition

Exercise 1.1 — Read off the shape

Let . Without computing anything, state the shape of its Jacobian and say what a single row and a single column represent.

Recall Solution

Shape. Rows = number of outputs ; columns = number of inputs . So . What we did & why: the shape is fixed before any calculus, purely by counting outputs and inputs. This is the "ROC — Rows are Outputs, Columns are inputs" mnemonic.

  • A row () is : the gradient of one output , telling how that single output responds to all inputs.
  • A column () is : how both outputs respond to nudging one input . Check: must send an input-direction to an output-change in . . ✔

Exercise 1.2 — Which entry is which?

For , which partial derivative lives at position (row 2, column 3)?

Recall Solution

Position means output , input . Here and the third input is . Why: the first index always picks the output (which row), the second index picks the input (which column). Getting this ordering automatic is the whole point of Level 1.


Level 2 — Application

Exercise 2.1 — Compute a Jacobian

Let . Find and evaluate at .

Recall Solution

Differentiate each output with respect to each input, holding the other input fixed:

  • ,
  • ,

Why each step: every entry is "pick an output, differentiate w.r.t. one input, treat the other input as a constant." Substituting (using ) turns symbolic slopes into the concrete local linear map.

Exercise 2.2 — Linear approximation with the Jacobian

Using from Exercise 2.1 and , estimate .

Recall Solution

The step from the base point is . The linearization says :

Why the Jacobian and not a plain slope? With two outputs there is no single "slope" number — the Jacobian is the matrix that plays the role of , so multiplying it by the nudge predicts the change in both outputs at once. (True value : the linear estimate is close because is small — see Linear approximation and Taylor series.)


Level 3 — Analysis

Exercise 3.1 — A non-square Jacobian and why it has no determinant

Let . Find , state its shape, and explain in one sentence why is meaningless here.

Recall Solution

Shape: outputs, inputs . Why no determinant: a determinant is only defined for a square matrix. Here , so there is no . (Determinants measure how a map scales volume from a space back into itself; a map changes the number of dimensions, so "volume scaling" has no single meaning — see Change of variables in integration.)

Exercise 3.2 — Diagonal Jacobian of an elementwise map

Let apply the same scalar function to each entry of , i.e. . Show the Jacobian is diagonal, and write it for .

Recall Solution

Entry . Since depends only on :

  • If : doesn't contain , so (off-diagonal vanishes).
  • If : .

Hence . For , recall , so Why this matters: elementwise activations in a neural net always give diagonal Jacobians — that is exactly why Backpropagation can multiply by them cheaply (a diagonal times a vector is just entrywise scaling).


Level 4 — Synthesis

Exercise 4.1 — Chain rule as a matrix product

Let and , so . Compute at using the Jacobian chain rule , then verify by substituting first.

Recall Solution

Inner Jacobian. , so is : Outer Jacobian in the variables : , so : At : , , so . Multiply (outer on the LEFT): Verify by substituting first. , so Why this works: the multivariable The chain rule (multivariable) says composing functions composes their linear approximations, and composing linear maps is matrix multiplication. Shapes only fit as , forcing the outer Jacobian on the left.

Exercise 4.2 — Jacobian of a linear layer + activation

Let with and then elementwise with . Give the full Jacobian symbolically, then evaluate at .

Recall Solution

Two building blocks:

  • (because ).
  • (Exercise 3.2).

Chain rule (activation is the outer map, so it goes on the left): Evaluate at : . Then , and . Why this is backprop: this product-of-Jacobians is precisely how gradients flow through one layer in Backpropagation and Jacobian-vector products (forward-mode autodiff).


Level 5 — Mastery

Exercise 5.1 — Determinant as local area scaling (polar map)

For the polar-to-Cartesian map , we have . Interpret geometrically: how much does a tiny rectangle located at get stretched in area, and what happens at ?

Figure — The Jacobian matrix
Recall Solution

The Jacobian is , and Geometry (see figure): a small patch that is wide (radial) and tall (angular) maps to a curved patch in the plane. Its two edges have physical lengths (radial) and (arc length — the arc grows with radius). Area , matching . Why the determinant answers this: for a square Jacobian, is the factor by which any tiny volume is multiplied by the map. That is literally the in polar integration — see Change of variables in integration. At : . The map collapses the whole line (every ) onto the single origin point, so any tiny patch there is squashed to zero area. A zero determinant flags a non-invertible (degenerate) point — the polar coordinate breaks down at the origin because is undefined there.

Exercise 5.2 — When the linear approximation is exact

Prove that for an affine map (with constant matrix and constant vector ), the Jacobian is everywhere, and the "approximation" holds with exact equality.

Recall Solution

Component : . Then (the is constant, drops out). So , constant for all . Now compute the exact difference: No "" needed — it is "". Why: the linearization keeps only first-order (straight-line) behavior. An affine map is already straight, so there is no curvature (second-order term) to discard. The Taylor series terminates; the Jacobian captures the map perfectly. This is the base case behind Linear approximation and Taylor series.

Exercise 5.3 — Jacobian-vector product without forming

For at the point , compute the Jacobian-vector product for the direction — the directional rate of change of both outputs.

Recall Solution

At : ; ; ; the last entry is .

J\mathbf{v}=\begin{bmatrix}2\pi & \tfrac{\pi^2}{4}\\ 0 & 1\end{bmatrix}\begin{bmatrix}1\\-1\end{bmatrix} =\begin{bmatrix}2\pi-\tfrac{\pi^2}{4}\\ -1\end{bmatrix}\approx\begin{bmatrix}3.815\\ -1\end{bmatrix}.$$ **Why "without forming $J$" matters:** in [[Jacobian-vector products (forward-mode autodiff)]] you compute $J\mathbf{v}$ directly by pushing the direction $\mathbf{v}$ through the function — you never build the full (possibly huge) matrix. Here we formed $J$ to check the arithmetic, but the *value* $J\mathbf{v}$ is what forward-mode autodiff returns cheaply. The first output rises at rate $\approx 3.815$, the second falls at rate $1$, when we move in direction $(1,-1)$.

Recall One-line self-quiz

Shape of for ? ::: (rows = outputs, columns = inputs). Chain rule for ? ::: , outer on the left. When does exist and what does mean? ::: only if is square (); it is the local volume-scaling factor. When is exact? ::: when is affine (), because there is no curvature to drop.