Gradient Calculator – Steepest Ascent, Magnitude & Directional Derivatives
The gradient of a multivariable function is the vector of all its first-order partial derivatives. For a function of two variables, f(x, y), the gradient is written ∇f = (∂f/∂x, ∂f/∂y); for three variables, f(x, y, z), it extends to ∇f = (∂f/∂x, ∂f/∂y, ∂f/∂z). This calculator uses the mathjs symbolic engine — the same engine behind the Derivative Calculator — to differentiate your expression with respect to each variable in turn, then optionally substitutes a point to give you a fully numeric result.
Why the Gradient Points “Uphill”
At any point, the gradient vector points in the direction where the function increases fastest — the direction of steepest ascent. Its magnitude, ‖∇f‖ = √(Σ (∂f/∂xᵢ)²), tells you how steep that increase is: a larger magnitude means the function changes more rapidly near that point. Moving in the opposite direction, −∇f, is the direction of steepest descent — the basis of the gradient descent optimization algorithm used throughout machine learning.
Symbolic Gradient
∇f = (∂f/∂x, ∂f/∂y)The partial derivatives, computed algebraically without needing a numeric point.
Magnitude & Direction
‖∇f‖, θ = atan2(∂f/∂y, ∂f/∂x)How steep the ascent is, and which way it points, at a specific point.
Directional Derivative
D_u f = ∇f · ûThe rate of change of f along any direction you choose, not just steepest ascent.
Evaluating the Gradient at a Point
Once you supply coordinates, the tool substitutes them into each partial derivative expression to produce a numeric gradient vector. From there it computes the magnitude (how steep the surface is) and, for 2-variable functions, the direction angle measured from the positive x-axis using atan2(∂f/∂y, ∂f/∂x). For 3-variable functions, the direction is instead expressed as the angle the gradient makes with each coordinate axis.
Directional Derivatives
The gradient alone tells you the direction of fastest increase, but sometimes you need the rate of change along a specific direction — say, along a path constrained by some other condition. The directional derivative answers this by projecting the gradient onto a unit vector û in your chosen direction: D_u f = ∇f · û. When û points the same way as ∇f, the directional derivative equals the full magnitude ‖∇f‖ — the maximum possible rate of increase. When ûis perpendicular to the gradient, the directional derivative is zero, since moving along a contour line does not change the function’s value.
Gradient Descent in One Step
Gradient descent is an iterative optimization method that repeatedly moves a point in the direction of steepest descent: x_new = x − η·∇f(x), where η (eta) is the step size, or learning rate. This calculator previews a single iteration so you can see exactly how the gradient shapes each update — a useful sanity check when implementing or debugging optimization code by hand.
Handling Undefined Points
Not every point lies in a function’s domain. If evaluating the function or any partial derivative would require dividing by zero, taking the square root of a negative number, or the logarithm of a non-positive number, the calculator reports the point as undefined rather than displaying a misleading result.
Practical Applications
Optimization & machine learning: gradient descent and its variants (SGD, Adam) all rely on computing the gradient of a loss function at each step.
Physics: the gradient of a scalar potential field (temperature, pressure, electric potential) gives the direction and strength of the associated force or flow.
Engineering & geography: the gradient of an elevation function points toward the steepest uphill direction on a terrain surface.
Multivariable calculus:setting the gradient equal to the zero vector is the standard first step in locating a function’s critical points.
Limitations
This tool computes gradients over the real numbers for functions built from standard arithmetic, trigonometric, exponential, and logarithmic operations. Piecewise functions, functions with branch cuts, and expressions that simplify only partially may produce unwieldy symbolic results — try expanding or simplifying your expression manually if the output looks unexpectedly long. The interactive contour diagram is available for 2-variable functions only, since a 2D plot cannot faithfully represent a 3-variable surface.