Gradient Calculator

Compute ∇f = ⟨fx, fy⟩ symbolically and read off the steepest-ascent direction.

Gradient Calculator

What Is the Gradient?

The gradient of a two-variable function f(x, y) packages both partial derivatives into a single vector:

∇f = ⟨ ∂f/∂x, ∂f/∂y ⟩

Written "del f" or "grad f," it's far more than notational convenience. At every point of the landscape z = f(x, y), the gradient vector points in the direction of steepest ascent and its magnitude |∇f| is the slope in that steepest direction. A hiker on the surface reading ∇f gets two facts at once: which way is straight uphill, and how hard the climb is. Downhill fastest? Walk along −∇f. Want level ground? Move perpendicular to ∇f, which is exactly why gradients are always perpendicular to contour lines on a topographic map.

How to Use This Calculator

Enter f(x, y). Both partials are computed symbolically and assembled into ∇f as a vector of formulas; add a point and the calculator evaluates the gradient there, reporting its components and magnitude, the local steepest-ascent rate. The plot draws the level curve of f passing through your point (the contour at the function's current value) with the point marked: the gradient, though not drawn as an arrow, is by theorem perpendicular to that curve at the mark.

Worked Example

Take the bowl f(x, y) = x² + y². The partials are fx = 2x and fy = 2y, so:

∇f = ⟨2x, 2y⟩ at (1, 2), ∇f = ⟨2, 4⟩ with magnitude √20 ≈ 4.472.

Geometry check: ⟨2, 4⟩ points directly away from the origin, from anywhere inside a bowl, straight uphill means directly away from the bottom, and twice the position vector does exactly that. The level curves are circles centered at the origin, and ⟨2x, 2y⟩ is radial: perpendicular to every one of them, as promised.

The Gradient's Three Jobs

PropertyStatementUsed for
Steepest ascent∇f points uphill fastest; |∇f| is that rateOptimization, gradient descent
Normal to level curves∇f ⟂ the contour f = constantTangent lines/planes to implicit curves
Universal rate machineDuf = ∇f · u for any unit direction uThe directional derivative

The third row is the deepest: one vector, computed once, delivers the rate of change in every direction by a mere dot product. Directions can be interrogated after the calculus is done, that economy is the reason the gradient is the central object of multivariable differentiation.

Common Mistakes to Avoid

  • Treating ∇f as a number. It's a vector, two components in two variables, n components in n. Its magnitude is a number; the direction is half the information.
  • Forgetting it lives in the input plane. ∇f is a 2D vector in the xy-plane (the map), not an arrow on the 3D surface. It says which way to walk on the map, not along the hill.
  • Expecting it to point at the maximum. Steepest ascent is local: ∇f points uphill here which may curve away from the summit en route, precisely why gradient-following algorithms take many small steps.
  • Sign confusion at minima and maxima. At any smooth peak, valley, or saddle, ∇f = ⟨0, 0⟩, the flat spots. Zero gradient is the multivariable critical-point condition, the 2D sibling of f'(x) = 0.

Real-World Applications

Gradient descent, step repeatedly along −∇f, is the algorithm training essentially every neural network: the "gradient" in the name is exactly this vector, computed in millions of dimensions (one per weight) by backpropagation, which is the chain rule organized for efficiency. Each training step of every large language model, image classifier, and recommender system evaluates a gradient and walks downhill on a loss landscape, this page's mathematics at industrial scale.

Physics writes its force laws with gradients: force is the negative gradient of potential energy (F = −∇U), heat flows down temperature gradients (Fourier's law), diffusion follows concentration gradients (Fick's law), and groundwater follows pressure gradients (Darcy's law). Meteorologists' pressure-gradient force drives wind; hikers' contour maps encode ∇ everywhere ("tight contours = steep" is a statement about |∇f|). When a quantity varies over space, its gradient is where the action is.

Frequently Asked Questions

Why is the gradient perpendicular to level curves?

Along a level curve f stays constant, so the rate of change in the tangent direction is zero: ∇f · (tangent) = 0, which is perpendicularity by definition of the dot product. All the change must happen crossing contours, none along them.

Why is ∇f the direction of steepest ascent?

The directional derivative is Duf = |∇f| cos θ, with θ the angle between u and the gradient. Cosine peaks at θ = 0, alignment with ∇f, giving rate |∇f|; the opposite direction gives −|∇f| (steepest descent), and perpendicular gives 0 (level walking). One formula, whole story.

How does the gradient extend to three or more variables?

Componentwise: ∇f = ⟨f_x, f_y, f_z⟩ for three, and n partials for n variables. Machine-learning gradients routinely have millions of components, same object, same steepest-ascent meaning, no new ideas needed beyond bookkeeping.

What does a zero gradient signify?

A critical point: local max, local min, or saddle. Classifying which requires second-derivative information, the Hessian matrix and its determinant play the role the second derivative test plays in one variable.

Is the gradient related to the derivative of one-variable calculus?

It's the direct generalization: in one variable ∇f = ⟨f'(x)⟩, a one-component vector, and "steepest ascent" degenerates to "move right if f' > 0." Every gradient property collapses to a familiar 1D fact when y disappears, a good way to sanity-check intuition.

What does the plotted level curve have to do with the gradient?

Everything visible: the curve drawn is the contour f = constant through your point, and the gradient at the marked point is exactly perpendicular to it, the theorem made checkable by eye. Where contours crowd together on a map, |∇f| is large; the calculator's magnitude readout is the number behind that visual density.

Why "del" and the ∇ symbol?

∇ (nabla, after a Hebrew harp of similar shape) is the vector of partial-derivative operators ⟨∂/∂x, ∂/∂y⟩; applying it to f produces the gradient. The same symbol builds divergence (∇·) and curl (∇×) in vector calculus, one operator, three fundamental combinations.