Gradient Calculator

Gradient magnitude |∇f|—
∂f/∂x—
∂f/∂y—
Direction (degrees)—

How Gradient Calculator is calculated: ∇f = (∂f/∂x, ∂f/∂y); |∇f| = √(∂f/∂x² + ∂f/∂y²); direction = atan2(∂f/∂y, ∂f/∂x)

What is a Gradient Calculator?

The Gradient Calculator is a free online tool that finds the gradient of a two-variable function at a point — the vector that points in the direction the function rises fastest, and says how steep that rise is. Multivariable-calculus, physics and engineering students use it when the direction of steepest ascent on a surface, for example to find the fastest way up a hill or the direction of a force. Instead of working out two partial derivatives and then combining them into a magnitude and an angle, where the angle's quadrant is easy to get wrong, you type the function from the list and the point (x, y) to evaluate at and the calculator returns the gradient's magnitude, its two components, and its direction in degrees straight away.

The working idea is simple. the calculator first finds the two partial derivatives by central finite differences, then assembles them into the vector (∂f/∂x, ∂f/∂y) The magnitude is the square root of the sum of the squared components, and the direction is atan2(∂f/∂y, ∂f/∂x) in degrees, which puts the angle in the correct quadrant — 0° points along +x, 90° along +y, and so on. There is no sign-up and nothing to install: the page runs entirely in your browser, so your numbers never leave your device.

That matters because the gradient is the single most useful object in multivariable calculus: it points uphill, its size is the steepness, and it is perpendicular to the contour lines of the function The components are numeric approximations from finite differences, so the magnitude and angle are accurate to roughly four decimal places for smooth functions — good enough for homework checks, not for a proof. The rest of this page walks through the formula, the input people get wrong most often, and a worked example with real numbers you can check by hand.

How a Gradient Calculator works

At its core, the calculator applies the gradient is the vector of the two partial derivatives, its magnitude is the square root of the sum of their squares, and its direction is the atan2 angle of the components. ∇f = (∂f/∂x, ∂f/∂y). The magnitude |∇f| = √(∂f/∂x² + ∂f/∂y²) is the steepest slope at the point, and the direction θ = atan2(∂f/∂y, ∂f/∂x) is measured anticlockwise from the +x axis, from −180° to 180°. The formula box at the top of this page shows the same rule in symbols: ∇f = (∂f/∂x, ∂f/∂y); |∇f| = √(∂f/∂x² + ∂f/∂y²); direction = atan2(∂f/∂y, ∂f/∂x).

Each partial derivative is a central difference with step h = 0.00001, evaluated on a preset function list. The angle uses atan2 rather than plain arctan, so a gradient pointing into the second or third quadrant gets the right angle instead of the mirrored one. If both partial derivatives are zero, the gradient is the zero vector: the magnitude is 0 and the direction is meaningless, so the calculator shows 0° for the angle in that case. All preset functions are smooth everywhere.

Central differences with h = 0.00001 give about four correct decimal places on smooth functions A derivative calculator can help you check the numbers that feed into this step, and it is worth doing that check before you trust an answer that looks surprising.

The the point explained

The point decides everything about the gradient, and the mistake people make is evaluating at a point they have not thought about. The gradient of x² + y² at (1, 2) points up and to the right with magnitude about 4.47, but at (0, 0) it is the zero vector — the bottom of the bowl — and at (−1, −2) it points down and to the left. Same function, three completely different answers, so the point is not a detail.

Enter the point exactly as the problem states it, and check the sign of each coordinate: a minus sign flips the gradient's direction by 180° in that component. If the magnitude comes out as 0, you may have found a stationary point, which is often the point of the exercise. Sketch the function first if you can: for a bowl the gradient always points away from the centre, so a gradient pointing towards the centre means the point or the function is wrong.

For f = x² + y² the gradient at (x, y) is (2x, 2y), so at (1, 2) it is (2, 4) with magnitude √20 ≈ 4.47 and direction atan2(4, 2) ≈ 63.43°. A slope calculator is a good cross-check when the input comes from a measurement or a table rather than from a textbook problem.

A worked example

Take the default settings on this page: f(x, y) = x² + y² at the point (1, 2).

The components are ∂f/∂x = 2 and ∂f/∂y = 4. The magnitude is √(2² + 4²) = √20 = 4.4721, and the direction is atan2(4, 2) = 63.4349° anticlockwise from the +x axis.

The gradient points up and to the right, at about 63° from the x axis, and its size 4.47 is the steepest slope at that point — steeper than the slope in either axis direction alone, because the steepest direction is diagonal. The direction must lie between 0° and 90° here, because both components are positive, and 63.43° does. A negative angle would have meant a sign error somewhere.

Where the Gradient Calculator is used

In optimisation, the gradient tells an algorithm which way to step: gradient descent walks downhill, against the gradient, and the size of the gradient says how big a step is safe.

In physics, the gradient of a potential energy surface gives the force, with a minus sign: the force points downhill, towards lower energy, and its size is the gradient's magnitude. A trigonometry calculator often sits next to it in the same workflow, because the two answers answer different halves of the same question.

In geography and mapping, the gradient of a height function points straight up the slope, perpendicular to the contour lines, and its magnitude is the steepness a walker would feel.

It also helps to keep the units consistent from the first number to the last. Mixing units — metres with centimetres, degrees with radians, seconds with minutes — is the quietest way to get an answer that looks plausible and is wrong by a large factor. Write the unit next to every number you enter, and check the result's unit against the unit you expect before you use the answer anywhere else.

Gradient Calculator vs Slope Calculator

A slope is the rate of change of a function of one variable, a single number. A gradient is the same idea for a function of two variables, and it needs a vector: two components, a magnitude and a direction. The slope is the one-dimensional version of the gradient.

Use the slope calculator for curves, where there is only one direction to move. Use the gradient calculator for surfaces, where the direction matters as much as the steepness — the fastest way up a hill is a direction, not just a number. The scientific calculator covers the other side of the same problem, so the two tools complement each other rather than compete.

The two agree where they overlap: the gradient's x-component is the slope of the surface in the x direction, exactly what a slope calculator would give for the cross-section of the surface along that axis.

Common mistakes with the Gradient Calculator

The first mistake is treating the gradient as a single number. The magnitude alone says how steep the surface is, but not which way is up — you need the direction too, and a gradient of magnitude 4.47 pointing north is a different answer from one pointing east.

The second mistake is using plain arctan for the direction, which confuses opposite quadrants. Atan2 fixes this by looking at the signs of both components, so a gradient of (−2, −4) correctly gives about −117°, not 63°.

The third mistake is reading the gradient as the slope in a random direction. The gradient is the steepest slope; the slope in any other direction is smaller, and along a contour line it is zero. If you need the slope in a specific direction, take the dot product of the gradient with that direction's unit vector.

A last mistake is trusting the first answer without a rough check. Before you accept a result, estimate it by hand to one significant figure: if the calculator says 400 and your rough estimate says 40, something is off — usually a misplaced decimal point or a wrong unit. The calculator does the arithmetic; the judgement about whether the answer makes sense still belongs to you.

How to use this Gradient Calculator

Open the page and enter the function from the list and the point (x, y) to evaluate at. Pick the function, enter the point, and read the magnitude first, then the components and the direction. The angle is measured anticlockwise from the +x axis.

Read the magnitude as the steepest slope at the point, and the direction as the compass bearing of the fastest rise, in degrees from the +x axis. If the magnitude is 0, the surface is flat at that point — a peak, a valley or a saddle — and the direction shown is meaningless.

Everything runs in your browser. No account, no upload, no data sent anywhere — your numbers never leave your device. If a result looks wrong, re-check the inputs first: a single mistyped number is the usual cause, and a derivative calculator will confirm the arithmetic.

Frequently Asked Questions

The gradient is (2, 4), its magnitude is 4.4721 and its direction is 63.4349° from the +x axis. By hand: ∇f = (2x, 2y) = (2, 4), so |∇f| = √20 ≈ 4.47.

the gradient is the vector of the two partial derivatives, its magnitude is the square root of the sum of their squares, and its direction is the atan2 angle of the components ∇f = (∂f/∂x, ∂f/∂y). The magnitude |∇f| = √(∂f/∂x² + ∂f/∂y²) is the steepest slope at the point, and the direction θ = atan2(∂f/∂y, ∂f/∂x) is measured anticlockwise from the +x axis, from −180° to 180°.

The gradient points in the direction of steepest increase of the function — the fastest way uphill. Its magnitude is the slope in that direction. It is always perpendicular to the contour line through the point, and the negative gradient points in the direction of steepest decrease.

It means the surface is flat at that point: both partial derivatives are zero. The point is a candidate maximum, minimum or saddle point. The gradient alone cannot tell you which, so the next step is the second-derivative test or a look at the function nearby.

More free tools

More calculators and utilities from Sortrun — free, no sign-up.