Logo

MonoCalc

/

Gradient Calculator

Math

Example functions

Evaluate at a point

Directional derivative

Gradient descent preview

Symbolic Gradient

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

∇f = (y * (2 * x + cos(x * y)), x ^ 2 + x * cos(x * y))

∂f/∂x

y * (2 * x + cos(x * y))

∂f/∂y

x ^ 2 + x * cos(x * y)

Gradient at the Point

f(point)
2.909
∇f(point)
(3.168, 0.584)
Magnitude ‖∇f‖
3.221
Direction
10.443°

Step-by-Step Breakdown

1
f(x, y) = x^2*y + sin(x*y)
2
∂f/∂x = y * (2 * x + cos(x * y))

Rules applied: Power Rule, Trig Rule, Product Rule

3
∂f/∂y = x ^ 2 + x * cos(x * y)

Rules applied: Power Rule, Trig Rule, Product Rule

4
∇f = (y * (2 * x + cos(x * y)), x ^ 2 + x * cos(x * y))
5
∇f(x=1.000, y=2.000) = (3.168, 0.584)
6
‖∇f‖ = 3.221

Direction angle θ = atan2(0.584, 3.168) = 10.443°

Contour Map & Gradient Vector

Drag to move the evaluation point

Drag the point to explore how the gradient changes. Domain shown: [-10, 10] on both axes. Orange arrow = gradient (steepest ascent).

About This Tool

Gradient Calculator – Steepest Ascent, Magnitude & Directional Derivatives

The gradient of a multivariable function is the vector of all its first-order partial derivatives. For a function of two variables, f(x, y), the gradient is written ∇f = (∂f/∂x, ∂f/∂y); for three variables, f(x, y, z), it extends to ∇f = (∂f/∂x, ∂f/∂y, ∂f/∂z). This calculator uses the mathjs symbolic engine — the same engine behind the Derivative Calculator — to differentiate your expression with respect to each variable in turn, then optionally substitutes a point to give you a fully numeric result.

Why the Gradient Points “Uphill”

At any point, the gradient vector points in the direction where the function increases fastest — the direction of steepest ascent. Its magnitude, ‖∇f‖ = √(Σ (∂f/∂xᵢ)²), tells you how steep that increase is: a larger magnitude means the function changes more rapidly near that point. Moving in the opposite direction, −∇f, is the direction of steepest descent — the basis of the gradient descent optimization algorithm used throughout machine learning.

Symbolic Gradient

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

The partial derivatives, computed algebraically without needing a numeric point.

Magnitude & Direction

‖∇f‖, θ = atan2(∂f/∂y, ∂f/∂x)

How steep the ascent is, and which way it points, at a specific point.

Directional Derivative

D_u f = ∇f · û

The rate of change of f along any direction you choose, not just steepest ascent.

Evaluating the Gradient at a Point

Once you supply coordinates, the tool substitutes them into each partial derivative expression to produce a numeric gradient vector. From there it computes the magnitude (how steep the surface is) and, for 2-variable functions, the direction angle measured from the positive x-axis using atan2(∂f/∂y, ∂f/∂x). For 3-variable functions, the direction is instead expressed as the angle the gradient makes with each coordinate axis.

Directional Derivatives

The gradient alone tells you the direction of fastest increase, but sometimes you need the rate of change along a specific direction — say, along a path constrained by some other condition. The directional derivative answers this by projecting the gradient onto a unit vector û in your chosen direction: D_u f = ∇f · û. When û points the same way as ∇f, the directional derivative equals the full magnitude ‖∇f‖ — the maximum possible rate of increase. When ûis perpendicular to the gradient, the directional derivative is zero, since moving along a contour line does not change the function’s value.

Why normalize the direction vector?
The directional derivative formula assumes a unit vector. If your direction vector isn’t already length 1, the calculator normalizes it automatically (toggle this off to see the raw, un-normalized dot product instead).

Gradient Descent in One Step

Gradient descent is an iterative optimization method that repeatedly moves a point in the direction of steepest descent: x_new = x − η·∇f(x), where η (eta) is the step size, or learning rate. This calculator previews a single iteration so you can see exactly how the gradient shapes each update — a useful sanity check when implementing or debugging optimization code by hand.

Handling Undefined Points

Not every point lies in a function’s domain. If evaluating the function or any partial derivative would require dividing by zero, taking the square root of a negative number, or the logarithm of a non-positive number, the calculator reports the point as undefined rather than displaying a misleading result.

Practical Applications

Optimization & machine learning: gradient descent and its variants (SGD, Adam) all rely on computing the gradient of a loss function at each step.

Physics: the gradient of a scalar potential field (temperature, pressure, electric potential) gives the direction and strength of the associated force or flow.

Engineering & geography: the gradient of an elevation function points toward the steepest uphill direction on a terrain surface.

Multivariable calculus:setting the gradient equal to the zero vector is the standard first step in locating a function’s critical points.

Limitations

This tool computes gradients over the real numbers for functions built from standard arithmetic, trigonometric, exponential, and logarithmic operations. Piecewise functions, functions with branch cuts, and expressions that simplify only partially may produce unwieldy symbolic results — try expanding or simplifying your expression manually if the output looks unexpectedly long. The interactive contour diagram is available for 2-variable functions only, since a 2D plot cannot faithfully represent a 3-variable surface.

Frequently Asked Questions

Is the Gradient Calculator free?

Yes, Gradient Calculator is totally free :)

Can I use the Gradient Calculator offline?

Yes, you can install the webapp as PWA.

Is it safe to use Gradient Calculator?

Yes, any data related to Gradient Calculator only stored in your browser (if storage required). You can simply clear browser cache to clear all the stored data. We do not store any data on server.

How does the Gradient Calculator work?

Enter a multivariable function such as x^2*y + sin(x*y), choose 2 or 3 variables, and the tool uses the mathjs symbolic engine to compute each partial derivative (∂f/∂x, ∂f/∂y, and ∂f/∂z if applicable). Together these form the gradient vector ∇f. If you supply a point, the calculator also substitutes those coordinates to give the numeric gradient, its magnitude, and its direction.

What does the gradient vector actually represent?

The gradient ∇f is the vector of all first-order partial derivatives of a scalar function. At any point, it points in the direction of steepest ascent — the direction in which the function increases fastest — and its magnitude tells you how steep that increase is.

What is a directional derivative and how is it computed here?

A directional derivative D_u f measures the rate of change of f along a specific direction rather than along the steepest-ascent direction. This tool computes it as the dot product of the gradient with your direction vector, normalized to a unit vector by default (D_u f = ∇f · û).

What does the gradient descent preview show?

Given a step size η (eta) and a starting point, the tool computes one iteration of gradient descent: x_new = x − η·∇f(x). This illustrates how optimization algorithms use the gradient to move toward a function's minimum, one step at a time.

What happens if the function is undefined at my chosen point?

If evaluating the function or any partial derivative at your point involves dividing by zero, taking the square root of a negative number, or the logarithm of a non-positive number, the calculator reports the point as undefined instead of showing a misleading NaN result.

Can I switch between degrees and radians for the direction angle?

Yes. For 2-variable functions the direction angle (measured from the positive x-axis) can be displayed in either degrees or radians. For 3-variable functions, the tool instead reports the angle the gradient makes with each coordinate axis, in your chosen unit.