Gradient Calculator
- Free
- No sign-up
- Works on phones
- Shows the working
The gradient calculator finds \( \nabla f \) for a function of two variables at a point, along with its length. It also works as a directional derivative calculator: give it a direction vector and it returns \( D_{\mathbf u} f \), the rate at which \( f \) changes as you move that way.
It’s aimed at multivariable calculus students working on gradients, steepest ascent and level curves. It is free and needs no sign-up.
How to use the gradient calculator
- Type \( f(x, y) \). Use
^for powers andsqrt(),sin(),ln(),e^(x)andpifor functions. Implicit multiplication like3x yworks. - Enter the point \( (x_0, y_0) \).
- Enter a direction \( \langle u_1, u_2 \rangle \). It doesn’t have to be a unit vector, because the calculator normalizes it for you. It just can’t be the zero vector.
- Press Compute gradient. The output lists \( \nabla f \), \( |\nabla f| \), the unit vector \( \hat{\mathbf u} \) and the directional derivative \( D_{\hat{\mathbf u}} f \).
Formula
The gradient collects the two partial derivatives into a vector:
$$\nabla f(x, y) = \left\langle f_x(x, y),\ f_y(x, y) \right\rangle$$
The directional derivative in the direction of a vector \( \mathbf u \) is the dot product of the gradient with the unit vector \( \hat{\mathbf u} = \frac{\mathbf u}{|\mathbf u|} \):
$$D_{\hat{\mathbf u}} f = \nabla f \cdot \hat{\mathbf u} = f_x\,\hat u_1 + f_y\,\hat u_2$$
Since \( \nabla f \cdot \hat{\mathbf u} = |\nabla f|\cos\theta \), the largest possible rate is \( |\nabla f| \), in the direction of \( \nabla f \) itself. The rate is \( -|\nabla f| \) in the opposite direction, and 0 at right angles to it. The calculator computes \( f_x \) and \( f_y \) symbolically, evaluates them at the point, and applies these formulas.
Worked example
Example 1: gradient and directional derivative. Let \( f(x, y) = x^2y - y^3 \). Find \( \nabla f(2, 1) \) and the rate of change of \( f \) at \( (2, 1) \) in the direction \( \langle 3, -4 \rangle \).
First the partials: \( f_x = 2xy \) and \( f_y = x^2 - 3y^2 \). At \( (2, 1) \):
$$\nabla f(2, 1) = \langle 4,\ 4 - 3 \rangle = \langle 4, 1 \rangle, \qquad |\nabla f| = \sqrt{17} \approx 4.1231$$
The direction vector has length \( \sqrt{9 + 16} = 5 \), so \( \hat{\mathbf u} = \langle 0.6, -0.8 \rangle \). Then
$$D_{\hat{\mathbf u}} f = 4(0.6) + 1(-0.8) = 1.6 = \tfrac85.$$
Moving from \( (2, 1) \) toward \( \langle 3, -4 \rangle \), \( f \) increases at 1.6 units per unit of distance. This is the example loaded in the calculator above.
Example 2: fastest and flat directions. Same function and point. Where does \( f \) increase fastest, and in which direction does it not change at all?
- Steepest ascent is along \( \nabla f = \langle 4, 1 \rangle \), and the rate there is \( \sqrt{17} \). Enter \( u_1 = 4 \), \( u_2 = 1 \) and the calculator shows \( D_{\hat{\mathbf u}} f = \sqrt{17} \). The unit vector is about \( \langle 0.9701, 0.2425 \rangle \).
- Zero rate happens perpendicular to the gradient, for example along \( \langle 1, -4 \rangle \): \( \frac{4(1) + 1(-4)}{\sqrt{17}} = 0 \). That direction is tangent to the level curve \( x^2y - y^3 = 3 \) through \( (2, 1) \).
How to read the output
- \( \nabla f \) is a vector at the point, not a number. It points uphill, in the direction of steepest increase.
- \( |\nabla f| \) is the steepest slope available at that point. When it is 0, you are at a critical point, which is where optimization problems look for maxima and minima.
- \( \hat{\mathbf u} \) is your direction scaled to length 1. If you forget to normalize by hand, your directional derivative will be off by a factor of \( |\mathbf u| \), which is the most common mistake on exams.
- \( D_{\hat{\mathbf u}} f \) is a signed number. Positive means \( f \) increases in that direction, negative means it decreases.
- The gradient is perpendicular to level curves. Contour lines of \( f \) cross \( \nabla f \) at right angles, which is why it’s used for normal vectors and tangent lines to curves \( f(x, y) = k \).
For the derivation of \( D_{\hat{\mathbf u}} f = \nabla f \cdot \hat{\mathbf u} \) and more practice, see the guide to the gradient and directional derivative. If you only need \( f_x \) and \( f_y \), start with partial derivatives or the partial derivative calculator.
Related guides
- Gradient and Directional Derivative: Formulas and Examples
- Partial Derivatives: How to Calculate Them
- Linear Approximation (Linearization): Formula and Examples
- Optimization Problems in Calculus: 4 Solved Examples
Further reading
- Directional Derivatives (Paul’s Online Math Notes) — the gradient, \( D_{\mathbf u} f = \nabla f \cdot \mathbf u \) and the maximum rate of change.
- Partial Derivatives (Paul’s Online Math Notes) — how to compute the two components of the gradient.
FAQ
What is the difference between the gradient and the directional derivative?
The gradient is a vector made of the partial derivatives. The directional derivative is a single number: the gradient dotted with a unit direction vector.
Do I need to enter a unit vector?
No. Enter any nonzero direction, such as \( \langle 3, -4 \rangle \). The calculator divides by its length before taking the dot product and shows the unit vector it used.
What is the maximum value of the directional derivative?
It is \( |\nabla f| \), reached when you move in the direction of the gradient. The minimum is \( -|\nabla f| \), in the opposite direction.
Does the gradient calculator work in three dimensions?
No. It handles functions \( f(x, y) \) of two variables with a two-component direction vector.
