01 / 20

The Gradient:
Steepest Ascent & Descent

Discover how \(\nabla f\) points in the direction of maximum increase and how \(-\nabla f\) drives optimization algorithms like gradient descent.

Multivariable Calculus

What Is the Gradient?

For a scalar function \(f(x, y)\), the gradient is a vector of all first partial derivatives:

For a function of \(n\) variables \(f(x_1, x_2, \ldots, x_n)\), the gradient generalizes to:

The Gradient as a Vector Field

At every point in the domain, \(\nabla f\) assigns a vector that encodes both direction and magnitude of the steepest rate of change.

peak \(f = 1\) \(f = 2\) \(f = 3\) \(\nabla f\)

Why Does \(\nabla f\) Matter?

Optimization
Gradient descent uses \(-\nabla f\) to find minima of loss functions in machine learning.
Physics
Forces point along \(-\nabla V\), where \(V\) is potential energy: a ball rolls downhill.
Engineering
Heat flows opposite to \(\nabla T\): from hot regions toward cold ones.

The Steepest Ascent Theorem

Proof sketch: By definition, \(D_{\mathbf{u}} f = \nabla f \cdot \mathbf{u} = \|\nabla f\|\;\|\mathbf{u}\|\cos\theta = \|\nabla f\|\cos\theta\). This is maximized when \(\theta = 0\), i.e., \(\mathbf{u}\) is parallel to \(\nabla f\).

Visualizing Directional Derivatives

x y \(\mathbf{a}\) \(\nabla f\) \(\mathbf{u}\) \(\theta\) \(-\nabla f\)

Gradient vs. Directional Derivative

Gradient \(\nabla f\) Directional Derivative \(D_{\mathbf{u}}f\)
Type Vector Scalar
What it gives Direction & rate of steepest increase Rate of change in direction \(\mathbf{u}\)
Formula \(\langle f_x, f_y \rangle\) \(\nabla f \cdot \mathbf{u}\)
Depends on direction? No: intrinsic to \(f\) Yes: depends on \(\mathbf{u}\)
Relationship \(D_{\mathbf{u}} f = \nabla f \cdot \mathbf{u}\); maximum when \(\mathbf{u} \parallel \nabla f\)

Steepest Descent Algorithm

To minimize \(f\), we iteratively step in the direction of \(-\nabla f\):

Here, \(\alpha\) is the learning rate (step size). Too large: overshoot. Too small: slow convergence.

\(\mathbf{x}_0\) min contours of \(f\)

How to Find the Steepest Direction

1
Compute partial derivatives. Find \(\frac{\partial f}{\partial x}\) and \(\frac{\partial f}{\partial y}\) (and any other variables).
2
Form the gradient vector. Assemble \(\nabla f = \langle f_x,\, f_y \rangle\).
3
Evaluate at the point. Plug in coordinates to get \(\nabla f(\mathbf{a})\).
4
Interpret: Steepest ascent direction is \(\nabla f(\mathbf{a})\). Steepest descent is \(-\nabla f(\mathbf{a})\).
5
Find the maximum rate. \(\|\nabla f(\mathbf{a})\|\) is the maximum directional derivative.

Example 1: Simple Polynomial

Let \(f(x, y) = x^2 + 3y^2\). Find the gradient at \((1, 2)\) and the steepest ascent direction.

1
Partial derivatives: \(f_x = 2x\), \(f_y = 6y\).
2
Gradient: \(\nabla f = \langle 2x,\, 6y \rangle\).
3
Evaluate at \((1,2)\): \(\nabla f(1,2) = \langle 2,\, 12 \rangle\).
4
Steepest ascent direction: \(\langle 2,\, 12 \rangle\). As a unit vector: \(\frac{1}{\sqrt{148}}\langle 2,\, 12 \rangle = \frac{1}{\sqrt{37}}\langle 1,\, 6 \rangle\).
5
Max rate of increase: \(\|\nabla f\| = \sqrt{4 + 144} = 2\sqrt{37} \approx 12.17\).

Example 2: Transcendental Function

Let \(f(x,y) = e^{-x}\sin y\). Find the direction of steepest descent at \((0, \pi/2)\).

1
Partials: \(f_x = -e^{-x}\sin y\), \(f_y = e^{-x}\cos y\).
2
At \((0, \pi/2)\): \(f_x = -e^0 \cdot 1 = -1\), \(f_y = e^0 \cdot 0 = 0\).
3
Gradient: \(\nabla f(0, \pi/2) = \langle -1,\, 0 \rangle\).
4
Steepest descent: \(-\nabla f = \langle 1,\, 0 \rangle\). That is, in the positive \(x\)-direction.

Example 3: Three Variables

Let \(f(x,y,z) = x^2 y + yz^3\). Find the steepest ascent direction and the maximum rate of change at \((1, -1, 2)\).

1
Partials: \(f_x = 2xy\), \(f_y = x^2 + z^3\), \(f_z = 3yz^2\).
2
Evaluate: \(f_x = -2\), \(f_y = 1 + 8 = 9\), \(f_z = 3(-1)(4) = -12\).
3
Gradient: \(\nabla f = \langle -2,\, 9,\, -12 \rangle\).
4
Max rate: \(\|\nabla f\| = \sqrt{4 + 81 + 144} = \sqrt{229} \approx 15.13\).

When Is \(D_{\mathbf{u}} f\) Zero?

Recall \(D_{\mathbf{u}} f = \|\nabla f\| \cos\theta\). The directional derivative is zero when \(\theta = \pi/2\), meaning \(\mathbf{u}\) is perpendicular to \(\nabla f\).

\(f = c\) \(\mathbf{a}\) \(\nabla f\) tangent

Common Mistakes

✕ Forgetting to normalize
The steepest ascent direction is \(\nabla f / \|\nabla f\|\), a unit vector. The gradient itself gives both direction and magnitude.
✕ Sign confusion
Steepest ascent is \(+\nabla f\). Steepest descent is \(-\nabla f\). Mixing these up reverses the optimization.
✕ Scalar vs. vector
The gradient \(\nabla f\) is a vector. The directional derivative \(D_{\mathbf{u}} f\) is a scalar. Do not confuse the two.

Summary at a Glance

Quantity Formula Meaning
Gradient \(\nabla f = \langle f_x, f_y \rangle\) Vector: direction of steepest ascent
Steepest ascent direction \(\dfrac{\nabla f}{\|\nabla f\|}\) Unit vector: fastest increase
Steepest descent direction \(-\dfrac{\nabla f}{\|\nabla f\|}\) Unit vector: fastest decrease
Max rate of change \(\|\nabla f\|\) Scalar: how fast \(f\) grows
Directional derivative \(D_{\mathbf{u}} f = \nabla f \cdot \mathbf{u}\) Rate of change in direction \(\mathbf{u}\)
Zero change \(\mathbf{u} \perp \nabla f\) Along level curves

Question 1 of 5

If \(f(x,y) = x^2 + y^2\), what is \(\nabla f\) at the point \((3, 4)\)?

Question 2 of 5

The gradient \(\nabla f\) at a point is perpendicular to which of the following?

Question 3 of 5

For \(f(x,y) = 3x^2 - y^2\), what is the maximum rate of change at \((1, 2)\)?

Question 4 of 5

In the gradient descent update rule \(\mathbf{x}_{n+1} = \mathbf{x}_n - \alpha\,\nabla f(\mathbf{x}_n)\), what does the negative sign ensure?

Question 5 of 5

If \(\nabla f(2,1) = \langle 3, -4 \rangle\) and \(\mathbf{u} = \langle 0, 1 \rangle\), what is the directional derivative \(D_{\mathbf{u}} f(2,1)\)?