Calculus, Linear Algebra & Discrete Math Multivariable & Vector Calculus Directional derivative Dᵤf = ∇f · u

Directional Derivative Calculator

Enter a function of two or three variables, a point and a direction vector, and this calculator returns the directional derivative Dᵤf = ∇f · u at that point. It normalises your direction vector for you — the most common source of a wrong answer is forgetting to — and reports the gradient, the largest rate of change available at that point, and the angle between the direction you asked for and the direction of steepest ascent.

Calculator

This calculator runs in your browser. Enable JavaScript for live results — the inputs, formula and worked example below remain fully readable without it.

Inputs this calculator takes, with typical values
InputWhat to enterExample
Function fUse x, y and z. Available: + - * / ^, sin, cos, exp, ln, sqrt, abs, pi, e.x^2 + y^2
Number of variablesChoosing two fixes z at 0 and ignores the z-component of the direction.Two — f(x, y)
x at the point PFirst coordinate of the point where the rate is measured.1
y at the point PSecond coordinate of the point.2
z at the point PThird coordinate; used only with three variables.0
Direction vₓThe vector need not be a unit vector; it is normalised before use.3
Direction v_ySecond component of the direction vector.4
Direction v_zThird component; used only with three variables.0

It returns

  • Directional derivative Dᵤf(P) — Rate of change of f per unit distance travelled in your direction.
  • Maximum rate of change |∇f(P)| — The largest directional derivative available at this point, attained along ∇f.
  • ∂f/∂x at P
  • ∂f/∂y at P
  • ∂f/∂z at P
  • Angle between your direction and ∇f — 0° means you are heading straight uphill; 90° means f does not change in that direction.

The formula

Duf(P)=f(P)v|v|
Duf=|f|cosθ

In plain text: Dᵤf(P) = ∇f(P) · u, where u = v / |v|

  • DᵤfRate of change of f per unit distance moved in the direction u
  • ∇fGradient vector, (∂f/∂x, ∂f/∂y, ∂f/∂z)
  • vThe direction you supply, of any length
  • uThe unit vector in that direction, v divided by its own length

Because u is a unit vector, Dᵤf is a rate per unit distance. Using an unnormalised v scales the answer by |v| and is the most frequent error on this topic.

Updated Category Multivariable & Vector Calculus Verified against published test cases Reading time 11 min

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.

  1. Take the partial derivatives. ∂f/∂x = 2x and ∂f/∂y = 2y.
  2. Evaluate them at P. ∇f(1, 2) = (2·1, 2·2) = (2, 4).
  3. Normalise the direction. |v| = √(3² + 4²) = √25 = 5, so u = (3/5, 4/5) = (0.6, 0.8).
  4. Take the dot product. Dᵤf = 2(0.6) + 4(0.8) = 1.2 + 3.2 = 4.4.
  5. Find the maximum rate. |∇f| = √(2² + 4²) = √20 = 4.472136, attained in the direction ∇f/|∇f| = (0.4472, 0.8944).
  6. 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

Dᵤf = |∇f| cos θ, so the fraction of the best available rate depends only on the angle from the gradient.
Angle θ from ∇fcos θFraction of |∇f|Meaning
1.000100%Steepest ascent
30°0.86686.6%Little is lost near the optimum
45°0.70770.7%Halfway to level in angle, not in rate
60°0.50050%Half the maximum rate
90°0.0000%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.

Frequently asked questions

Do I have to use a unit vector?

Yes, and this calculator does it for you. Dᵤf is a rate of change per unit distance, so the direction has to be scaled to length one. Dotting the gradient with an unnormalised vector multiplies the answer by that vector's length: with v = (3,4) the result comes out five times too large. The calculator reports the length it divided by so you can see the correction.

What is the difference between the gradient and the directional derivative?

The gradient is a vector whose components are the partial derivatives; the directional derivative is a single number, the component of that vector along your chosen direction. One gradient generates every directional derivative at the point through Dᵤf = ∇f·u. The gradient's magnitude is the largest directional derivative available, and its direction is where that maximum occurs.

What does a negative directional derivative mean?

That f decreases as you move in that direction, at the rate given by the magnitude. It happens whenever the angle between your direction and the gradient exceeds 90°. The most negative possible value is −|∇f|, attained by heading exactly opposite the gradient — which is the direction gradient descent takes.

How do I enter a direction given as an angle?

Convert it to components: a direction θ measured anticlockwise from the positive x-axis is the vector (cos θ, sin θ). For 30°, enter vₓ = 0.866025 and v_y = 0.5. Since the calculator normalises anyway, any positive multiple of that pair works equally well.

Why is the maximum rate equal to the magnitude of the gradient?

Because Dᵤf = ∇f·u = |∇f||u|cos θ, and |u| = 1, so the value is |∇f|cos θ. That is largest when cos θ = 1, which happens when u points along ∇f, and its value there is |∇f|. The same expression gives the minimum, −|∇f|, in the opposite direction.

What happens at a point where the gradient is zero?

Every directional derivative is zero, so the surface is momentarily flat in every direction. That is a critical point — a maximum, a minimum or a saddle — and first derivatives cannot tell you which. The angle to the gradient is undefined rather than zero, since the zero vector has no direction, and the calculator reports it as unavailable.

Can the directional derivative exist when the partial derivatives do not describe the function?

Yes, and this is the standard cautionary example. There are functions whose partial derivatives both exist and are zero at the origin, yet which have non-zero directional derivatives along other lines, because they are not differentiable there. The formula Dᵤf = ∇f·u requires differentiability, not merely the existence of partials. For every function you are likely to type here, differentiability holds.

Does the directional derivative tell me how much f changes if I move a metre?

Only approximately, and only for small steps. Dᵤf is the instantaneous rate at P, so f(P + hu) ≈ f(P) + h·Dᵤf is a first-order estimate whose error grows like . Over a finite distance the gradient itself changes, and the honest answer is the line integral of the gradient along the path you take.

How do I get the tangent plane to a surface from this?

Write the surface as a level set g(x, y, z) = c. Because the gradient is perpendicular to every direction that stays on the level set, ∇g(P) is a normal vector to the surface at P, and the tangent plane is ∇g(P)·(r − P) = 0. Compute ∇g here or on the gradient vector calculator and read the components straight off.

References