Gradient Calculator

Compute the gradient vector, directional derivative, gradient magnitude, and visualize the gradient field for multivariable functions f(x,y).

f(x₀, y₀)
2.00
f = x² + y² at (1, 1)
∂f/∂x
2.00
Partial derivative with respect to x
∂f/∂y
2.00
Partial derivative with respect to y
∇f (gradient)
(2.00, 2.00)
Vector of partial derivatives
|∇f| (magnitude)
2.83
√((∂f/∂x)² + (∂f/∂y)²) — max rate of increase
Gradient Angle
45.00°
Direction of steepest ascent
Directional Derivative
2.00
∇f · û = (2.00)·(1.00) + (2.00)·(0.00)
Level Curve
f = 2.00
Gradient is perpendicular to this curve

Gradient Field

Arrows show gradient direction; color intensity shows magnitude. Red dot: evaluation point.

Partial Derivatives Table

Point (x, y)f(x,y)∂f/∂x∂f/∂y|∇f|
(-1.00, -1.00)2.00-2.00-2.002.83
(-1.00, 1.00)2.00-2.002.002.83
(-1.00, 3.00)10.00-2.006.006.32
(0.00, 0.00)0.000.000.000.00
(0.00, 2.00)4.000.004.004.00
(1.00, -1.00)2.002.00-2.002.83
(1.00, 1.00)2.002.002.002.83
(1.00, 3.00)10.002.006.006.32
(2.00, 0.00)4.004.000.004.00
(2.00, 2.00)8.004.004.005.66
(3.00, -1.00)10.006.00-2.006.32
(3.00, 1.00)10.006.002.006.32
(3.00, 3.00)18.006.006.008.49
Planning notes, formulas, and examples

About the Gradient Calculator

The gradient is a vector of partial derivatives that points in the direction of greatest increase of a multivariable function. For f(x,y), the gradient ∇f = (∂f/∂x, ∂f/∂y) at any point gives both the direction and rate of steepest ascent. Its magnitude |∇f| equals the maximum rate of change, and it is always perpendicular to the level curves (contours) of the function.

This calculator numerically computes the gradient for several standard functions, evaluates it at any point, and calculates the directional derivative in a custom direction. The gradient field visualization shows arrows at grid points indicating the gradient direction and magnitude (color-coded), giving an intuitive understanding of how the function changes across the plane.

The gradient is fundamental in multivariable calculus, optimization (gradient descent/ascent), machine learning (backpropagation), physics (force fields, heat flow), and image processing (edge detection). Understanding gradient fields is essential for anyone working with optimization algorithms, potential theory, or fluid dynamics.

When This Page Helps

Computing partial derivatives and gradient vectors by hand for complex multivariable functions takes time, and numerical differentiation across a grid of points to visualize the gradient field is impractical without software. This calculator evaluates partial derivatives at any point, computes the directional derivative in any direction, and renders the gradient field with color-coded arrows — helping you visualize how a function changes across the plane. It is essential for students verifying calculus homework, engineers optimizing cost surfaces, and data scientists understanding gradient descent behavior.

How to Use the Inputs

  1. Select a function f(x,y) from the dropdown — options include x² + y², xy, and more.
  2. Enter the evaluation point (x₀, y₀) where you want to compute the gradient.
  3. Enter a direction vector (x, y) for the directional derivative.
  4. Adjust grid size for the gradient field visualization.
  5. Use presets for common functions at standard points.
  6. Review partial derivatives, gradient vector, magnitude, and directional derivative.
  7. Study the gradient field arrows — they show the direction of steepest increase.
Formula used
∇f = (∂f/∂x, ∂f/∂y) |∇f| = √((∂f/∂x)² + (∂f/∂y)²) Dûf = ∇f · û (directional derivative)

Example Calculation

Result: ∇f = (2, 2), |∇f| ≈ 2.83, D_û f = 2

For f = x² + y² at (1,1): ∂f/∂x = 2x = 2, ∂f/∂y = 2y = 2. Gradient = (2,2), magnitude = 2√2 ≈ 2.83. In direction (1,0), D = 2.

Tips & Best Practices

  • The gradient always points perpendicular to level curves, toward higher values.
  • At a local minimum or maximum, ∇f = (0, 0) — these are critical points.
  • The directional derivative equals |∇f|·cos(θ), where θ is the angle between the gradient and direction.
  • Gradient descent moves in the −∇f direction to minimize a function.
  • For linear functions f = ax + by, the gradient is constant: ∇f = (a, b).

Gradient in Machine Learning and Optimization

The gradient is the engine behind modern optimization. Gradient descent — moving iteratively in the −∇f direction — is how neural networks learn during backpropagation. Stochastic gradient descent (SGD), Adam, and RMSProp are all variants that rely on gradient computation. The magnitude |∇f| indicates how steep the loss landscape is, while the direction tells the optimizer where to step. Vanishing gradients (|∇f| → 0 in deep networks) and exploding gradients are major challenges in training deep models.

Gradient in Physics and Engineering

In physics, the gradient connects scalar fields to vector fields. Temperature gradients drive heat flow (Fourier's law: q = −k∇T). Pressure gradients produce wind. The electric field is the negative gradient of voltage: **E** = −∇V. In fluid dynamics, the gradient of a velocity potential gives the velocity field. Engineers use gradient information for structural optimization, aerodynamic design, and electromagnetic field analysis.

Level Curves and the Gradient

Level curves (contours) are lines where f(x,y) = constant. The gradient is always perpendicular to level curves and points toward increasing values. The spacing of contour lines indicates gradient magnitude — closely spaced lines mean steep slopes. Topographic maps use this principle: closely packed elevation contours indicate cliffs, while widely spaced lines indicate gentle terrain. In optimization, level curves of the cost function help visualize convergence paths.

Sources & Methodology

Last updated:

Frequently Asked Questions

  • The gradient ∇f of a scalar function is a vector of partial derivatives. It points in the direction of steepest increase and its magnitude is the rate of that increase.