Skip to content

Gradient Calculator

Find the gradient ∇f of a function of two or three variables, its value and magnitude at a point, the direction of steepest ascent, a directional derivative and the tangent plane.

Calculator Details

∇f:…See results ↓

A function of x and y (and z): + − * / ^, brackets, sin, cos, tan, exp, ln, log (base 10), sqrt, abs, pi, e. 2x means 2·x

f(x, y) or f(x, y, z)

Where to evaluate the gradient

Where to evaluate the gradient

Direction for the directional derivative (any length; it is normalised)

Direction for the directional derivative

Your Results

∇f: …

∇f

…

Loading the symbolic engine…

Compare scenarios

Save these inputs as a scenario, change them, and compare the results side by side.

Loading, available in a moment

Detailed Breakdown

How This Calculator Works

How it's calculated

∇f = (∂f/∂x, ∂f/∂y) · |∇f| = √(Σ ∂f²)

D_u f = ∇f · u/|u| · tangent plane z = f(P) + f_x(P)(x − x₀) + f_y(P)(y − y₀)

Frequently Asked Questions

What is the gradient of a function?

The vector of its first partial derivatives: ∇f = (∂f/∂x, ∂f/∂y) for f(x, y), or (∂f/∂x, ∂f/∂y, ∂f/∂z) in three variables. At each point it points in the direction in which f increases fastest, and its length is that fastest rate of increase.

How do you calculate a gradient?

Differentiate f with respect to each variable in turn, treating the others as constants, and put the results in a vector. For f = x²y + 3xy²: ∂f/∂x = 2xy + 3y² and ∂f/∂y = x² + 6xy. At (1, 2) that is (16, 13).

What does the magnitude of the gradient mean?

It is the slope in the steepest direction: how fast f changes per unit distance if you move the way ∇f points. For the example at (1, 2), |∇f| = √(16² + 13²) = √425 ≈ 20.6. Moving the opposite way, f decreases at the same rate, which is the idea behind gradient descent in optimisation and machine learning.

What is a directional derivative?

The rate of change of f in a chosen direction u: D_u f = ∇f · (u ÷ |u|). Normalising u matters: the direction (3, 4) becomes (0.6, 0.8). For the example, D_u f = 16 × 0.6 + 13 × 0.8 = 20, a little less than the maximum 20.6 because (0.6, 0.8) is close to, but not exactly, the gradient direction.

Why is the gradient perpendicular to level curves?

Along a level curve (a contour) f doesn’t change, so the directional derivative along the curve is 0, which means ∇f · t = 0 for the tangent direction t. The gradient is therefore at right angles to contour lines on a map, pointing uphill. In three variables it is normal to level surfaces, which is how the tangent plane to f(x, y, z) = c is found.

How do I find the tangent plane from the gradient?

For a surface z = f(x, y) at (x₀, y₀): z = f(x₀, y₀) + f_x(x₀, y₀)(x − x₀) + f_y(x₀, y₀)(y − y₀). For the example, z = 14 + 16(x − 1) + 13(y − 2). For a level surface F(x, y, z) = c, the plane is ∇F(P) · (X − P) = 0.

What happens when the gradient is zero?

The point is a critical point: a local maximum, a local minimum or a saddle point, and no direction is steepest. x² + y² has ∇f = (0, 0) at the origin, its minimum. To tell the three kinds apart, look at the second partial derivatives (the second derivative test).

Is the gradient the same as the slope?

It generalises the slope. For a function of one variable the gradient is just f′(x). With two or more variables the slope depends on direction, so the gradient packs all the directional slopes into one vector: the slope in any direction is its dot product with that direction.

Included: the symbolic gradient of a function of two or three variables, its value and magnitude at a point, the unit direction of steepest ascent, the directional derivative along any vector, and the tangent plane to z = f(x, y) or to the level surface of f(x, y, z), following OpenStax Calculus Volume 3 §4.6 (trig in radians). The chart shows f along the steepest-ascent line through the point. Left out: second derivatives (Hessian), classification of critical points, contour plots, gradients of vector fields (divergence, curl), and variables other than x, y and z. For a single partial derivative of any order, use the derivative calculator.

Gradient Calculator: ∇f, Directional Derivatives and Tangent Planes

By FindMySum · Last reviewed

A gradient calculator finds ∇f, the vector of partial derivatives of a function of several variables, and tells you what it means at a point: how steep the function is, which way it climbs fastest, how fast it changes in any direction you choose, and the tangent plane that best approximates it there. Type a function of x and y (or x, y and z), a point and a direction. The derivatives are found symbolically, so you see the formulas as well as the numbers.

What the gradient is

For f(x, y), the gradient is

∇f = (∂f/∂x, ∂f/∂y).

Each partial derivative is an ordinary derivative with the other variable held constant. In three variables, add ∂f/∂z. At any point, ∇f:

  • points in the direction of steepest increase of f;
  • has length |∇f| equal to that steepest rate of increase;
  • is perpendicular to the level curve (or level surface) through the point.

Worked example with the default function

f(x, y) = x²y + 3xy², at the point (1, 2).

  1. Partial with respect to x (y constant): ∂f/∂x = 2xy + 3y².
  2. Partial with respect to y (x constant): ∂f/∂y = x² + 6xy.
  3. At (1, 2): ∂f/∂x = 2(1)(2) + 3(4) = 16 and ∂f/∂y = 1 + 6(1)(2) = 13, so ∇f(1, 2) = (16, 13).
  4. Magnitude: |∇f| = √(16² + 13²) = √425 ≈ 20.616.
  5. Direction of steepest ascent: (16, 13) ÷ 20.616 ≈ (0.776, 0.631).

So at (1, 2), f increases fastest towards (0.776, 0.631), at about 20.6 units of f per unit of distance.

Directional derivatives

The rate of change of f in a direction u is the dot product of the gradient with the unit vector in that direction:

D_u f = ∇f · (u ÷ |u|).

For the default direction (3, 4), the unit vector is (0.6, 0.8), and

D_u f = 16 × 0.6 + 13 × 0.8 = 9.6 + 10.4 = 20.

That is slightly less than the maximum 20.616 because (0.6, 0.8) points a little away from the gradient. In general D_u f = |∇f| cos θ, where θ is the angle between u and ∇f: largest along ∇f, zero along a level curve, most negative straight against ∇f.

The tangent plane

Near the point, z = f(x, y) looks like a plane:

z = f(x₀, y₀) + f_x(x₀, y₀)(x − x₀) + f_y(x₀, y₀)(y − y₀).

For the example, f(1, 2) = 2 + 12 = 14, so the tangent plane is

z = 14 + 16(x − 1) + 13(y − 2).

This plane is also the linear approximation of f: at (1.1, 2.1) it predicts 14 + 1.6 + 1.3 = 16.9, close to the true value 17.09.

For a function of three variables, the gradient is normal to the level surface f(x, y, z) = f(P), and that surface's tangent plane is f_x(P)(x − x₀) + f_y(P)(y − y₀) + f_z(P)(z − z₀) = 0. For f = xyz at (1, 2, 3), ∇f = (6, 3, 2) and the plane is 6(x − 1) + 3(y − 2) + 2(z − 3) = 0.

Critical points

Where ∇f = 0, there is no direction of steepest ascent: the point is a local maximum, a local minimum or a saddle. For f = x² + y², the gradient (2x, 2y) is zero only at the origin, the bottom of the bowl. The calculator reports this case; deciding which kind of critical point it is needs second derivatives.

Typing functions

  • Use * or juxtaposition for multiplication (2x means 2·x), ^ for powers, and brackets freely.
  • Functions: sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, exp, ln (natural log), log (base 10), sqrt, abs.
  • Constants: pi and e. Any other letter is treated as a constant and the gradient is shown as a formula, but it can't be evaluated until you replace the letter with a number.

Where gradients are used

Gradients are everywhere in science and engineering. Heat flows down the temperature gradient (Fourier's law), electric fields are the negative gradient of electric potential, and optimisation algorithms from linear regression to deep learning follow the gradient downhill to a minimum.

More questions

What is the difference between a gradient and a derivative?

A derivative is the rate of change of a function of one variable, a single number at each point. The gradient is its extension to several variables: a vector made of all the partial derivatives. Each partial derivative is the ordinary derivative along one axis with the other variables held fixed.

How is the gradient used in machine learning?

Training a model means minimising a loss function of many parameters. Gradient descent repeatedly moves the parameters a small step in the direction of −∇(loss), the direction of steepest decrease. Backpropagation is an efficient way of computing that gradient for a neural network.

What is the gradient on a topographic map?

If f(x, y) is the elevation, the gradient at a point points straight uphill, perpendicular to the contour lines, and its magnitude is the steepness (rise over run). Closely spaced contours mean a large gradient. Water flows in the direction of −∇f.

Can the directional derivative be larger than the magnitude of the gradient?

No. Since D_u f = |∇f| cos θ, where θ is the angle between u and ∇f, the directional derivative is at most |∇f| (when u points along the gradient) and at least −|∇f| (when it points the opposite way). It is zero along level curves, where θ = 90°.

Do I need to use radians?

Yes, for trigonometric functions. The derivative of sin x is cos x only when x is in radians, so the calculator treats every angle as radians. Convert degrees by multiplying by π/180 inside the function, for example sin(x*pi/180).

Sources

This article explains how the calculator works and is general information, not financial, tax, legal or medical advice. Rules change; check the sources above or a qualified professional before you act.

Spotted a wrong result or a bug? Report a problem

May we count your visits with Invoker Analytics? It keeps a random visitor number in your browser. Your calculator inputs are never sent. Privacy policy