Steepest ascent

Gradient and directional derivative calculator

This tool estimates the gradient of a function of two or three variables at one point. If you also type a direction, it estimates the directional derivative in that direction. You type $f(x,y)$ or $f(x,y,z)$, a point, and an optional direction vector. Each partial derivative is a central difference. The numbers are numerical approximations, not a symbolic derivative.

The estimate is useful when $f$ is smooth near the point, and when the step is small enough that each slice looks like a tangent, yet large enough that rounding does not swallow the change in $f$. The boxes start with step $0.001$.

This is not a computer algebra system. It does not simplify a formula, it does not prove that the partial derivatives exist, and it does not solve a constrained optimization. For the picture of steepest ascent, read multivariable and vector calculus. For why two gradients line up at a constrained optimum, read Lagrange multipliers intuition.

Allowed pieces: numbers, the variables $x$, $y$, and $z$, plus, minus, times, divide, powers, parentheses, and $\sin$, $\cos$, $\tan$, $\mathrm{sqrt}$, $\mathrm{abs}$, $\log$ (natural), $\exp$, $\pi$, $e$. Type them as sin, cos, tan, sqrt, abs, log, exp, pi, e. Write a times sign between variables. The letters xy are not the product x*y.

Point

Direction, optional

Leave every box blank to skip the directional derivative. A zero vector is refused.

Worked examples fill the boxes and compute.

How to use the calculator

The boxes start on a paraboloid check you can do by hand. Leave $f(x,y)=x^{2}+y^{2}$ at $(1,2)$, with direction $(3,4)$ and step $0.001$, and press Compute. The gradient is $(2,4)$. The magnitude is $\sqrt{20}$. The direction has length $5$, so the unit direction is $(3/5,4/5)=(0.6,0.8)$. The directional derivative is $2\cdot 0.6+4\cdot 0.8=4.4$. If the screen disagrees, check the spelling before you trust a harder example.

Pick two or three variables. In two variables the $z$ boxes hide, and an expression that uses $z$ is refused until you switch. Leave the direction blank when you only want the gradient. Fill every component when you want a directional derivative.

The four example buttons each load one worked case and compute it. Paraboloid is the check above. Temperature map and Hill elevation are scalar fields with a story. Three variables adds $z$.

How to read the output

The large line is the gradient, and, when you gave a direction, the directional derivative. Under it, each partial derivative is named, then the magnitude, then the unit vector of steepest ascent. The magnitude is the fastest rate of increase. The unit vector is that direction, with length $1$.

If a direction was typed, the note also shows the unit vector the page actually used, the directional derivative $D_u f$, and the angle between that unit vector and the gradient. A positive directional derivative means $f$ increases as you walk that way. A negative one means $f$ decreases. A value near zero means the direction is level to first order, which is the tangent to a level curve.

Treat the output as a probe. Change the step by a factor of ten and compute again. If the stable digits hold, you are probably near the slope. If they jump, you are seeing rounding, or a kink the tangent cannot settle on. Units still belong to you. A temperature gradient is degrees per unit distance. The page does not know the units.

Worked examples

Paraboloid $f(x,y)=x^{2}+y^{2}$ at $(1,2)$, direction $(3,4)$. This is a bowl with its bottom at the origin. The gradient $(2,4)$ points away from the bottom, and straight up the bowl. The magnitude printed to the usual rounding is $4.472135955$, which is $\sqrt{20}$. The directional derivative is $4.4$.

Temperature map $T(x,y)=70+2x-y$ at $(1,3)$, facing east along $(1,0)$. This is the temperature field from the multivariable pillar, with $x$ east and $y$ north. The gradient is $(2,-1)$ at every point. One unit east raises the reading by $2$. One unit north lowers it by $1$. Facing east, the directional derivative is $2$. The fastest rate of increase is $\sqrt{5}$.

Hill elevation $f(x,y)=100-x^{2}-2y^{2}$ at $(1,1)$, facing east along $(1,0)$. The peak is at the origin, where the height is $100$. At $(1,1)$ the gradient is $(-2,-4)$, which points back toward the peak, not farther downhill. Facing east, the directional derivative is $-2$, so this step loses height.

Three variables $f(x,y,z)=xy+z^{2}$ at $(1,2,3)$, direction $(0,0,1)$. The gradient is $(y,x,2z)=(2,1,6)$. Walking along the positive $z$ axis, the directional derivative is $6$, the same number as the partial derivative with respect to $z$. The partial derivatives in $x$ and $y$ do not contribute, because this direction has no $x$ or $y$ component.

What the gradient is telling you

Stand on a smooth hill and turn until the ground rises fastest under your feet. That facing is the gradient. Its length is the steepness of that facing, in rise per unit of horizontal distance. The partial derivatives are the steepness you would feel if you had to walk parallel to an axis, with the other coordinates held fixed. The gradient packs those axis slopes into the single best facing.

A directional derivative is the steepness along a facing you chose, which may not be the best one. On a smooth hill it equals the steepest slope times the cosine of the angle between your facing and the gradient. Walk straight uphill and the cosine is $1$, so you feel the full magnitude. Walk along a level curve and the cosine is $0$, so the height does not change to first order. Walk downhill and the cosine is negative, so the directional derivative is negative.

That product is a dot product for a small reason, not a new operation. The dot product of two vectors is the product of their lengths and the cosine of the angle between them. The direction in the definition is a unit vector, so its length is $1$ and it drops out. What remains is the magnitude of the gradient times the cosine. Skip the unit length, and the extra factor is the length of the vector you typed. The number stops being a slope per unit distance.

The temperature map is the same geometry with different units. $T(x,y)=70+2x-y$ has gradient $(2,-1)$ everywhere. The hottest facing is along $(2,-1)$, east and somewhat south, and the fastest rate of increase is the length $\sqrt{5}$. Facing due east keeps only the eastern partial derivative, which is $2$. The northern partial derivative is present in the gradient and silent in that particular walk, because you did not move north.

Common mistakes

  • Forgetting to normalize the direction. The directional derivative wants a unit vector. Dotting $(2,4)$ with $(3,4)$ gives $22$, which is $4.4$ times $5$. The extra $5$ is the length of $(3,4)$, not a rate per unit distance. This page divides by that length and shows the unit vector it used. If you normalize twice, once on paper and once by accident in your head, you will not match the screen.
  • Mixing up the gradient and the directional derivative. The gradient is a vector. It has a direction and a length. The directional derivative is one number, the slope in a direction you chose. The number is the dot product of the gradient with a unit vector. They answer different questions. A course that asks for $\nabla f$ wants the vector. A course that asks for $D_u f$ wants the number.
  • Reading a partial derivative as the slope of the whole surface. A partial derivative lets one variable move and holds the others fixed. It is the slope along an axis. The slope along a diagonal is the directional derivative, and it can be larger than either partial derivative. On the paraboloid at $(1,2)$, the partial derivatives are $2$ and $4$, while the steepest slope is $\sqrt{20}$, about $4.47$.
  • Trusting a central difference at a corner. For $|x|+|y|$ at the origin, type abs(x)+abs(y). The samples on the left and right cancel, and the central difference reports a slope near zero. The surface has a kink there. Steepest ascent is not a single vector. If the digits refuse to settle when you change the step, do not treat the output as a derivative.
  • Using the zero vector as a direction. It has no length and no direction. Dividing by its length would be division by zero. The page refuses it. Leave the boxes blank when you only want the gradient.
  • A step that is too large or too small. A step near $1$ follows a long secant on each slice. A step near $10^{-16}$ can make the two sample points the same number in floating point, so the quotient becomes junk. A tail of zeros with a stray last digit, such as $2.0000000001$ when the slope is $2$, is floating point dust. Change the step by a factor of ten. If the stable digits hold, trust those digits.

Related reading

The map of the course is multivariable and vector calculus. The short lines are gradient and partial derivative. Constrained optima, where the gradient of the objective is parallel to the gradient of the constraint, are on Lagrange multipliers intuition. When the output is several numbers rather than one, the derivative is a matrix. That story is Jacobian matrices in plain language.

After the gradient is on your paper, the vector operations calculator checks a dot product, a magnitude, or a unit vector. A field given by components, when you want divergence or curl rather than a gradient, belongs on the divergence and curl calculator. A single variable slope, with every other input held fixed by you, belongs on the numerical derivative calculator.

Disclaimer. Educational estimate only. This page is not a computer algebra system and not a proof. See the site disclaimer and the FAQ on calculators versus understanding.

Common questions

What does the gradient on this page mean?

The gradient is the vector of partial derivatives at the point you typed. Its direction is steepest ascent, and its length is the fastest rate of increase. The entries are central difference estimates, not a symbolic derivative.

Why is the directional derivative a dot product?

A directional derivative is the slope along one chosen direction. On a smooth surface that slope equals the steepest slope times the cosine of the angle between your direction and the gradient. A dot product with a unit vector is exactly that product.

Why does the direction have to be a unit vector?

The directional derivative is a rate per unit distance. If you dot the gradient with a vector of length $5$, you scale the slope by $5$. This page normalizes the direction you type and shows the unit vector it used.

Are the partial derivatives exact?

No. Each partial derivative is a central difference with the step shown under the result. For a polynomial of low degree the estimate often matches the algebra. A kink, a corner, or a point outside the domain will not settle.

What if I leave the direction blank, or type the zero vector?

Leave the direction blank when you only want the gradient. The zero vector does not name a direction, so the page refuses it instead of dividing by zero.

Want a tool that matches a new explainer, or a check that a page and a calculator disagree? Write a short note.

Suggest a topic or tool