skip to content

Why is a nonzero gradient always perpendicular to the level curves of a function f(x, y)?

level: middleimportance: should knowfreq 48%

answer

  1. the function does not change along a contour
  2. zero rate in the tangent direction
  3. a vanishing combination with a nonzero vector
  4. cos(theta) = 0 is the only way out
  5. topographic maps: uphill crosses the lines squarely

basics

~10 s

Along a level curve the function is constant, so the rate of change in the tangent direction is zero. With a nonzero gradient, that combination vanishes only if the two are at right angles.

solid answer

~50 s

A level curve is the set of points where `f(x, y) = c` for a fixed constant `c`. Walk along it and `f` does not change, so the directional derivative in the unit tangent direction `t` is exactly zero. But that directional derivative is `grad f . t`, and with a nonzero gradient the combination can vanish only when `cos(theta) = 0` — the gradient is perpendicular to the curve. Concretely, for the elliptical bowl `f(x, y) = x^2 + 4y^2` the contours are ellipses; at `(1, 1)` the gradient is `(2, 8)` and the contour's tangent direction is proportional to `(4, -1)`, and `2*4 + 8*(-1) = 0`. Two riders: the gradient points across the contour toward *higher* values, and where contour lines bunch together the gradient is large. Where `grad f = 0` the argument singles out nothing.

go deeper

for a junior

Know the picture from a topographic map: contour lines join equal values, and the uphill direction crosses them at right angles rather than running along them.

for a middle

Give the argument in full: f is constant along the contour, so the rate along the tangent is zero, and a vanishing combination with a nonzero gradient forces a right angle.

for a senior

Add the practical readings interviewers want: the gradient points toward higher values, contour crowding signals a large gradient, and the whole claim collapses where the gradient is zero.

for a principal

Own the geometric consequence for elongated bowls: when contours are highly stretched, the perpendicular direction points sharply across the valley rather than along it, which shapes how any first-order method behaves on badly conditioned objectives.

## Level sets, in plain terms A **level set** (in two variables, a **level curve** or **contour**) of `f` is the collection of input points sharing one output value: `{ (x, y) : f(x, y) = c }`. A topographic map is exactly this — each printed line joins the points at a single elevation. Contours describe the input plane, not the surface floating above it; the surface is the graph, the contour is its shadow at one height. ## The argument Pick a point `a` on the contour `f = c`, and let `t` be a unit vector tangent to the contour there — the bearing you would face if you walked along the contour without leaving it. **Step 1.** Moving along the contour keeps `f` fixed at `c` by definition. So the instantaneous rate of change of `f` along `t` is zero: `D_t f(a) = 0`. **Step 2.** For a differentiable `f`, that rate is the gradient combined with the direction: `D_t f(a) = grad f(a) . t`. **Step 3.** Therefore `grad f(a) . t = 0`. Writing it as `|grad f(a)| * |t| * cos(theta)` with `|t| = 1`, the product vanishes only if `|grad f(a)| = 0` or `cos(theta) = 0`. Excluding the zero gradient by assumption leaves `theta = 90` degrees. That is the entire proof, and it is worth being able to say in three sentences: `f` is constant along the contour, so the rate along the tangent is zero, so the gradient must be at right angles to it. ## A concrete check on an elliptical bowl Take `f(x, y) = x^2 + 4y^2`. Its level sets are the ellipses `x^2 + 4y^2 = c`, nested around the origin and stretched wider in `x` than in `y` because the `y` term is weighted more heavily. The gradient is `grad f = (2x, 8y)`. At the point `(1, 1)` the function value is `1 + 4 = 5`, so this point sits on the contour `x^2 + 4y^2 = 5`, and the gradient there is `(2, 8)`. What is the tangent to that ellipse at `(1, 1)`? Differentiating the relation `x^2 + 4y^2 = 5` implicitly gives `2x + 8y * y' = 0`, so `y' = -2x / (8y) = -2/8 = -1/4` at that point. A tangent direction is therefore proportional to `(1, -1/4)`, or equivalently `(4, -1)`. Combine: `(2, 8)` against `(4, -1)` gives `2*4 + 8*(-1) = 8 - 8 = 0`. Perpendicular, exactly as the general argument predicts. ## Which side of the contour does it point to? Perpendicularity fixes a line, not an arrow. The gradient chooses the side of *increasing* `f`: it points from the contour `f = c` toward nearby contours with larger values. On a hillside map, the gradient at any point aims uphill and crosses the contour lines at right angles. Its opposite crosses them at right angles too, but pointing downhill. ## Reading contour spacing The same identity explains a habit every reader of topographic maps has: contour lines drawn at fixed value increments crowd together where the terrain is steep and spread apart where it is gentle. Formally, to move from `f = c` to `f = c + dc` you must travel roughly `dc / |grad f|` in the perpendicular direction. A large gradient means a short crossing distance, hence tightly packed lines; a small gradient means the next contour is far away. So a contour plot displays both facts at once: the gradient's direction (perpendicular to the lines, toward higher values) and its magnitude (inversely related to the local spacing). ## Where the argument breaks down **Zero gradient.** If `grad f(a) = 0`, Step 3 is satisfied trivially and singles out nothing. Geometrically this is where contours behave strangely: at the centre of the elliptical bowl the level set degenerates to a single point, and at a flat saddle point contour lines can cross each other, so 'the tangent direction' is not even unique. **Non-differentiable points.** The identity `D_t f = grad f . t` requires differentiability at the point; at a corner or crease of the surface the argument has no gradient to work with. **Higher dimensions.** In three variables the level sets are surfaces rather than curves, and the same reasoning shows the gradient is perpendicular to the whole tangent plane: every direction lying in that plane keeps `f` constant, so every one of them gives zero when combined with the gradient. The statement generalises unchanged — the gradient is normal to the level set through the point. ## What to say in an interview Lead with the one-line argument (constant along the contour, so zero rate along the tangent, so perpendicular), then offer a concrete verification like the ellipse, then volunteer the two riders: the gradient points toward higher values, and closely spaced contours mean a large gradient. Naming the zero-gradient exception unprompted is what marks a careful answer.

  • What does the spacing of contour lines tell you about the gradient?
    With contours drawn at fixed value increments, crossing from one to the next takes roughly dc / |grad f| in distance. Tightly packed lines therefore mean a large gradient and steep terrain; widely spaced lines mean a small gradient and gentle terrain. Spacing reads off magnitude, orientation reads off direction.
  • Perpendicular leaves two possible arrows — which one is the gradient?
    The one pointing toward higher function values. Perpendicularity only fixes the line; the sign is settled by the fact that the gradient is the direction of increase. Its opposite is equally perpendicular to the contour but crosses toward lower values.
  • What happens to this claim at a point where the gradient is zero?
    It says nothing. The combination vanishes automatically, so no perpendicular direction is singled out. Such points are exactly where contours misbehave: a level set can collapse to a single point at the bottom of a bowl, or two contour branches can cross at a flat saddle.
  • Does the same statement hold for a function of three variables?
    Yes, with surfaces instead of curves. The level set f(x, y, z) = c is a surface, every direction lying in its tangent plane keeps f constant, so each gives zero when combined with the gradient. The gradient is therefore normal to the entire tangent plane at that point.

On a topographic map the fastest way uphill always cuts across the contour lines at a right angle; walking along a line keeps you at the same elevation and gains nothing.

saying these in an interview costs you the question

  • Says the gradient is tangent to the contour rather than perpendicular
  • Claims the gradient points along the contour toward the minimum
  • Asserts the perpendicularity even where the gradient vanishes
  • Confuses the level curve in the input plane with the graph surface
  • Thinks closely spaced contours mean a small gradient

context