Gradient Calculator

Enter the coefficients of a two-variable quadratic function f(x, y) = ax² + by² + cxy + dx + ey and a point (x₀, y₀) to get the gradient vector ∇f = (∂f/∂x, ∂f/∂y), its magnitude, and its direction of steepest ascent.

Quick Facts

Gradient definition
∇f = (∂f/∂x, ∂f/∂y)
The vector of first partial derivatives; it points toward the steepest increase of f.
Partial derivative rule
∂/∂x(ax²) = 2ax
Differentiate with respect to x while treating y as a constant, and vice versa.
Gradient magnitude
|∇f| = √((∂f/∂x)² + (∂f/∂y)²)
Equals the maximum rate of increase of f at that point.

Your Results

Calculated
∂f/∂x
-
Partial derivative with respect to x
∂f/∂y
-
Partial derivative with respect to y
Gradient magnitude |∇f|
-
Maximum rate of increase at this point
Direction of steepest ascent
-
Angle from the positive x-axis, counterclockwise

Ready

Enter the function coefficients and a point (x₀, y₀), then press Calculate.

Formula and Method for the Gradient of a Two-Variable Function

For a function of two variables, f(x, y), the gradient is the vector of its first partial derivatives: ∇f = (∂f/∂x, ∂f/∂y). At any point (x₀, y₀), this vector points in the direction the function increases fastest, and its length is the maximum rate of increase in any direction at that point. This calculator works with a general two-variable quadratic function, f(x, y) = ax² + by² + cxy + dx + ey, which is the standard testbed for gradient problems because every term differentiates cleanly.

How the calculation works

To find ∂f/∂x, differentiate with respect to x while treating y as a constant: ∂f/∂x = 2ax + cy + d. To find ∂f/∂y, differentiate with respect to y while treating x as a constant: ∂f/∂y = 2by + cx + e. Plugging in the point (x₀, y₀) gives the gradient vector ∇f(x₀, y₀) = (2ax₀ + cy₀ + d, 2by₀ + cx₀ + e). The calculator then reports the vector's magnitude, |∇f| = √((∂f/∂x)² + (∂f/∂y)²), and its direction, θ = atan2(∂f/∂y, ∂f/∂x), measured counterclockwise from the positive x-axis.

Common mistakes

  • Forgetting the cross term: when a function has an xy term, both partial derivatives pick up a piece of it — ∂(cxy)/∂x = cy and ∂(cxy)/∂y = cx — not just one of them.
  • Mixing up gradient with slope: the gradient of a two-variable function is a vector with two components, not a single number like the slope of a line; "steepness" in one particular direction is a different quantity (the directional derivative).
  • Assuming a nonzero function value means a nonzero gradient: the gradient depends only on the partial derivatives, so a large f(x, y) can still sit at a flat point where ∇f = (0, 0).

Real-world applications

  • Gradient descent in machine learning repeatedly steps opposite the gradient of a loss function to find the input that minimizes it.
  • Physics uses the gradient of a potential or temperature field to find the direction of steepest change, such as heat flow or force direction.
  • Optimization problems locate candidate maxima, minima, and saddle points by finding where the gradient equals the zero vector.
  • Contour and topographic maps use the gradient of an elevation function to show the steepest uphill or downhill direction at any location.

Frequently Asked Questions

What is the gradient of a function?
The gradient of a function f(x, y) is the vector of its first partial derivatives, written ∇f = (∂f/∂x, ∂f/∂y). At any point, it points in the direction the function increases fastest, and its length gives the maximum rate of increase at that point.
How do you find the gradient of f(x,y) = ax² + by² + cxy + dx + ey?
Take the partial derivative with respect to x while treating y as a constant, and vice versa: ∂f/∂x = 2ax + cy + d and ∂f/∂y = 2by + cx + e. The gradient at a point (x₀, y₀) is the vector ∇f(x₀, y₀) = (2ax₀ + cy₀ + d, 2by₀ + cx₀ + e).
What does the magnitude of the gradient represent?
The magnitude |∇f| = √((∂f/∂x)² + (∂f/∂y)²) equals the steepest slope of the function's surface at that point — the maximum instantaneous rate of change in any direction.
What does a zero gradient mean?
If ∇f = (0, 0) at a point, that point is a critical point of the function — a local minimum, local maximum, or saddle point — and there is no well-defined direction of steepest ascent there.