1.2.4 · D1Calculus & Optimization Basics

Foundations — Gradients and directional derivatives

2,496 words11 min readBack to topic

Before you can trust that arrow, you must be able to read every symbol on the page without hesitation. This note walks each one from nothing — plain words, a picture, and why the topic can't live without it. Read top to bottom; each piece is a brick for the next.


0. The function — the landscape itself

The picture: imagine a floor marked with an east axis and a north axis . Above every floor spot the function raises the ground to height . The result is a surface — a hill. Figure 1 draws exactly this: the amber dot is a floor spot and the dashed amber line rises to its height on the surface.

Figure — Gradients and directional derivatives
Figure 1 — The function as a hill: every floor position raises the ground to a height.

Why the topic needs it. Everything else — slope, gradient, descent — is a question about this surface. No surface, nothing to be steep.


1. The symbols and — where you stand

Sometimes there are more than two inputs. Instead of naming them we number them . The little number below is a label, not a power — means "the second input", not squared.

Picture: is an infinite sheet of graph paper (two coordinates). is all of space. is the same idea with coordinates — impossible to draw past 3, but the arithmetic is identical.

Why the topic needs it. ML models have thousands of inputs (weights). We must talk about "input number " generally, so and are unavoidable.


2. Vectors and , — points and arrows

  • = the place you are standing on the floor.
  • = the direction you decide to step (an arrow).

Figure 2 shows both: the cyan arrow marks where you stand, and the amber arrow (of length exactly ) is a step you might take — the dotted sides and are its components.

Figure — Gradients and directional derivatives
Figure 2 — is a place (cyan); is a unit-length direction (amber).

Why unit vectors matter. When we ask "how fast does height change as I step in direction ?", we want the answer per one metre walked. If the arrow were 2 metres long, we'd accidentally double the answer. Forcing length separates "which way" from "how far."

See Dot product and projections for how norms combine with angles next.


3. The limit — "zoom in until it's straight"

Slope means "rise over run." On a curve the rise-over-run depends on how big a step you take. To pin down the slope exactly at a point, we shrink the step toward .

Picture: take two nearby points on a curve, draw the straight line through them (a secant), then slide the second point toward the first. The secant tips over until it just kisses the curve — that final line is the tangent, and its steepness is the derivative. In Figure 3 the faint white lines are secants for shrinking ; the bold amber line is the tangent they home in on.

Figure — Gradients and directional derivatives
Figure 3 — As the step the secant lines (white) tip into the tangent (amber); its slope is the derivative.

Why the topic needs it. Both the ordinary derivative and the partial derivative are defined by this limit. It is the ground floor of all slopes.


4. The derivative and the partial symbol

In one variable, the derivative is the limit above: the instant slope of the curve .

With several inputs we need to say "slope along one axis only, holding the others frozen." That is the partial derivative, and it gets a special curly-d symbol (read "partial" or "del-dee") to warn you: other variables are being held constant.

Picture: stand on the hill and slice it with a vertical wall running exactly east–west. The wall cuts the surface into a single curve. is the slope of that curve. Turn the wall north–south and you get .

Why the topic needs it. The gradient is built entirely out of these numbers — one per axis. Master this and see Partial derivatives for practice.


5. The gradient symbol — bundling all the slopes

Picture: at your feet, each axis-slope becomes one component of a single arrow. Stacked together, that arrow ends up pointing straight up the steepest direction of the hill, and its length is that steepest slope. (The why is proven in the parent note via the dot product; here we just make sure you can read as "the vector of partials.")

Why the topic needs it. It is the whole point. Gradient descent follows downhill to train models.


6. Summation and the dot product

Picture: the dot product measures how much two arrows point the same way. Same direction → large positive. Perpendicular → zero. Opposite → large negative.

Why the topic needs it. The star quantity of this topic, the directional derivative (defined next), is a dot product. Both the algebra form () and the geometry form () are used.


7. The directional derivative — the payoff symbol

Everything so far was built to write down one symbol you will meet constantly in the parent note.

Picture: stand at (Figure 2's cyan arrow), face along (the amber arrow), and read how fast the ground rises straight ahead. That reading is .

Why the topic needs it. It is the question the whole topic answers: "step this way — how fast do I rise?" Steepest ascent, steepest descent, and contour-walking are all special cases of this one number.


Prerequisite map

The diagram below is a prerequisite map: read it top-to-bottom. Each box is one idea from the sections above, and each arrow means "the idea at the tail is needed to build the idea at the head." Follow the arrows and you rebuild the whole topic; the words on an arrow say what the lower idea contributes.

Limit h to 0

Derivative slope at a point

Partial derivative freeze other axes

Vectors a and u

Norm length and unit vector

Gradient nabla f vector of partials

Dot product and cos theta

Directional derivative D u f

Gradient descent uses minus gradient

Step size eta

Each box must feel obvious before you tackle the parent topic. If any box is fuzzy, reread its section above.


8. The Greek letter — step size

Picture: the gradient tells you which way to go; tells you how far per step. It is used in Gradient descent, and appears in the map above feeding the "gradient descent" box.


Equipment checklist

Read in plain words
"The height of the hill at floor position " — two inputs, one output.
Does mean " squared"?
No — the low subscript is a name tag ("input number two"); (high superscript) is the power.
What is ?
The set of all lists of real numbers — the flat floor / input space you stand on.
What does a vector look like and store?
An arrow from the origin; it stores a direction and a length.
Compute the length of and its unit vector
Length ; unit vector .
Why do we take a limit for slope?
To get the exact instant slope, the value the average-slope approximations settle onto as the step shrinks.
What does measure, and which arguments stay fixed?
The slope of when only moves by ; every other input keeps its value (frozen).
Must partials and always exist?
No — only where is smooth enough for the limit to settle; corners/cusps can make them undefined.
What is in words?
The vector whose components are all the partial derivatives; it points up the steepest slope.
Write out two ways
(multiply matching parts and add) and (geometry).
What is when arrows are perpendicular?
— so the dot product is zero and there is no height change.
What single number does give?
The slope of at when you step in unit direction ; it equals .
What role does play?
The step size / learning rate — how far you move per downhill step.