What a directional derivative measures
A partial derivative tells you how fast f changes as you move parallel to one coordinate axis. A directional derivative answers the same question for any direction you choose. Standing at a point on a hillside whose height is f(x, y), ∂f/∂x is the slope due east and ∂f/∂y the slope due north; Dᵤf is the slope in whatever compass direction you decide to walk.
The formula is remarkably economical: Dᵤf = ∇f · u. Two numbers in two dimensions, or three in three, encode the slope in every possible direction. That is not obvious and it is not true of arbitrary functions — it holds because a differentiable function is locally linear, so the slopes in different directions must combine linearly rather than independently.
The unit in the unit vector is the whole reason the answer means anything. Dᵤf is a rate per unit distance travelled, so the direction vector must be scaled to length one before the dot product. Feeding in v = (3, 4) without normalising gives an answer five times too large, and because that answer is still a plausible-looking number nothing warns you. This calculator normalises automatically and tells you what length it divided by.
Why the gradient controls every direction
Start from the definition: Dᵤf(P) = lim(h→0) [f(P + hu) − f(P)]/h. Apply the chain rule to g(h) = f(P + hu) and you get g'(0) = ∂f/∂x·u₁ + ∂f/∂y·u₂ + ∂f/∂z·u₃, which is precisely ∇f·u. The derivation needs f to be differentiable at P, not merely to have partial derivatives there — a distinction that matters, because functions exist whose partials all vanish at a point while directional derivatives along other directions do not.
Writing the dot product in its geometric form, Dᵤf = |∇f||u|cos θ = |∇f| cos θ, gives every fact worth knowing at once. The rate is largest when cos θ = 1, that is when you head along ∇f, and its value there is |∇f|. It is most negative along −∇f, with value −|∇f|. It is zero when θ = 90°, which means the gradient is perpendicular to the level curve or level surface through the point — walk along a contour and your height does not change.
So the gradient answers three questions simultaneously: which way is steepest uphill, how steep that is, and which directions are level. It is also why gradient descent works: −∇f is the locally best direction to reduce f, and no other direction can beat it at first order.
The partial derivatives here are computed numerically, one coordinate at a time, with a central difference at a step of 10⁻⁴ scaled to the size of that coordinate, then Richardson-extrapolated to fourth-order accuracy. For a smooth function that is good to roughly twelve significant figures, which is far tighter than the precision displayed.
Worked example: f(x, y) = x² + y² at (1, 2) in the direction (3, 4)
Every step is exact arithmetic; check it against the output above.
- Take the partial derivatives. ∂f/∂x = 2x and ∂f/∂y = 2y.
- Evaluate them at P. ∇f(1, 2) = (2·1, 2·2) = (2, 4).
- Normalise the direction. |v| = √(3² + 4²) = √25 = 5, so u = (3/5, 4/5) = (0.6, 0.8).
- Take the dot product. Dᵤf = 2(0.6) + 4(0.8) = 1.2 + 3.2 = 4.4.
- Find the maximum rate. |∇f| = √(2² + 4²) = √20 = 4.472136, attained in the direction ∇f/|∇f| = (0.4472, 0.8944).
- Compare. 4.4 is 98.4% of the best available 4.472136, because cos θ = 4.4/4.472136 = 0.983870 and θ ≈ 10.3°. Your chosen direction is only about ten degrees off the steepest route, which is why you lose so little.
Two checks worth running on any answer of this kind. First, the opposite direction: u = (−0.6, −0.8) gives Dᵤf = −4.4, equal in size and opposite in sign, because the dot product is linear in u. Second, a level direction: rotating ∇f = (2, 4) by ninety degrees gives (−4, 2), and Dᵤf along that is 2(−4/√20) + 4(2/√20) = (−8 + 8)/√20 = 0 exactly — the tangent to the circle x² + y² = 5, along which f is constant by construction.
Now the mistake. If you skip normalisation and dot ∇f with (3, 4) directly, you get 2(3) + 4(4) = 22. That is 5 × 4.4, exactly the length of v times the true answer. It is not a rate per unit distance, and nothing about the number 22 signals that it is wrong.
Reading the result
The sign tells you uphill or downhill. A positive directional derivative means f increases as you move that way; negative means it decreases; zero means you are moving along a level curve, at least instantaneously. The magnitude is a rate per unit distance in whatever units the problem carries — degrees per metre for a temperature field, metres of rise per metre travelled for a terrain model.
Compare the value with |∇f| to see how efficient your direction is. Their ratio is cos θ, and the angle is reported. Below about 30° you are getting more than 86% of the maximum available rate; at 60° you get half; at 90° nothing. That is the practical content of the cosine: near the optimum, direction errors cost very little, which is why gradient descent tolerates inexact search directions.
A gradient magnitude of zero is a special case and the calculator says so. At a critical point every directional derivative is zero, there is no steepest direction, and the angle is undefined rather than zero. Whether that point is a maximum, a minimum or a saddle needs second derivatives — in one variable that is the critical points question, and in several it is the Hessian test.
Finally, look at the table of standard directions. The entries for +x and −x are the partial derivative and its negative; the largest entry in the column is always |∇f|, attained on the steepest-ascent row. If some other row exceeds it, the gradient has been computed wrongly — a useful self-check that costs nothing.
Reference: how much of the maximum rate a direction delivers
| Angle θ from ∇f | cos θ | Fraction of |∇f| | Meaning |
|---|---|---|---|
| 0° | 1.000 | 100% | Steepest ascent |
| 30° | 0.866 | 86.6% | Little is lost near the optimum |
| 45° | 0.707 | 70.7% | Halfway to level in angle, not in rate |
| 60° | 0.500 | 50% | Half the maximum rate |
| 90° | 0.000 | 0% | Along the level curve; f is unchanging |
| 120° | −0.500 | −50% | Descending at half the steepest rate |
| 180° | −1.000 | −100% | Steepest descent |
The near-flatness of the cosine near 0° is the reason a 10° error in direction costs only 1.5% of the rate, while a 10° error near 90° changes the rate from 0 to 17% of the maximum. Direction accuracy matters least where the rate is largest.
Mistakes and assumptions
- Not normalising the direction vector. The single most common error, and the answer stays plausible. Dᵤf is defined for unit u only; anything else is not a rate per unit distance.
- Confusing the gradient with the directional derivative. The gradient is a vector; the directional derivative is a scalar obtained by dotting it with a unit vector.
- Assuming that having all partial derivatives is enough. The formula Dᵤf = ∇f·u requires differentiability, which is strictly stronger. Functions exist with both partials zero at the origin and non-zero directional derivatives in other directions.
- Reporting an angle at a critical point. When ∇f = 0 there is no direction of steepest ascent and the angle is undefined, not zero.
- Giving a direction as an angle without converting. A direction of θ from the positive x-axis is the vector (cos θ, sin θ); enter those components.
- Forgetting that the answer is local. Dᵤf describes the rate at the instant you leave P. Travel any finite distance and the gradient has changed.
- Leaving a z-dependence in a two-variable problem. With two variables selected, z is held at 0 and ∂f/∂z is excluded; the calculator warns when the expression actually uses z.
The gradient is perpendicular to level sets
If you move along a level curve, f does not change, so Dᵤf = 0, so ∇f·u = 0 — the gradient is orthogonal to every tangent direction of the level set. That is the fastest way to get the normal vector to a surface g(x, y, z) = c, and hence its tangent plane: the normal is ∇g at the point. It is also the geometric content of the method of Lagrange multipliers, where the gradients of objective and constraint must be parallel at an optimum. The gradient vector calculator reports that normal direction directly.
Where directional derivatives lead
The immediate descendant is gradient descent, the workhorse of numerical optimisation and of machine learning. It moves in the direction −∇f precisely because that is the direction with the most negative directional derivative, and the step size question — how far to travel before the linear approximation stops being useful — is the whole practical difficulty of the method.
In vector calculus the gradient sits alongside two other first-order operators. The divergence measures net outflow of a vector field and the curl measures its rotation. A field that is a gradient always has zero curl, which is the test for whether a potential exists, and it is the multivariable version of "every derivative is the derivative of something".
Numerically, every partial derivative on this page is computed by the finite-difference machinery described on the numerical derivative calculator, one coordinate at a time. The cost of a gradient by finite differences is n + 1 function evaluations in n dimensions, which is affordable for two or three variables and prohibitive for the millions of variables in a modern optimisation problem — hence automatic differentiation.
One assumption to state: everything here is first-order and local. The directional derivative is the coefficient of the linear term in the Taylor expansion of f about P. To know whether a critical point is a maximum, a minimum or a saddle, you need the second-order term, which in several variables is the Hessian matrix and its eigenvalues. The one-variable analogue of that whole story is on the critical points calculator.
