1.2.4 · D4Calculus & Optimization Basics

Exercises — Gradients and directional derivatives

2,115 words10 min readBack to topic

Level 1 — Recognition

Recall Solution 1.1

(a) Vector. The gradient has one component per input variable. Here there are two inputs , so is a 2-component arrow, not a number. The number is what you get after dotting with a direction. (b) Steepest slope . Magnitude of a vector is : This is the largest value can ever reach, because maxes out at . (c) Steepest-ascent unit direction Dividing a vector by its own length gives a length-1 arrow pointing the same way.

Recall Solution 1.2

(a) True. A contour (level set) is a curve where keeps the same value. Same value no change . Since , that dot product is zero, so . (b) False. The gradient is perpendicular to the contour, not along it. It points across the contours, straight uphill. See the trap below.


Level 2 — Application

Recall Solution 2.1

Partials — differentiate one variable, freeze the other (see Partial derivatives). (treat constant; has no , so it dies). (treat constant). Evaluate at :

Recall Solution 2.2

Step 1 — raw direction (arrow from to target): . Step 2 — normalise. Length , so the unit step is . Why normalise? should measure slope per one step of distance; a longer arrow would fake a steeper slope. See Dot product and projections. Step 3 — dot product with from 2.1:

Recall Solution 2.3

Gradient (1-D, so it's an ordinary derivative): . At : . Positive loss rises as grows, so we step the other way. Update: We moved toward smaller loss by stepping opposite the gradient, because is steepest descent.


Level 3 — Analysis

Recall Solution 3.1

Use with . (a) Max at (, step aligned with gradient): , value . (b) Min at (, step opposite): , value . This is the descent direction. (c) Zero at (, step perpendicular): or , value — both run along the contour.

Figure — Gradients and directional derivatives

Notice the two contour directions in (c): perpendicularity has two solutions (forward and backward along the contour), and both give zero.

Recall Solution 3.2

Dotting the gradient with an axis unit vector just reads off a component: and . So , and the steepest slope is The directional derivatives along the axes are literally the partial derivatives — that's why the gradient is the vector of partials.


Level 4 — Synthesis

Recall Solution 4.1

Gradient: , , so , . Half the max rate means . But , so The rate depends only on the angle, not on where you stand — a clean payoff of . One valid direction: rotate the unit gradient by . Using the 2-D rotation of by : any with works. (A second valid answer exists by rotating .)

Figure — Gradients and directional derivatives
Recall Solution 4.2

Parametrise a path that stays on the contour, and let be the height along it. By the Chain rule, On a contour the tangent is perpendicular to (that's what "along the contour" means), so the dot product is . Hence everywhere on the path is constant never changes. This is exactly the statement " contour" turned into a derivative fact.


Level 5 — Mastery

Recall Solution 5.1

Gradient: . At : , , steepest-ascent unit direction , max slope . Contours are circles; the gradient points radially outward — perpendicular to the circle, as expected. At the origin : . Now for every direction . There is no steepest direction — the surface is momentarily flat to first order. This is a critical point (here, the minimum). The direction of steepest ascent is undefined; that's not a failure of the theory, it's the signal that gradient descent has converged (zero step). See Jacobian and Hessian for how the second-order info (the Hessian) tells minimum vs maximum vs saddle when the gradient is zero.

Figure — Gradients and directional derivatives
Recall Solution 5.2

(a) Gradient: . At : . (b) Step opposite the gradient: (c) Loss check: ; . Since , the loss dropped. ✓ (d) Why not straight at ? The straight-to-minimum direction from is (normalised ). The negative gradient is (normalised ) — it leans much harder along because is 4× steeper in (the term). Steepest descent chases steepness, not the shortest route home. On stretched (ill-conditioned) bowls this causes the zig-zag that motivates momentum and preconditioning.


Score yourself

Recall What did each level test?

L1 tested recognising gradient-as-vector and the contour-perpendicularity fact. L2 tested the compute pipeline: partials → evaluate → normalise → dot. L3 tested reasoning through (max/min/zero, two perpendicular solutions). L4 tested combining rate control via angle and proving the contour fact with the chain rule. L5 tested the degenerate zero-gradient case, a full sign audit, and minimum-vs-saddle nuance.

Connections