Partial Derivatives & Gradients
Partial derivatives measure how a function changes when one input moves and the others stay fixed. The gradient collects those rates into a vector. For a differentiable function, a nonzero gradient points toward the greatest local increase per unit distance. A zero gradient alone does not prove a minimum.
Imagine adjusting two model parameters. You could try a small change to each one separately, but eventually you need to move both. The gradient lets you combine those two measurements. It is a local forecast, though. A forecast for a small move is not a promise about a long trip.
How Partial Derivatives Form a Gradient
Start with f(x,y) = x² + 2y². A contour joins input pairs that produce the same output. The
two axes are inputs; the number written on a contour is the output. That distinction matters:
moving upward on this map changes y, not necessarily f.
To measure the x partial at p = (x₀,y₀), freeze y at y₀. The function becomes a one-variable
slice, f(x,y₀). Its derivative is ∂f/∂x = 2x₀. The symbol ∂ reminds you that other inputs
are being held fixed. Freezing x instead gives ∂f/∂y = 4y₀.
You can approach either derivative with secants. The right x secant is
[f(x₀+h,y₀) − f(p)] / h = 2x₀+h; the left one is 2x₀−h. Let h tend to zero and both
approach 2x₀. A finite secant is an average rate over an interval. The derivative is its
limit, not merely the last small sample you happened to calculate.
Put the coordinate rates in coordinate order:
∇f(p) = (∂f/∂x, ∂f/∂y).
For a small displacement δ = (δx,δy), differentiability gives the linear prediction
Δf ≈ (∂f/∂x)δx + (∂f/∂y)δy = ∇f(p) · δ. Each component earns its place by measuring the
effect of that coordinate. Adding the two partials without accounting for the displacement
would silently assume a particular move.
Write the displacement as δ = εu, where ‖u‖ = 1. The directional derivative is then
Dᵤf(p) = ∇f(p) · u, and the predicted change is εDᵤf. The direction tells you which way;
ε tells you how far. This lesson uses equal, dimensionless coordinate units and ordinary
Euclidean distance. Changing the coordinate scale can change what “steepest” means.
Partial Derivatives & Gradients Step by Step
The default uses the bowl f(x,y) = x² + 2y², the base point (1,1), and a direction 45°
counterclockwise from +x. The base output is 3.
-
Freeze y at 1. The x slice is
x²+2. Withh = 0.5, the left and right secant slopes are 1.5 and 2.5. Withh = 0.05, they are 1.95 and 2.05. The exact x partial is 2. -
Freeze x at 1. The y slice is
1+2y². The corresponding slopes are 3 and 5, then 3.9 and 4.1. Their limit is 4. -
Assemble the vector.
∇f(1,1) = (2,4). Its length is√20 ≈ 4.472136. -
Predict a diagonal move. The unit direction is
u = (1/√2,1/√2). Its local rate is2/√2 + 4/√2 = 3√2 ≈ 4.242641. At distanceε = 0.2, the predicted change is 0.848528. -
Check the function. Compare the prediction with the actual change at the same distance. Then reduce ε from 0.2 to 0.02. Which distance gives the closer forecast?
Distance ε Predicted Δf Actual Δf Absolute error 0.2 0.848528 0.908528 0.06 0.02 0.084853 0.085453 0.0006 These displayed values are rounded. For this quadratic, one tenth of the distance gives one hundredth of the error.
-
Compare equal unit directions. Perpendicular to
(2,4), the local rate is 0. Rotate toward the gradient: the angle φ closes to 0° and the rate reaches√20 ≈ 4.472136. This direction is about 63.435° from +x. Reversing it makes φ = 180° and the rate−√20. A sufficiently small step in that opposite direction reduces the loss. -
Check the zero-gradient boundary. In a new experiment, compare the bowl and saddle
x²−2y²at the origin. Both have gradient(0,0). An x move of 0.2 raises both by 0.04; a y move of 0.2 raises the bowl by 0.08 but lowers the saddle by 0.08. The saddle is not a minimum. For the bowl,x²+2y² ≥ 0proves the minimum; the zero gradient alone does not.
During the direction experiment, the base point stays fixed. A dashed normalized gradient reference shares the map with the unit arrow; the angle arc and signed rate gauge connect the rotation to its effect. The separate component diagram preserves the gradient's actual magnitude. Result beats hold the prediction and measurements before the next experiment. The closing pair of maps gives both functions the same coordinate scale.
Why Does the Gradient Point Toward the Steepest Increase?
The dot product supplies the argument: ∇f · u = ‖∇f‖ cos φ for a unit u, where φ is the
angle between the vectors. Since cos φ ≤ 1, no unit direction can exceed ‖∇f‖. When the
gradient is nonzero, choosing u = ∇f/‖∇f‖ attains the bound. Choosing the opposite direction
attains the minimum, −‖∇f‖.
This is also why gradient descent moves opposite the gradient. The usual update
p ← p − η∇f(p) uses a displacement of length η‖∇f‖; η is not the distance ε used in this
lesson. A sufficiently small step along the negative gradient decreases a differentiable
function when the gradient is nonzero. A large step can cross the low point and climb again.
For the two functions here, write f(x,y) = x² + 2s y², with s = +1 for the bowl and −1 for
the saddle. The exact finite change is
Δf = ε(∇f · u) + ε²(uₓ² + 2s uᵧ²). The second term is the missing remainder. Reducing ε
by ten reduces its magnitude by one hundred. That quadratic error rate belongs to these
quadratics; differentiability by itself does not guarantee it for every function.
Edge Cases
- One partial is zero. At
(0,1)on the bowl, the x partial is 0 but the y partial is 4. The gradient still has a direction. - A zero directional rate can hide finite change. At that same point, a horizontal move has zero first-order prediction. Moving 0.2 still raises f by 0.04. A straight step along a contour's tangent need not remain on the contour.
- A zero gradient need not be a minimum. The saddle
x²−2y²has gradient(0,0)at the origin. Moving 0.2 along x raises f by 0.04; moving 0.2 along y lowers it by 0.08. All local directional derivatives there are zero, yet nearby values go both ways. - A stationary minimum needs additional evidence. The bowl also has gradient
(0,0)at the origin. Herex²+2y² ≥ 0proves the minimum. Two positive test moves alone would not prove a minimum for an arbitrary function. - Partials are not the whole differentiability test. Some functions have partial derivatives at a point without a valid linear approximation there. Both polynomial functions in this lesson are differentiable everywhere.
Common Mistakes
- Changing both coordinates while calling the result an x partial. Freeze the other inputs.
- Treating
∇fas a scalar or swapping its coordinates. The vector preserves which rate belongs to which input. - Comparing raw direction vectors of different lengths. Normalize them before claiming a greater rate per unit distance.
- Equating the linear prediction with every finite change. Check the remainder or shrink the displacement.
- Normalizing a zero gradient or declaring it a minimum. There is no unique steepest unit direction there; the neighboring function values decide what kind of point it is.
Keep exploring
A few lessons that share the same technique or lead into the next idea.
Found a mistake or something unclear? Leave feedback.