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

Partial Derivatives and Directional Derivatives

How fast does a function change if you nudge just one input, or move in any chosen direction? Partial derivatives measure the sensitivity to each knob, and directional derivatives combine them. They are the building blocks of gradients, Jacobians and every gradient-based learning algorithm.

Level 0: Foundation

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

How steep, in which direction?

Stand on a hillside. If you step east, the ground might rise steeply. Step north and it might be almost flat. Step north-east and you get something in between. A slope on a surface depends on the direction you walk.

The slope going purely east (only xx changes) is the partial derivative with respect to xx. The slope in any chosen direction is the directional derivative.

Partial and directional derivatives: slice the surface, read the slope
slice t ↦ f(p + t u)
∂f/∂x = 1.600, ∂f/∂y = 4.000 · D_u f = ∂f/∂x·cos θ + ∂f/∂y·sin θ = 3.386 · steepest possible = |∇f| = 4.308
Black arrow = your direction u; orange arrow = the steepest-ascent direction (the gradient). θ = 0° gives ∂f/∂x, θ = 90° gives ∂f/∂y. The green line in the right panel is the tangent of the slice; its slope is D_u f.
Why engineers care

A robot arm has several joints. Engineers ask: “if I turn only the shoulder a tiny bit, how far does the hand move?” and “what about only the elbow?”. Those are partial derivatives. They tell the controller which joint to use for each motion.

📝 Quick check (Level 0)
0/3 answered
  1. 1. On a perfectly flat table, the slope in every direction is…
  2. 2. The ground rises at slope 2 going east. Going west, the slope is…
  3. 3. A partial derivative changes how many inputs at once?

Level 1: Beginner

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

Partial derivatives

∂f∂x(x,y)=lim⁡h→0f(x+h,y)−f(x,y)h\frac{\partial f}{\partial x}(x,y) = \lim_{h\to0}\frac{f(x+h,y) - f(x,y)}h

Recipe: treat every other variable as a constant and differentiate as usual (A3.1-2).

Example. f(x,y)=x2y+3yf(x,y) = x^2y + 3y:

  • fx=2xyf_x = 2xy, since yy is a constant and 3y3y vanishes.
  • fy=x2+3f_y = x^2 + 3.

At (1,2)(1,2), both equal 4.

Notation: ∂f∂x=fx=∂xf\frac{\partial f}{\partial x} = f_x = \partial_xf. The partial derivatives with respect to each input are the slopes along the coordinate axes.

📝 Quick check (Level 1)
0/3 answered
  1. 1. f = x²y + 3y: f_x at (1, 2)?
  2. 2. f = 3x + 5y: f_y = ?
  3. 3. f = x² + y²: f_x at (3, 4)?

Level 2: Intermediate

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

Directional derivatives

For a unit vector u\mathbf u:

Duf(p)=lim⁡t→0f(p+tu)−f(p)t=∇f(p)⋅u=fxu1+fyu2D_{\mathbf u}f(\mathbf p) = \lim_{t\to0}\frac{f(\mathbf p + t\mathbf u) - f(\mathbf p)}t = \nabla f(\mathbf p)\cdot\mathbf u = f_xu_1 + f_yu_2

The last equality holds for differentiable ff. You only need the nn partial derivatives to get the slope in every direction. For example, with f=x2y+3yf = x^2y + 3y at (1,2)(1,2) and u=(0.6,0.8)\mathbf u = (0.6, 0.8): 4⋅0.6+4⋅0.8=5.64\cdot0.6 + 4\cdot0.8 = 5.6.

By Cauchy–Schwarz, Duf≤∥∇f∥D_{\mathbf u}f\le\lVert\nabla f\rVert, with equality when u\mathbf u points along ∇f\nabla f. That makes the gradient the direction of steepest ascent (A3.2-3).

Higher partials and Clairaut’s theorem

fxy=∂y(∂xf)f_{xy} = \partial_y(\partial_xf). For f=x3y2f = x^3y^2: fx=3x2y2f_x = 3x^2y^2, so fxy=6x2yf_{xy} = 6x^2y. Computing in the other order, fy=2x3yf_y = 2x^3y and fyx=6x2yf_{yx} = 6x^2y. They agree, which is Clairaut’s (Schwarz’s) theorem: if the second partials are continuous, the order doesn’t matter. That’s why the Hessian (A3.2-6) is symmetric.

Partials on a computer

A central difference in coordinate ii costs 2 evaluations, so a full gradient costs 2n2n (or n+1n+1 with forward differences). For a network with 10910^9 parameters that’s hopeless, which is why we use automatic differentiation (A3.1-2, A3.3).

🐍 Exercise 1: partial and directional derivatives numerically
Compute partials by central differences, and directional derivatives straight from the definition. Check D_u f = ∇f · u in 3-D.
📝 Quick check (Level 2)
0/3 answered
  1. 1. x²y + 3y at (1, 2), u = (0.6, 0.8): D_u f = ?
  2. 2. The largest directional derivative of x² + y² at (3, 4)?
  3. 3. f_xy for x³y² at (1, 1)?

Level 3: Advanced

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

Partials existing is not enough

f(x,y)=xyx2+y2f(x,y) = \frac{xy}{x^2+y^2} (with f(0,0)=0f(0,0) = 0) has fx(0,0)=fy(0,0)=0f_x(0,0) = f_y(0,0) = 0, since ff is 0 on both axes. Yet f(t,t)=12f(t,t) = \frac12, so ff isn’t even continuous at the origin. Partials only look along two lines.

Differentiability: the right definition

ff is differentiable at p\mathbf p if there is a linear map, the gradient, with

f(p+h)=f(p)+∇f(p)⋅h+o(∥h∥)f(\mathbf p + \mathbf h) = f(\mathbf p) + \nabla f(\mathbf p)\cdot\mathbf h + o(\lVert\mathbf h\rVert)

This is the tangent-plane approximation (A3.2-7). Theorem: if the partials exist near p\mathbf p and are continuous at p\mathbf p, then ff is differentiable there. If ff is differentiable, then Duf=∇f⋅uD_{\mathbf u}f = \nabla f\cdot\mathbf u. Proof: set h=tu\mathbf h = t\mathbf u, divide by tt and let t→0t\to0. ∎

When Clairaut fails

f=xy(x2−y2)x2+y2f = \frac{xy(x^2-y^2)}{x^2+y^2} (with f(0,0)=0f(0,0) = 0) has fxy(0,0)=−1f_{xy}(0,0) = -1 but fyx(0,0)=1f_{yx}(0,0) = 1. Its second partials aren’t continuous at the origin. In practice (smooth losses, physical models), Clairaut holds.

Exercise 3.1: Compute D_u f for f = eˣ sin y at (0, π/2) in the direction (1, 1)

∇f=(exsin⁡y,excos⁡y)=(1,0)\nabla f = (e^x\sin y, e^x\cos y) = (1, 0). With u=(1,1)/2\mathbf u = (1,1)/\sqrt2, Duf=1/2≈0.7071D_{\mathbf u}f = 1/\sqrt2\approx0.7071.

📝 Quick check (Level 3)
0/3 answered
  1. 1. If both partials exist at p, then f is…
  2. 2. D_u f when u ⊥ ∇f?
  3. 3. Clairaut's theorem needs…

Level 4: Expert

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

Derivatives without formulas: zeroth-order methods

When ff is a black box, such as a physics simulator, a real robot trial or a hardware-in-the-loop test, you can only evaluate it. SPSA (simultaneous perturbation stochastic approximation; Spall, 1992) estimates the gradient from a single directional derivative along a random ±1\pm1 direction Δ\boldsymbol\Delta:

g^=f(x+cΔ)−f(x−cΔ)2c Δ,E[g^]≈∇f\hat{\mathbf g} = \frac{f(\mathbf x + c\boldsymbol\Delta) - f(\mathbf x - c\boldsymbol\Delta)}{2c}\,\boldsymbol\Delta, \qquad \mathbb E[\hat{\mathbf g}]\approx\nabla f

It costs 2 evaluations whatever the dimension. Gaussian-smoothing variants (Nesterov and Spokoiny, 2017) and evolution strategies (Salimans et al., 2017) use the same idea to train policies in parallel. On a smooth, cheap function, coordinate finite differences are more accurate per evaluation (Exercise 2). Zeroth-order methods shine when evaluations are noisy or very high-dimensional.

🐍 Exercise 2 (research): finite differences vs SPSA in 50 dimensions
Estimate the gradient of a 50-D quadratic with coordinate finite differences (51 evaluations) and with SPSA (2 per sample), and compare their accuracy.

Sensitivity everywhere

  • Robot kinematics. The partials ∂x/∂θi\partial\mathbf x/\partial\theta_i form the columns of the manipulator Jacobian (A3.2-5). They decide which joint to move, and they reveal singular poses where a direction becomes unreachable (A2.3-7).
  • Forward-mode autodiff computes one directional derivative (a Jacobian–vector product) per pass, at about the cost of one function evaluation (A3.1-2, A3.3).
  • Sensitivity analysis in engineering design. ∂(mass)/∂(thicknessi)\partial(\text{mass})/\partial(\text{thickness}_i) guides structural optimization of aircraft and spacecraft parts. Adjoint methods compute all of these at once (Jameson, 1988), the same trick as backprop.
  • Feature attribution. “Saliency maps” are partial derivatives of a classifier’s output with respect to each input pixel (Simonyan, Vedaldi and Zisserman, 2014).

References

  1. A. Clairaut (1740); H. A. Schwarz (1873). On the symmetry of mixed partial derivatives.
  2. A. Jameson (1988). “Aerodynamic design via control theory.” Journal of Scientific Computing, 3.
  3. J. Spall (1992). “Multivariate stochastic approximation using a simultaneous perturbation gradient approximation.” IEEE Transactions on Automatic Control, 37(3).
  4. K. Simonyan, A. Vedaldi, A. Zisserman (2014). “Deep inside convolutional networks: visualising image classification models and saliency maps.” ICLR Workshop.
  5. Y. Nesterov, V. Spokoiny (2017). “Random gradient-free minimization of convex functions.” Foundations of Computational Mathematics, 17.
  6. T. Salimans, J. Ho, X. Chen, S. Sidor, I. Sutskever (2017). “Evolution strategies as a scalable alternative to reinforcement learning.” arXiv:1703.03864.
  7. W. Rudin (1976). Principles of Mathematical Analysis, 3rd ed. Chapter 9.