Foundations to Frontier
Tests
A. Mathematical Foundations › A3 Calculus and Analysis › Multivariable calculus

The Gradient: Steepest Ascent and Orthogonality to Level Sets

The gradient bundles all partial derivatives into one arrow. It points uphill as steeply as possible and stands perpendicular to every contour line. Walking against it is gradient descent, the algorithm that trains nearly every machine-learning model and steers potential-field robots.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

The uphill arrow

At every spot on a hill, imagine an arrow pointing in the direction where the ground rises fastest. Its length shows how steep that is. That arrow is the gradient.

Two facts make it special:

  • A ball let go on the hill rolls the opposite way, straight downhill.
  • The arrow always crosses the contour lines at a right angle. Walking along a contour keeps your height the same, so the uphill direction must be perpendicular to it.
The gradient field and gradient descent (click to choose a start)
after 300 steps: (-0.000, 0.000), f = 9.46e-46, ‖∇f‖ = 6.2e-23
White arrows = direction of ∇f (uphill, perpendicular to the colour bands). Orange = path of x ← x − η∇f. L = 20: steps above 2/L = 0.1 diverge. Near the limit the path zig-zags across the valley.
Why engineers care

Training an AI model means walking downhill on a “mistake landscape” with millions of directions, by stepping against the gradient again and again. Some robots navigate the same way: they roll downhill on an invisible landscape that’s low at the goal and high around obstacles.

📝 Quick check (Level 0)
0/3 answered
  1. 1. A ball on a hill rolls…
  2. 2. Gradient arrows cross contour lines at…
  3. 3. A longer gradient arrow means the ground is…

Level 1: Beginner

★★☆☆☆ Basic⏱ 15 minSecondary-school mathematics: arithmetic and elementary algebra.

Definition

∇f=(∂f∂x1,…,∂f∂xn)\nabla f = \Big(\frac{\partial f}{\partial x_1},\ldots,\frac{\partial f}{\partial x_n}\Big)

Examples.

  • ∇(x2+y2)=(2x,2y)\nabla(x^2 + y^2) = (2x, 2y) points straight away from the origin. At (3,4)(3,4), it is (6,8)(6,8), with length 10.
  • ∇(3x−2y)=(3,−2)\nabla(3x - 2y) = (3,-2) is the same arrow everywhere, because the function is a tilted plane.
  • At a minimum, maximum or saddle, ∇f=0\nabla f = \mathbf 0.

Three facts (proved at Level 3):

  1. ∇f\nabla f points in the direction of steepest ascent.
  2. ∥∇f∥\lVert\nabla f\rVert is that steepest rate.
  3. ∇f\nabla f is perpendicular to the level set through the point.
📝 Quick check (Level 1)
0/3 answered
  1. 1. ∇(x² + y²) at (1, 2)?
  2. 2. |∇(x² + y²)| at (3, 4)?
  3. 3. ∇f at a minimum is…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 40 minUndergraduate students and practising engineers.

Tangent lines and normals from the gradient

Because ∇f(p)\nabla f(\mathbf p) is normal to the level set, the tangent line (or tangent plane, in 3-D) of {f=c}\{f = c\} at p\mathbf p is

∇f(p)⋅(x−p)=0\nabla f(\mathbf p)\cdot(\mathbf x - \mathbf p) = 0

For the circle x2+y2=25x^2 + y^2 = 25 at (3,4)(3,4): 6(x−3)+8(y−4)=06(x-3) + 8(y-4) = 0, which is 3x+4y=253x + 4y = 25, with slope −34-\tfrac34. The unit normal is ∇f/∥∇f∥=(0.6,0.8)\nabla f/\lVert\nabla f\rVert = (0.6, 0.8). This is how renderers shade implicit surfaces, and how robots get contact normals from signed distance fields.

Gradient descent

xk+1=xk−η ∇f(xk)\mathbf x_{k+1} = \mathbf x_k - \eta\,\nabla f(\mathbf x_k)

For an LL-smooth ff (curvature at most LL), any step η<2/L\eta<2/L decreases ff near a minimum, and η=1/L\eta = 1/L is safe everywhere (the descent lemma, A3.1-4). With uneven curvature (a long, narrow valley, κ=L/μ\kappa = L/\mu large), the gradient points mostly across the valley, so the iterates zig-zag. That is why conditioning matters (A2.3-8).

🐍 Exercise 1: numerical gradients and gradient descent
Compute gradients numerically and implement gradient descent. On x² + 10y² (L = 20), confirm η = 0.09 converges and η = 0.11 explodes, and count the steps with η = 1/L.
📝 Quick check (Level 2)
0/3 answered
  1. 1. The slope of the tangent to x² + y² = 25 at (3, 4)?
  2. 2. One gradient step on x² + y² from (1, 1) with η = 0.25 gives x = ?
  3. 3. The largest stable η for x² + 10y²?

Level 3: Advanced

★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.

Proofs of the three facts

Steepest ascent and its rate. For unit u\mathbf u, Duf=∇f⋅u≤∥∇f∥D_{\mathbf u}f = \nabla f\cdot\mathbf u\le\lVert\nabla f\rVert by Cauchy–Schwarz, with equality iff u=∇f/∥∇f∥\mathbf u = \nabla f/\lVert\nabla f\rVert. ∎

Orthogonality to level sets. Let r(t)\mathbf r(t) be any curve inside {f=c}\{f = c\}. Then f(r(t))=cf(\mathbf r(t)) = c for all tt. The chain rule (A3.2-4) gives ∇f(r(t))⋅r′(t)=0\nabla f(\mathbf r(t))\cdot\mathbf r'(t) = 0. So the gradient is perpendicular to every tangent direction of the level set. ∎

Gradient flow decreases f. Along x˙=−∇f(x)\dot{\mathbf x} = -\nabla f(\mathbf x): ddtf(x(t))=∇f⋅x˙=−∥∇f∥2≤0\frac{d}{dt}f(\mathbf x(t)) = \nabla f\cdot\dot{\mathbf x} = -\lVert\nabla f\rVert^2\le0, with equality only at critical points. ∎ Gradient descent is the Euler discretization of this flow (Practice Code 4).

“Steepest” depends on how you measure distance

The gradient is the steepest direction for the Euclidean length of a step. If step length is measured by ∥d∥M=d⊤Md\lVert\mathbf d\rVert_M = \sqrt{\mathbf d^\top M\mathbf d}, the steepest direction becomes M−1∇fM^{-1}\nabla f. Choosing M=∇2fM = \nabla^2f gives Newton’s method. Choosing the Fisher information gives the natural gradient (Amari, 1998). Preconditioners like Adam use cheap diagonal approximations. Practice Code 5 shows one preconditioned step solving a valley that takes plain descent 882 steps.

Exercise 3.1: Show that gradient descent with optimal fixed step on ½xᵀAx contracts by (κ−1)/(κ+1)

In the eigenbasis, each coordinate is multiplied by 1−ηλi1 - \eta\lambda_i. The best η=2λmin⁡+λmax⁡\eta = \frac2{\lambda_{\min} + \lambda_{\max}} balances the extremes, giving max⁡∣1−ηλi∣=κ−1κ+1\max\lvert1 - \eta\lambda_i\rvert = \frac{\kappa - 1}{\kappa + 1}.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Along the gradient flow with ‖∇f‖ = 3, df/dt = ?
  2. 2. The orthogonality proof uses…
  3. 3. With metric M, steepest descent moves along…

Level 4: Expert

★★★★★ Expert⏱ 40 minResearchers: original papers and open problems.

Potential fields: robots that roll downhill

Khatib (1986) proposed letting a robot follow −∇U-\nabla U, where U=Uatt+UrepU = U_{\text{att}} + U_{\text{rep}}. Here Uatt=12k∥x−g∥2U_{\text{att}} = \tfrac12k\lVert\mathbf x - \mathbf g\rVert^2 pulls toward the goal, and UrepU_{\text{rep}} grows near obstacles. It is fast and reactive, and still used for local collision avoidance on manipulators and drones. Its known flaw is spurious local minima where ∇U=0\nabla U = 0 away from the goal (Koditschek and Rimon’s navigation functions fix this for some environments).

🐍 Exercise 2 (research): potential-field navigation and its trap
Implement the attractive-plus-repulsive gradient and follow −∇U past two obstacles to the goal. Then put an obstacle exactly on the straight line and watch the robot stall where ∇U = 0.

The gradient in modern research

  • Deep learning is gradient descent at scale. Stochastic gradients (Robbins and Monro, 1951), momentum (Polyak, 1964), and adaptive preconditioning (Adam; Kingma and Ba, 2015) are all ways of choosing a better step from ∇L\nabla L.
  • Convergence theory. For μ\mu-strongly convex, LL-smooth ff, gradient descent with η=1/L\eta = 1/L converges linearly at rate 1−μ/L1 - \mu/L. For non-convex ff, it finds ∥∇f∥≤ε\lVert\nabla f\rVert\le\varepsilon in O(1/ε2)O(1/\varepsilon^2) steps (Nesterov, 2004).
  • Trajectory optimization. CHOMP and TrajOpt move whole robot trajectories along functional gradients of smoothness-plus-obstacle costs (Ratliff et al., 2009). Diffusion policies denoise actions using learned gradients of log-densities, called score functions (Chi et al., 2023).
  • Adversarial examples. The fast gradient sign method perturbs an input by ϵsign⁡(∇xL)\epsilon\operatorname{sign}(\nabla_{\mathbf x}L) (Goodfellow, Shlens and Szegedy, 2015). The gradient with respect to the input reveals a model’s most sensitive direction.

References

  1. A.-L. Cauchy (1847). “Méthode générale pour la résolution des systèmes d’équations simultanées.” Comptes rendus, 25. (Gradient descent.)
  2. O. Khatib (1986). “Real-time obstacle avoidance for manipulators and mobile robots.” IJRR, 5(1).
  3. D. Koditschek, E. Rimon (1990). “Robot navigation functions on manifolds with boundary.” Advances in Applied Mathematics, 11(4).
  4. S. Amari (1998). “Natural gradient works efficiently in learning.” Neural Computation, 10(2).
  5. Y. Nesterov (2004). Introductory Lectures on Convex Optimization. Springer.
  6. D. Kingma, J. Ba (2015). “Adam: A method for stochastic optimization.” ICLR.
  7. I. Goodfellow, J. Shlens, C. Szegedy (2015). “Explaining and harnessing adversarial examples.” ICLR.
  8. C. Chi, S. Feng, Y. Du, Z. Xu, E. Cousineau, B. Burchfiel, S. Song (2023). “Diffusion policy: Visuomotor policy learning via action diffusion.” RSS.