Multivariable calculusFree · No sign-up

Gradient Calculator

This gradient calculator finds ∇f, the vector of first-order partial derivatives of a function of 2 or 3 variables, with steps. Add a point to get the direction of steepest ascent, the maximum rate of change |∇f| and the directional derivative, all drawn on a contour map. Students, engineers and data scientists use it for multivariable calculus homework, optimization and gradient descent checks.

See the contour map
  • Directional derivative Duf
  • Critical points + second-derivative test
  • Tangent line to the level curve
2–3
variables
6+
results per point
7
ready-made examples
Gradient engine
f =
p =
v =
Preview
—Full solution ↓

Results

Your gradient, on the contour map and step by step

The red arrow is ∇f at your point. It crosses the bold level curve at a right angle, and the dashed line is the tangent to that curve.

Interactive diagram

Contour map and gradient field

∇f steepest ascentu your directiontangent level curve

Drag on the map to move the point.

Gradient

Step-by-step solution

—

    Step by step

    How to Use the Gradient Calculator

    To use the gradient calculator, follow these 5 steps. The result and the map update as you type.

    1. 1

      Type the function

      Use x and y, or x, y and z, for example x^2 + 3*x*y or exp(-(x^2 + y^2)).

    2. 2

      Add a point

      Enter 1, 2 or 1, 1, 1 to evaluate ∇f, |∇f| and the unit direction there.

    3. 3

      Add a direction (optional)

      Enter any nonzero vector, such as 3, 4. The tool normalises it and returns Duf.

    4. 4

      Read the results

      Check the gradient formula, its value, the tangent line and any critical points with their type.

    5. 5

      Explore the map

      Drag the point across the contour map. The arrow always crosses the level curve at 90°.

    Try an example:

    Definition

    What Is the Gradient of a Function?

    The gradient of a function is the vector of its first-order partial derivatives, one component for each independent variable. For a differentiable function f(x, y), the gradient is the 2-dimensional vector ∇f = (∂f/∂x, ∂f/∂y); for f(x, y, z), it is the 3-dimensional vector (∂f/∂x, ∂f/∂y, ∂f/∂z).

    The symbol ∇ is called nabla, or the del operator. Read ∇f as "grad f" or "del f". A scalar function takes a point and returns one number, such as a height or a temperature; the gradient turns that scalar function into a vector field, with one arrow at every point.

    Each arrow carries 2 facts about the function at its base point:

    • Direction: the direction of steepest ascent, where f grows fastest.
    • Length: the maximum rate of change of f, the slope in that steepest direction.

    In 1 variable, the gradient reduces to the ordinary derivative f′(x), the slope of the tangent line. For a straight line y = mx + c, the gradient is the constant m.

    Gradient field explorer: ∇f arrows over the contour map

    f = e^(−(x² + y²)): a hill. Orange shading marks high values of f and teal marks low values. Every arrow points uphill, crosses the contour lines at a right angle, and grows longer where the contours crowd together.

    Formula

    Gradient Formula in 2 and 3 Variables

    The gradient formula lists the partial derivatives of f in the order of its variables: 2 components for f(x, y) and 3 components for f(x, y, z).

    2 variables

    f(x, y)

    Example: f = x² + y² gives ∇f = (2x, 2y).

    3 variables

    f(x, y, z)

    Example: f = x² + y² + z² gives ∇f = (2x, 2y, 2z).

    The nabla operator is the vector of partial derivative operators, ∇ = (∂/∂x, ∂/∂y, ∂/∂z). Applied to a scalar function, ∇ gives the gradient. Applied to a vector field with a dot product, ∇ · F gives the divergence; with a cross product, ∇ × F gives the curl.

    The gradient is linear. For constants a and b, ∇(af + bg) = a∇f + b∇g, so a sum of polynomial terms is differentiated term by term. The product rule carries over as well: ∇(fg) = f∇g + g∇f.

    The gradient in 1, 2 and 3 variables
    VariablesGradientResult
    1: a line through 2 pointsa number (slope)
    1: a curve y = f(x)a number
    2: f(x, y)2D vector
    3: f(x, y, z)3D vector
    iThe gradient of a line between 2 points is rise over run. The line through (1, 2) and (4, 8) has gradient (8 − 2)/(4 − 1) = 6/3 = 2, and its equation is y = 2x. In the form y = mx + c, the gradient is m and the y-intercept is c.

    Method

    How to Find the Gradient

    To find the gradient, take the partial derivative of f with respect to each variable, write the partial derivatives as a vector, and substitute the point. The 3 steps below find ∇f for f(x, y) = x²y + 3y at (1, 2).

    01

    Step 1: Find each partial derivative

    To find ∂f/∂x, hold y constant; to find ∂f/∂y, hold x constant. The power rule gives d/dx xⁿ = nxⁿ⁻¹ for each polynomial term:

    02

    Step 2: Write the partials as a vector

    To write the gradient, place the partial derivatives in variable order, x first and y second:

    The result is a vector field, defined at every point.

    03

    Step 3: Evaluate at the point

    To evaluate at (1, 2), substitute x = 1 and y = 2 in each component:

    |∇f(1, 2)| = √32 = 4√2 ≈ 5.6569.

    At a point

    Gradient at a Point: Magnitude and Direction

    The gradient at a point is one vector with 2 meanings: its direction is the direction of steepest ascent, and its magnitude |∇f| is the maximum rate of change of f at that point.

    04

    Direction of steepest ascent

    The direction of steepest ascent is the unit vector ∇f/|∇f|. Moving that way raises f faster than any other direction; moving the opposite way, along −∇f, is the direction of steepest descent.

    For f = x² + y² at (1, 2), ∇f = (2, 4) and the unit direction of steepest ascent is (2, 4)/√20 ≈ (0.4472, 0.8944), straight away from the origin.

    05

    Maximum rate of change |∇f|

    The maximum rate of change of f at a point equals the length of the gradient vector, |∇f|. For f(x, y, z):

    For f = x² + y² at (1, 2), |∇f| = √(4 + 16) = √20 ≈ 4.4721: f rises about 4.47 units per unit of distance in the steepest direction, and less in every other direction.

    Gradient magnitude on the bowl f = x² + y²

    |∇f| = 2r grows with the distance r from the origin. The level circles crowd together far from the centre, and the red arrows get longer to match. At the origin, ∇f = (0, 0): the bottom of the bowl.

    Any direction

    Directional Derivative From the Gradient

    The directional derivative of f in the direction of a unit vector u is the dot product of the gradient with u: Duf = ∇f · u. Duf measures the rate of change of f per unit of distance when you move in the direction u.

    α is the angle between ∇f and u. The cosine form gives 3 rules:

    • α = 0°: Duf = |∇f|, the maximum.
    • α = 90°: Duf = 0, along the level curve.
    • α = 180°: Duf = −|∇f|, the steepest descent.

    Normalise the direction first, if it is not a unit vector. For v = (3, 4), |v| = 5 and u = (0.6, 0.8). The calculator divides by |v| on its own.

    Example: the temperature T = 100 − x² − 2y² at (2, 1) has ∇T = (−4, −4). Toward v = (−1, −1), u = (−0.7071, −0.7071) and DuT = 2.8284 + 2.8284 = 5.6569 degrees per unit, the largest possible rate.

    Directional derivative explorer: turn u around the point (2, 1)
    Dᵤf = ∇f · u—
    maximum |∇f|—

    f = 100 − x² − 2y², ∇f(2, 1) = (−4, −4). Red: ∇f. Orange: u. The lower graph traces Duf = |∇f| cos α: it peaks at 5.6569 when u lines up with ∇f (225°) and crosses 0 at 135° and 315°.

    Geometry

    Gradient and Level Curves (Always at 90°)

    Yes, the gradient is always perpendicular to the level curve through the point, wherever ∇f ≠ 0. A level curve f(x, y) = c is a curve on which f stays constant, the contour line of a map. For f(x, y, z), the level sets are level surfaces, and ∇f is perpendicular to those surfaces.

    The proof takes 2 lines. Along the level curve, f does not change, so the directional derivative in the tangent direction T is 0:

    A dot product of 0 means a 90° angle. The tangent T and the gradient ∇f are orthogonal at every point of every level curve.

    The spacing of contours carries the magnitude. On a map drawn at equal steps of f, contours packed close together mean a large |∇f| and a steep slope; widely spaced contours mean a small |∇f| and gentle ground.

    Level-curve explorer: slide the point around the ellipse x² + 2y² = 4
    point—
    ∇f = (2x, 4y)—
    ∇f · T (unit)—
    tangent line—

    Dark curve: the level curve f = 4. Red: ∇f. Dashed teal: the tangent line. The dot product ∇f · T stays at 0 at every position, which is the 90° angle in numbers.

    Linear approximation

    Tangent Line and Tangent Plane From ∇f

    The gradient ∇f(P) is a normal vector to the level set through P, so it gives the tangent line to a level curve in 2D and the tangent plane to a level surface in 3D in one formula.

    2D

    Tangent line to f(x, y) = c at (x₀, y₀)

    Circle x² + y² = 5 at (1, 2): ∇f = (2, 4), so 2(x − 1) + 4(y − 2) = 0, which simplifies to x + 2y = 5.

    3D

    Tangent plane to f(x, y, z) = c at (x₀, y₀, z₀)

    Sphere x² + y² + z² = 3 at (1, 1, 1): ∇f = (2, 2, 2), so 2(x − 1) + 2(y − 1) + 2(z − 1) = 0, which simplifies to x + y + z = 3.

    Tangent objects from the gradient
    SurfaceNormal vectorTangent equation
    Level curve f(x, y) = c∇f(x₀, y₀)tangent line, ∇f · (x − x₀, y − y₀) = 0
    Level surface f(x, y, z) = c∇f(x₀, y₀, z₀)tangent plane, ∇f · (x − x₀, y − y₀, z − z₀) = 0
    Graph z = g(x, y)(gx, gy, −1)z = g(x₀, y₀) + gx(x − x₀) + gy(y − y₀)

    The normal line through the point runs along ∇f: (x, y, z) = (x₀, y₀, z₀) + t∇f. For the sphere at (1, 1, 1), the normal line is (1 + 2t, 1 + 2t, 1 + 2t), which passes through the centre (0, 0, 0) at t = −½.

    Optimization

    Critical Points and the Second-Derivative Test

    A critical point of f is a point where the gradient is the zero vector, ∇f = 0, or where ∇f does not exist. Every local maximum and local minimum of a differentiable function sits at a critical point, but some critical points are saddle points instead.

    The second derivative test classifies a critical point (a, b) of f(x, y) with the Hessian determinant D, built from the second partial derivatives:

    Second derivative test
    Condition at (a, b)Type
    D > 0 and fxx > 0local minimum
    D > 0 and fxx < 0local maximum
    D < 0saddle point
    D = 0test is inconclusive

    For f = x² − y² − xy, ∇f = (2x − y, −2y − x) is 0 only at (0, 0). There, fxx = 2, fyy = −2 and fxy = −1, so D = −4 − 1 = −5 < 0: a saddle point.

    For f = xy, ∇f = (y, x) vanishes at (0, 0), with D = 0 · 0 − 1² = −1: a saddle point.

    Critical points of f = x³ − 3x + y²

    The gradient arrows shrink to 0 at 2 points. Around (1, 0), the contours close into rings and every arrow points outward: a local minimum, f = −2. At (−1, 0), the contours cross in an X: a saddle point, f = 2.

    Other coordinates

    Gradient in Cylindrical and Spherical Coordinates

    The gradient in cylindrical and spherical coordinates divides each angular partial derivative by a scale factor: r for θ in cylindrical, ρ for φ and ρ sin φ for θ in spherical.

    Gradient in 3 coordinate systems
    SystemGradient formulaExample
    Cartesian (x, y, z)f = x² + y²: (2x, 2y, 0)
    Cylindrical (r, θ, z)f = r²: 2r r̂
    Spherical (ρ, φ, θ)f = 1/ρ: −(1/ρ²) ρ̂
    iThis gradient calculator works in Cartesian coordinates. For a function given in r, θ or ρ, rewrite it in x, y and z first, with r = √(x² + y²) and ρ = √(x² + y² + z²). The function r² becomes x² + y², with ∇f = (2x, 2y, 0), a vector of length 2r pointing along r̂: the same answer as the cylindrical formula. The coordinate systems themselves are covered in the cylindrical and spherical coordinates calculators.

    Practice

    Worked Examples

    There are 4 worked examples below, covering a gradient at a point, a directional derivative, critical points and a 3-variable gradient. Each one loads into the calculator with one click.

    2 variables

    Gradient of x² + y² at (1, 2)

    1. Partial derivatives:
    2. Gradient vector:
    3. At (1, 2):
    4. Magnitude:

    Answer: . The arrow points straight away from the origin, perpendicular to the level circle x² + y² = 5, with tangent line x + 2y = 5.

    directional

    Directional derivative of sin x cos y

    f(x, y) = sin x cos y at (1, 0.5), in the direction v = (3, 4).

    1. Gradient:
    2. At (1, 0.5):
    3. Unit vector:
    4. Dot product:

    Answer: . f falls slightly in the direction (3, 4): u (orange) sits just past 90° from ∇f (red).

    critical points

    Critical points of x³ − 3x + y²

    1. Set ∇f = 0:
    2. Solve:
    3. Second partials:
    4. Classify:

    Answer: a local minimum at (1, 0) with f = −2 (teal), and a saddle point at (−1, 0) with f = 2 (red).

    3 variables

    Gradient of a 3-variable function

    f(x, y, z) = xy + z sin(xy) at (1, 1, 1).

    1. In x (chain rule):
    2. In y:
    3. In z:
    4. At (1, 1, 1):

    Answer: , with |∇f| ≈ 2.3352. The map shows the slice z = 1.

    Applications

    Real-World Uses of the Gradient

    There are 5 main real-world uses of the gradient: heat flow, electric fields, machine learning, terrain and map reading, and the grade of ramps, roads and drains.

    Physics

    Heat flow

    Fourier's law states that heat flows down the temperature gradient: q = −k∇T, with k the thermal conductivity in watts per metre-kelvin (W/m·K). Heat moves from hot to cold along −∇T.

    Physics

    Electric fields

    The electric field is the negative gradient of the electric potential: E = −∇V, in volts per metre (V/m). Field lines cross the equipotential surfaces at 90°.

    Machine learning

    Gradient descent

    Neural networks train by gradient descent, θ ← θ − α∇L, stepping against the gradient of the loss function L. Backpropagation computes ∇L with the chain rule. For L = x² + y² from (1, 2) with α = 0.1, one step lands at (0.8, 1.6).

    Geography

    Terrain and elevation

    On a topographic map, the gradient of elevation points straight uphill and crosses the contour lines at right angles. Water runs off along −∇h, the steepest descent.

    A gradient as a grade is the rise divided by the run, written as a slope, a percentage, an angle in degrees or a ratio. A 1-metre rise over a 12-metre run is a slope of 1/12 ≈ 0.0833, a grade of 8.33%, an angle of arctan(1/12) ≈ 4.76° and a ratio of 1 : 12.

    Common grades in percent, degrees and ratio
    UsePercentDegreesRatio
    Ramp (ADA max)8.33%4.76°1 : 12
    Steep road6%3.43°1 : 16.7
    Drain, ¼ in/ft2.08%1.19°1 : 48
    45° slope100%45°1 : 1

    The Americans with Disabilities Act (ADA) sets the 1 : 12 maximum for wheelchair ramps, and a drain pipe at ¼ inch per foot falls about 2 cm per metre. Percent equals 100 × rise/run, degrees equal arctan(rise/run), and a 100% grade is 45°, not vertical.

    Slope converter: rise over run to percent, degrees and ratio
    rise
    run
    slope m—
    percent grade—
    angle—
    ratio—

    Use the same unit for rise and run. Between 2 points, rise = y₂ − y₁ and run = x₂ − x₁.

    Wolfram Alpha, Symbolab, Mathway and MathCracker return ∇f as text, and Desmos and GeoGebra draw contour plots. Handhelds with a computer algebra system, such as the TI-Nspire CX CAS and the Casio ClassPad, find partial derivatives symbolically. This gradient calculator combines the steps, the value at a point, the directional derivative, the critical points and the contour map on one page.

    Questions

    Frequently Asked Questions

    Is the gradient a vector or a scalar?

    The gradient is a vector, while the function it comes from is a scalar function. For f(x, y) = x² + y², f(1, 2) = 5 is a scalar and ∇f(1, 2) = (2, 4) is a 2-dimensional vector. The gradient has one component for each independent variable: 2 for f(x, y) and 3 for f(x, y, z).

    Why is the gradient perpendicular to level curves?

    The gradient is perpendicular to level curves since f does not change along a level curve, so the directional derivative along the tangent T is 0. D_T f = ∇f · T = 0, and a dot product of 0 means a 90° angle. For x² + y² = 5 at (1, 2), ∇f = (2, 4) and the tangent direction (2, −1) give 4 − 4 = 0.

    What does a zero gradient mean?

    A zero gradient means the point is a critical point, where every first-order partial derivative is 0 and f has no direction of increase to first order. A critical point is a local maximum, a local minimum or a saddle point; the second derivative test with D = f_xx f_yy − f_xy² decides which. For x³ − 3x + y², ∇f = 0 at (1, 0), a minimum, and at (−1, 0), a saddle.

    What is the difference between the gradient and the directional derivative?

    The difference is that the gradient is a vector of partial derivatives, while the directional derivative is a scalar rate of change in one chosen direction. The 2 are linked by D_u f = ∇f · u for a unit vector u. The largest directional derivative equals |∇f| and points along ∇f; at (1, 2) on x² + y², the gradient is (2, 4) and the maximum rate is √20 ≈ 4.4721.

    What is the gradient of a constant function?

    The gradient of a constant function is the zero vector. Every partial derivative of a constant is 0, so f = 7 gives ∇f = (0, 0) in 2 variables and (0, 0, 0) in 3 variables. Every point of a constant function is a critical point, and its level set is the whole plane or space instead of a curve.

    This gradient calculator finds ∇f with steps, its magnitude and direction at a point, the directional derivative, the tangent to the level curve and the critical points.