Partial Derivatives and the Gradient

Drag the point across the contour map. The two partial derivatives are the slopes along the axes; turn the heading dial and "Slope this way" is the slope you would feel walking in that direction.

The partial derivative
The slope in direction u
The tangent plane
The second-derivative test, at a point where ∇f = 0 (D < 0: a saddle)
Loading interactive simulation...

Lesson

The theory — Partial Derivatives and the Gradient

A partial derivative of f(x, y) is the ordinary derivative in one variable with the other held fixed: fx is the slope of the surface walking in the x-direction, fy walking in the y-direction.

What each symbol means

∇f
the gradient, the vector (f_x, f_y)
θ
the heading, in degrees round from east
D
the discriminant f_xx f_yy − f_xy²

Where the formula comes from

  1. Hold one variable still. For fx, treat y as a constant and differentiate as usual; for fy, the other way round.
  2. The gradient. The two partials make a vector, ∇f. It points up the steepest slope, the coloured arrow on the map, and its length is that slope.
  3. Any other direction. The slope on a heading θ is the dot product of the gradient with the unit vector that way: the steepest slope times the cosine of the angle off it, and 0 along the contour.
  4. The tangent plane. Close to a point the surface is nearly a plane, with the two partials as its slopes. It is the two-variable form of the tangent line on the derivative page.
  5. Where both partials are 0. The point is critical, and the discriminant D decides: D > 0 with fxx > 0 is a minimum, D > 0 with fxx < 0 a maximum, D < 0 a saddle, and D = 0 says nothing.

Problems solved in full

  1. First and second partial derivatives 4 steps

    For f(x, y) = x³y² − 2xy + y³, find fx, fy and the three second partial derivatives at (1, 2), and check that the two mixed ones agree.

    Open this problem in the tool

    1. For fx treat y as a constant, and for fy treat x as one:

    2. At (1, 2):

    3. Differentiate again. The mixed partial can be taken in either order:

    4. At (1, 2):

    Answer

    fx = 8, fy = 14, fxx = 24, fyy = 14 and fxy = fyx = 10. The two mixed partials agree wherever they are continuous, which is Schwarz's theorem, often credited to Clairaut; every polynomial qualifies.

  2. The slope in a given direction, and the steepest one 4 steps

    For f(x, y) = x²y + y³, find the rate of change at (2, 1) in the direction of the vector (3, 4), and the largest rate of change there, with its direction.

    Open this problem in the tool

    Show solution
    1. The gradient first:

    2. A direction has to be a unit vector, and (3, 4) has length 5:

    3. The directional derivative is the dot product:

    4. The largest rate is the length of the gradient, in the gradient's own direction:

    Answer

    8 in the direction of (3, 4); at most √65 = 8.062, on a heading of 60.3°. Forgetting to divide (3, 4) by its length gives 40, five times too much, and it is the commonest slip in this question.

  3. The tangent plane, and an estimate from it 3 steps

    Find the tangent plane to z = √(x² + y²) at (3, 4), and use it to estimate √(3.02² + 3.97²).

    Open this problem in the tool

    Show solution
    1. At (3, 4) the height is 5, and the partials are x/√(x² + y²) and y/√(x² + y²):

    2. The tangent plane uses the height and both slopes:

    3. At (3.02, 3.97):

    Answer

    The tangent plane is z = 0.6x + 0.8y, and it gives 4.988 against a true 4.988116. Close to (3, 4) the surface is nearly flat, so the plane tracks it, as the tangent line tracked a curve on the derivative page.

  4. Critical points and the second-derivative test 3 steps

    Find and classify the critical points of f(x, y) = x³ + y³ − 3xy.

    Open this problem in the tool

    Show solution
    1. Set both partial derivatives to 0:

    2. The first gives y = x², and the second then gives x⁴ = x, so x = 0 or x = 1:

    3. The second partials are fxx = 6x, fyy = 6y and fxy = −3. Test each point:

    Answer

    (0, 0) is a saddle and (1, 1) a local minimum, with f(1, 1) = −1. It is not the lowest point of the surface: along the line y = x, f = 2x³ − 3x², which falls without bound as x → −∞.

  5. Steepness of a hillside rising 3 metres east and 4 metres north 6 steps

    You are on a hillside where the ground rises 3 metres per 100 travelled due east, and 4 metres per 100 travelled due north. How steep is the hill, which way does it fall, and what heading must a road take to climb at half that gradient?

    Open this problem in the tool

    Show solution
    1. Those two measurements are the partial derivatives. Keeping them as 3 and 4 per hundred reads more easily than 0.03 and 0.04, and changes nothing.

    2. The steepest slope is the length of the gradient, which is neither the sum of the parts nor the larger of them. Three and four give five, and five is what a walker feels.

    3. Its heading is atan2(4, 3), which is 53.1° round from east. Downhill is the opposite way, at 233.1°. Nothing was measured along either.

    4. For a road at 2.5 per hundred, run the identity backwards. The slope on a heading θ away from that steepest heading is 5 cos θ, so cos θ = 2.5/5 and θ = 60°.

    5. Sixty, not forty-five. A road at 45° would still be climbing at 3.54 per hundred, which is 71% of the steepest and nowhere near half of it.

    6. The length comes from the same cosine. Gaining a fixed height at half the gradient means covering twice the ground for as long as the slope holds, and that factor of two is what the switchbacks on a mountain road are made of.

    Answer

    The hill is 5 m per 100 m, rising at a heading of 53.1° and falling at 233.1°, and a road holding 2.5 m per 100 m must run 60° off that steepest heading and travel twice as far. The tool answers the first half: point it any way you like and it gives the slope. The second half is the inverse question, and it is the one that a road engineer, a ramp accessibility standard and a ski piste grading all actually ask. Given the gradient I am allowed, what heading am I forced onto?

  6. The heading with no slope, and how long it stays level 6 steps

    At (1, 1) on 1.5x² + 2y² the panel puts the slope on a heading of 143.1° at 0.000. Work out what the ground does if you keep walking that way, and decide whether that heading is one you could follow to stay level.

    Open this problem in the tool

    Show solution
    1. A quarter turn from the steepest heading of 53.1°. The two terms of the dot product come out −2.4 and +2.4, so the slope card reads 0.000.

    2. Zero slope is a statement about the first derivative and nothing else. Take the second one along the same heading. It is the quadratic form built from the three second partials, with the same cosine and sine inside it.

    3. On this surface f_xx is 3, f_yy is 4 and the mixed partial is 0, so the second derivative along the level heading is 3.36. Positive, so the ground curves upward.

    4. The height along that line is therefore a parabola with its lowest point where you are standing. Half a unit out the ground has risen 0.42, from 3.5 to 3.92, and the slice panel draws exactly that curve.

    5. Turn it into a property of the contour. The curve that really does hold height bends away from the tangent at the second derivative divided by the gradient: 0.672, which is a radius of 1.488.

    6. The standard formula for the curvature of a level set gives the same number from the partials alone, with no heading anywhere in it. Two routes, one answer, and it is exactly 84/125.

    Answer

    No. That heading is level for an instant and then climbs. Walk half a unit along it and you have gained 0.42, where the first derivative predicted 0. The two zero-slope headings are tangents to the contour rather than the contour itself, and staying level means turning continuously, on a circle of radius 1.488 at this point. The panel gives you the tangent; the curvature says how far it is worth trusting.

The hill is steeper than anything you measured 🖖

Stand at (1, 1) on 1.5x² + 2y². Walk due east and the ground rises at 3. Walk due north and it rises at 4. Neither of those is the steepest slope at that point: the steepest is 5, on a heading of 53.1°, and you did not walk it. A partial derivative is the slope along one axis and nothing more, and the axes are an accident of where somebody laid the paper. What combines them is Pythagoras rather than addition, so the steepest slope is √(fx² + fy²), which can never come out smaller than the size of either, and is strictly larger unless one of them is zero. The gap is widest when the two are equal: measure 1 along each axis and the ground is actually rising at 1.414, which is 41% more than either measurement reported.

Every heading at once, and it is one cosine 🖖

Turn the dial through a full circle and watch the slope readout. It traces a cosine, |∇f| cos(θ − θg), where θg is the steepest heading. That is the entire first-order behaviour of a smooth surface at a point, and one consequence is drawn on the map: wherever the gradient is not zero, two headings have no slope at all, a quarter turn either side of the steepest. Those two point along the contour, which is why the steepest path up a hill crosses contours at right angles and why a contour map can be read at a glance. The same cosine kills a plausible shortcut. At 45° off the steepest line you are still climbing at 71% of the full gradient, not half of it, so cutting the corner on a hill buys much less than it looks.

Level in both directions is not the top 🖖

Press Neither top nor bottom. Both partial derivatives are zero at the origin of x² − y², and the point is neither a maximum nor a minimum: along the x-axis it is the bottom of a valley, along the y-axis the top of a ridge. Now press Both axes level, which is the surface xy. Here both axes are exactly level, the slice panel drawing a flat line at 0° and again at 90°, and the point is still a saddle. Its rise and fall sit on the diagonals, where nobody thought to look. What separates the cases is the discriminant fxxfyy − fxy², which is −4 for the first surface and −1 for the second: negative says saddle, positive says one or the other, and the sign of fxx then says which. On x³ − 3xy² the discriminant comes out 0 and the test has nothing to report. That surface has three wedges rising out of the origin and three falling, and no second derivative in the calculation can see them.

Learning path

Why everything looks straight up close