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

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.
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
Drag on the map to move the point.
Gradient
Step-by-step solution
—Step by step
To use the gradient calculator, follow these 5 steps. The result and the map update as you type.
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)).
Add a point
Enter 1, 2 or 1, 1, 1 to evaluate ∇f, |∇f| and the unit direction there.
Add a direction (optional)
Enter any nonzero vector, such as 3, 4. The tool normalises it and returns Duf.
Read the results
Check the gradient formula, its value, the tangent line and any critical points with their type.
Explore the map
Drag the point across the contour map. The arrow always crosses the level curve at 90°.
Definition
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:
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.
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
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).
f(x, y)
Example: f = x² + y² gives ∇f = (2x, 2y).
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.
| Variables | Gradient | Result |
|---|---|---|
| 1: a line through 2 points | a number (slope) | |
| 1: a curve y = f(x) | a number | |
| 2: f(x, y) | 2D vector | |
| 3: f(x, y, z) | 3D vector |
Method
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).
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:
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.
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
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.
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.
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.
|∇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
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:
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.
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
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.
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
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.
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.
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.
| Surface | Normal vector | Tangent 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
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:
| Condition at (a, b) | Type |
|---|---|
| D > 0 and fxx > 0 | local minimum |
| D > 0 and fxx < 0 | local maximum |
| D < 0 | saddle point |
| D = 0 | test 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.
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
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.
| System | Gradient formula | Example |
|---|---|---|
| Cartesian (x, y, z) | f = x² + y²: (2x, 2y, 0) | |
| Cylindrical (r, θ, z) | f = r²: 2r r̂ | |
| Spherical (ρ, φ, θ) | f = 1/ρ: −(1/ρ²) ρ̂ |
Practice
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.
Answer: . The arrow points straight away from the origin, perpendicular to the level circle x² + y² = 5, with tangent line x + 2y = 5.
f(x, y) = sin x cos y at (1, 0.5), in the direction v = (3, 4).
Answer: . f falls slightly in the direction (3, 4): u (orange) sits just past 90° from ∇f (red).
Answer: a local minimum at (1, 0) with f = −2 (teal), and a saddle point at (−1, 0) with f = 2 (red).
f(x, y, z) = xy + z sin(xy) at (1, 1, 1).
Answer: , with |∇f| ≈ 2.3352. The map shows the slice z = 1.
Applications
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.
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.
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°.
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).
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.
| Use | Percent | Degrees | Ratio |
|---|---|---|---|
| Ramp (ADA max) | 8.33% | 4.76° | 1 : 12 |
| Steep road | 6% | 3.43° | 1 : 16.7 |
| Drain, ¼ in/ft | 2.08% | 1.19° | 1 : 48 |
| 45° slope | 100% | 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.
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
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).
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.
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.
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.
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.