☰ Course contents
Mathematics 🎓 University Year 1 The Gradient: The Compass of Steepest Ascent
🎓 University Year 1 · Lesson 5 of 15

The Gradient: The Compass of Steepest Ascent

Collect a function's partial derivatives into a single vector, and it points straight uphill — toward the fastest increase — everywhere at once.

University Year 1Calculus II / Linear Algebra
The Gradient: The Compass of Steepest Ascent — illustration
💡
The big idea: A function of two variables f(x, y) is a landscape of hills and valleys. Its partial derivatives measure the slope along the x- and y-directions separately. Bundle them into one vector, the <strong>gradient</strong> &nabla;f, and something remarkable happens: that vector points in the direction of <em>steepest ascent</em>, its length is the steepest slope, and it is always perpendicular to the level curves. It is the single object that answers &ldquo;which way is up, and how steep?&rdquo;
🎯 By the end, you'll be able to
  • Define the gradient of a scalar field as the vector of its partial derivatives
  • Interpret the gradient's direction (steepest ascent) and magnitude (steepest slope)
  • Compute directional derivatives as the dot product ∇f · û
  • Explain why the gradient is perpendicular to level curves
📎 You should already know
  • Partial derivatives
  • Vectors and the dot product
  • Level curves and contour maps

Which way is uphill?

Stand on a hillside described by a height function f(x, y). You can measure the slope if you walk due east (that is ∂f/∂x) or due north (∂f/∂y). But those are just two of infinitely many directions. Which way is the steepest, and how steep is it?

The gradient answers both at once. It packages the two partial derivatives into a single vector that acts like a compass needle for “uphill.”

🔑 The gradient is the vector of partial derivatives
The gradient of f, written ∇f, has the partial derivatives as its components. It is a vector that lives in the input plane, not a number — and at every point it aims in the direction where f increases fastest.
\[ \nabla f=\left(\frac{\partial f}{\partial x},\ \frac{\partial f}{\partial y}\right) \]
The gradient of f(x, y): its components are the partial derivatives in each coordinate direction.
🎮 The Gradient Climber LIVE
The gradient arrow always points in the direction of steepest increase.

The directional derivative

To find the slope in any direction — described by a unit vector û — take the dot product of the gradient with that direction. This is the directional derivative: it projects the gradient onto the way you want to walk.

Because a dot product is largest when the two vectors are parallel, the slope is greatest exactly when you walk in the direction of ∇f itself — confirming that the gradient points the steepest way up. Walk perpendicular to it and the slope is zero: you are contouring around the hill at constant height.

\[ D_{\hat u}f=\nabla f\cdot \hat u=\lVert \nabla f\rVert\cos\theta \]
The directional derivative in direction û. It is largest (= ‖∇f‖) when θ = 0, i.e. û points along the gradient.
📝 Worked example: Find the gradient of f(x, y) = x² + y² at the point (1, 2).
  1. Partial with respect to x: \( \partial f/\partial x = 2x \). Partial with respect to y: \( \partial f/\partial y = 2y \).
  2. So \( \nabla f=(2x,\,2y) \).
  3. Evaluate at (1, 2): \( (2\cdot 1,\ 2\cdot 2)=(2,4) \).
✓ ∇f(1, 2) = <strong>(2, 4)</strong> — it points directly away from the origin, straight up the bowl, with magnitude √(2²+4²) = √20 = 2√5.
📝 Worked example: For f(x, y) = x²y, find the slope at (1, 1) in the direction of the vector (3, 4).
  1. Gradient: \( \nabla f=(2xy,\ x^{2}) \); at (1, 1) this is \( (2,1) \).
  2. Make the direction a unit vector: \( \lVert(3,4)\rVert=5 \), so \( \hat u=(3/5,\,4/5) \).
  3. Directional derivative: \( \nabla f\cdot \hat u=2\cdot\tfrac{3}{5}+1\cdot\tfrac{4}{5}=\tfrac{6+4}{5}=\tfrac{10}{5} \).
✓ The slope in that direction is <strong>2</strong>. (You must normalise the direction first, or the number is meaningless.)
✨ The gradient is perpendicular to level curves
Along a level curve (a contour where f is constant) the function does not change, so the directional derivative along the curve is zero. But ∇f · û = 0 means ∇f is perpendicular to that direction. Hence the gradient always crosses the contour lines at a right angle — which is exactly why the steepest path up a hill cuts straight across the contours rather than following them.
⚠️ Normalise the direction first
The directional derivative formula ∇f · û requires û to be a unit vector. If you dot with a non-unit vector like (3, 4) directly, you scale the answer by its length (here 5) and get a wrong, inflated slope. Always divide the direction by its magnitude before taking the dot product.

Check your understanding

1. The gradient ∇f of a scalar function f(x, y) is:
The gradient collects the partial derivatives into a vector: ∇f = (∂f/∂x, ∂f/∂y).
2. In what direction does the gradient point?
The gradient points where f increases fastest; its magnitude is that steepest rate of increase. (Steepest decrease is −∇f.)
3. How is the gradient oriented relative to a level curve of f?
Along a level curve f is constant, so the directional derivative there is zero; ∇f · û = 0 means ∇f is perpendicular to the curve.
4. The directional derivative of f in the direction of a unit vector û equals:
D_û f = ∇f · û. This projects the gradient onto the chosen direction; it is largest when û points along ∇f.
5. For f(x, y) = x² + y², what is ∇f at the point (1, 2)?
∇f = (2x, 2y), so at (1, 2) it is (2·1, 2·2) = (2, 4).
✅ Key takeaways
  • The gradient ∇f = (∂f/∂x, ∂f/∂y) is a vector built from the partial derivatives.
  • It points in the direction of steepest ascent, and its magnitude ‖∇f‖ is the steepest slope.
  • The directional derivative in a unit direction û is the dot product ∇f · û.
  • ∇f is always perpendicular to the level curves of f, so the steepest path cuts across the contours.
  • Always normalise the direction to a unit vector before taking the dot product, or the slope is wrong.