# Gradient and Directional Derivatives: Formula and Examples

> Learn what the gradient vector is, how to compute a directional derivative with a unit vector, and why the gradient points in the direction of steepest ascent.

Source: https://practicecalculus.com/blog/gradient-and-directional-derivatives
Updated: 2026-10-04

## Key takeaways

- The gradient $\nabla f = \langle f_x, f_y \rangle$ collects all the first partial derivatives into one vector.
- The directional derivative in the direction of a unit vector $\mathbf{u}$ is $D_{\mathbf{u}} f = \nabla f \cdot \mathbf{u}$. The vector must have length 1.
- The gradient points in the direction of steepest ascent, and its length $|\nabla f|$ is that steepest rate of increase.
- The gradient is perpendicular to the level curve (or level surface) through the point.

You are standing on a hillside described by $z = f(x, y)$. Partial derivatives tell you how steep the ground is if you walk due east or due north. But what if you walk northeast? And which way should you walk to climb as fast as possible? The gradient answers both questions with a single vector.

This guide explains the gradient, the directional derivative formula, why the gradient points uphill, and works through four complete examples.

## What is the gradient?

The **gradient** of a function is the vector of its first [partial derivatives](/blog/partial-derivatives). For two and three variables:

$$\nabla f(x, y) = \langle f_x(x, y),\ f_y(x, y) \rangle, \qquad \nabla f(x, y, z) = \langle f_x, f_y, f_z \rangle$$

The symbol $\nabla$ is read "del" or "grad." The gradient is a vector-valued function: at each point it gives you a vector that lives in the input plane (the $xy$-plane), not on the surface.

For example, if $f(x, y) = x^2 + 3xy$, then $f_x = 2x + 3y$ and $f_y = 3x$, so

$$\nabla f(x, y) = \langle 2x + 3y,\ 3x \rangle, \qquad \nabla f(1, 2) = \langle 8, 3 \rangle$$

## The directional derivative formula

The **directional derivative** of $f$ at a point in the direction of a **unit vector** $\mathbf{u}$ is the rate of change of $f$ per unit distance traveled in that direction:

$$D_{\mathbf{u}} f(x, y) = \nabla f(x, y) \cdot \mathbf{u}$$

If $\mathbf{u} = \langle u_1, u_2 \rangle$, that is $D_{\mathbf{u}} f = f_x u_1 + f_y u_2$.

Partial derivatives are special cases. With $\mathbf{u} = \langle 1, 0 \rangle$ you get $D_{\mathbf{u}} f = f_x$, and with $\mathbf{u} = \langle 0, 1 \rangle$ you get $f_y$.

How to compute a directional derivative:

1. Find the gradient $\nabla f$ and evaluate it at the point.
2. Turn the direction into a **unit vector**: divide by its length, or use $\mathbf{u} = \langle \cos\theta, \sin\theta \rangle$ for an angle $\theta$.
3. Take the [dot product](/blog/vectors-dot-and-cross-product) of the two.

> **Tip:** step 2 is the one people skip. If the problem says "in the direction of $\langle 3, 4 \rangle$," you must use $\langle \frac{3}{5}, \frac{4}{5} \rangle$.

## Worked example 1: a direction given by a vector

Find the directional derivative of $f(x, y) = x^2 + 3xy$ at $(1, 2)$ in the direction of $\mathbf{v} = \langle 3, 4 \rangle$.

**Step 1. Gradient at the point.** From above, $\nabla f(1, 2) = \langle 2(1) + 3(2),\ 3(1) \rangle = \langle 8, 3 \rangle$.

**Step 2. Unit vector.** $|\mathbf{v}| = \sqrt{9 + 16} = 5$, so $\mathbf{u} = \left\langle \frac{3}{5}, \frac{4}{5} \right\rangle$.

**Step 3. Dot product.**

$$D_{\mathbf{u}} f(1, 2) = 8 \cdot \frac{3}{5} + 3 \cdot \frac{4}{5} = \frac{24}{5} + \frac{12}{5} = \frac{36}{5} = 7.2$$

Moving from $(1, 2)$ toward $\langle 3, 4 \rangle$, $f$ increases at about $7.2$ units per unit of distance.

## Worked example 2: a direction given by an angle

Find the directional derivative of $f(x, y) = x e^y$ at $(2, 0)$ in the direction making an angle $\theta = \frac{\pi}{3}$ with the positive $x$-axis.

**Step 1. Gradient.** $f_x = e^y$ and $f_y = x e^y$, so $\nabla f(2, 0) = \langle e^0, 2e^0 \rangle = \langle 1, 2 \rangle$.

**Step 2. Unit vector from the angle.**

$$\mathbf{u} = \left\langle \cos\tfrac{\pi}{3}, \sin\tfrac{\pi}{3} \right\rangle = \left\langle \tfrac{1}{2}, \tfrac{\sqrt{3}}{2} \right\rangle$$

This is already length 1, so no dividing is needed.

**Step 3. Dot product.**

$$D_{\mathbf{u}} f(2, 0) = 1 \cdot \frac{1}{2} + 2 \cdot \frac{\sqrt{3}}{2} = \frac{1}{2} + \sqrt{3} \approx 2.23$$

## Why the gradient points in the direction of steepest ascent

Use the geometric form of the dot product. If $\theta$ is the angle between $\nabla f$ and the unit vector $\mathbf{u}$, then

$$D_{\mathbf{u}} f = |\nabla f|\,|\mathbf{u}|\cos\theta = |\nabla f|\cos\theta$$

Since $\cos\theta$ ranges from $-1$ to $1$, three facts drop out:

- **Steepest ascent:** the largest value, $|\nabla f|$, happens at $\theta = 0$, when $\mathbf{u}$ points along $\nabla f$.
- **Steepest descent:** the smallest value, $-|\nabla f|$, happens at $\theta = \pi$, when $\mathbf{u}$ points along $-\nabla f$.
- **No change:** $D_{\mathbf{u}} f = 0$ when $\theta = \frac{\pi}{2}$, that is in directions perpendicular to $\nabla f$. Those are the directions along the level curve.

That last fact means **the gradient is always perpendicular to the level curves of $f$**. On a topographic map, the gradient points straight uphill, crossing the contour lines at right angles.

## Worked example 3: steepest ascent on a hill

The height of a hill is $f(x, y) = 100 - x^2 - 2y^2$. A hiker stands at $(3, 1)$.

**Step 1. Gradient.** $\nabla f = \langle -2x, -4y \rangle$, so $\nabla f(3, 1) = \langle -6, -4 \rangle$.

**Step 2. Direction of steepest ascent.** It is $\langle -6, -4 \rangle$, or as a unit vector,

$$\mathbf{u} = \frac{\langle -6, -4 \rangle}{\sqrt{36 + 16}} = \frac{\langle -3, -2 \rangle}{\sqrt{13}}$$

It points uphill, roughly back toward the summit at the origin. (Not exactly at it: the hill is steeper in the $y$ direction, so the gradient heads toward the $x$-axis more sharply than a straight line to the top would.)

**Step 3. Steepest rate.** $|\nabla f(3, 1)| = \sqrt{52} = 2\sqrt{13} \approx 7.21$.

**Step 4. Steepest descent.** The opposite direction, $\langle 6, 4 \rangle$, with rate $-2\sqrt{13}$.

**Step 5. Level directions.** Perpendicular to $\langle -3, -2 \rangle$ are $\langle 2, -3 \rangle$ and $\langle -2, 3 \rangle$ (check: $-6 + 6 = 0$). Walking either way keeps the hiker at the same height, at least instantaneously.

The point $(3, 1)$ lies on the level curve $x^2 + 2y^2 = 11$ (where the height is $89$). The graph shows that curve, the gradient direction, and the tangent direction. They meet at a right angle.

```graph
title: 'Level curve x² + 2y² = 11 of the hill f(x, y) = 100 − x² − 2y², with the gradient line and tangent line at (3, 1)'
caption: 'At $(3, 1)$ the gradient $\langle -6, -4 \rangle$ points uphill along the gradient line, perpendicular to the level curve. The tangent direction $\langle 2, -3 \rangle$ keeps $f$ constant.'
x: [-5, 5]
y: [-3, 3]
functions:
    - expr: sqrt((11 - x^2)/2)
      label: level curve x² + 2y² = 11
    - expr: -sqrt((11 - x^2)/2)
      color: '#5b4fe0'
    - expr: 2x/3 - 1
      label: gradient direction
      dashed: true
    - expr: 5.5 - 1.5x
      label: tangent to level curve
      dashed: true
points:
    - [3, 1, '(3, 1)']
    - [0, 0, 'summit']
```

## Worked example 4: three variables

Find the directional derivative of $f(x, y, z) = xyz$ at $P(1, 2, 3)$ in the direction of the point $Q(2, 4, 5)$.

**Step 1. Gradient.** $\nabla f = \langle yz, xz, xy \rangle$, so $\nabla f(1, 2, 3) = \langle 6, 3, 2 \rangle$.

**Step 2. Direction vector.** $\overrightarrow{PQ} = \langle 1, 2, 2 \rangle$, with length $\sqrt{1 + 4 + 4} = 3$. So $\mathbf{u} = \left\langle \frac{1}{3}, \frac{2}{3}, \frac{2}{3} \right\rangle$.

**Step 3. Dot product.**

$$D_{\mathbf{u}} f(1, 2, 3) = 6 \cdot \frac{1}{3} + 3 \cdot \frac{2}{3} + 2 \cdot \frac{2}{3} = 2 + 2 + \frac{4}{3} = \frac{16}{3}$$

The maximum possible rate at $P$ is $|\nabla f| = \sqrt{36 + 9 + 4} = 7$, so this direction gets you $\frac{16}{3} \approx 5.33$ out of a possible $7$.

In three variables the gradient is perpendicular to the **level surface** $f(x, y, z) = c$, which is why $\nabla f$ is used as the normal vector for tangent planes.

## Common mistakes with gradients and directional derivatives

1. **Not normalizing the direction.** Using $\langle 3, 4 \rangle$ instead of $\langle \frac{3}{5}, \frac{4}{5} \rangle$ makes the answer 5 times too large.
2. **Using the point instead of the direction.** In example 4, the direction is $Q - P$, not $Q$ itself.
3. **Forgetting to evaluate the gradient at the point.** The answer to a directional derivative question is a number, not a formula.
4. **Thinking the gradient lives on the surface.** For $z = f(x, y)$, $\nabla f$ is a 2D vector in the $xy$-plane telling you which way to walk.
5. **Mixing up the maximum rate and its direction.** The direction is $\nabla f$ (or its unit vector). The rate is the number $|\nabla f|$.

## Quick reference: gradient facts

| Question | Answer |
| --- | --- |
| Gradient of $f(x, y)$ | $\nabla f = \langle f_x, f_y \rangle$ |
| Rate of change in direction $\mathbf{u}$ ($\lvert\mathbf{u}\rvert = 1$) | $D_{\mathbf{u}} f = \nabla f \cdot \mathbf{u}$ |
| Unit vector at angle $\theta$ | $\langle \cos\theta, \sin\theta \rangle$ |
| Direction of fastest increase | $\nabla f$ |
| Fastest rate of increase | $\lvert \nabla f \rvert$ |
| Direction of fastest decrease | $-\nabla f$ |
| Directions of zero change | perpendicular to $\nabla f$ (along the level curve) |

## Practice until it feels like reading a map

Once you can compute a gradient in your head and remember to normalize the direction, these problems become quick points on an exam. They are also the key idea behind [Lagrange multipliers](/blog/lagrange-multipliers). The interactive lesson below gives you surfaces, points and directions to work with, and checks every step instantly so you catch a missing unit vector the first time.

## Frequently asked questions

### What is the gradient of a function?

The gradient of $f(x, y)$ is the vector $\nabla f = \langle f_x, f_y \rangle$ of its partial derivatives, and for three variables it adds $f_z$. At each point it points in the direction where $f$ increases fastest, and its length is that fastest rate of increase.

### What is a directional derivative?

A directional derivative is the rate of change of $f$ as you move from a point in a chosen direction. It generalizes partial derivatives, which only measure change along the coordinate axes. You compute it as $D_{\mathbf{u}} f = \nabla f \cdot \mathbf{u}$ with $\mathbf{u}$ a unit vector.

### Why does the direction vector have to be a unit vector?

The directional derivative is a rate per unit of distance. If you use a longer vector, the dot product is scaled by its length and the answer is too big. Always divide the direction vector by its length first.

### Why does the gradient point in the direction of steepest ascent?

Since $D_{\mathbf{u}} f = |\nabla f|\cos\theta$, where $\theta$ is the angle between $\nabla f$ and $\mathbf{u}$, the rate is largest when $\cos\theta = 1$, that is when $\mathbf{u}$ points the same way as $\nabla f$. The largest rate is then $|\nabla f|$.

### What is the relationship between the gradient and level curves?

At any point, the gradient is perpendicular to the level curve through that point. Moving along the level curve keeps $f$ constant, so the directional derivative along it is 0, which forces the gradient to be at right angles to it.
