Skip to content
Tutorials Center
My learning

Topics

Lesson 17 of 39 · The Gradient and Directional Derivatives

Gradients, Level Sets and Tangent Planes

Why the gradient is normal to level curves and surfaces, and how to write tangent lines, tangent planes and normal lines to level sets, with Python.

Earlier we met two ways to describe a surface: as a graph z = f(x, y) and as a level surface F(x, y, z) = c. The gradient connects the second view to geometry: at every point, ∇F is a normal vector to the level surface. This gives tangent planes and normal lines for almost any surface with one formula.

The key fact

Suppose a smooth curve r(t) lies on the level surface F(x, y, z) = c. Then F(r(t)) = c is constant, so by the chain rule

Text
d/dt F(r(t)) = ∇F · r'(t) = 0

So the gradient is perpendicular to the velocity vector of every curve on the surface through the point. Those velocity vectors fill the tangent plane, so ∇F is perpendicular to the tangent plane. The same argument in two dimensions shows that ∇f is perpendicular to the level curves of f(x, y).

Tangent plane and normal line to a level surface

If ∇F(x₀, y₀, z₀) ≠ 0, then:

  • Tangent plane: F_x(x₀, y₀, z₀)(x - x₀) + F_y(x₀, y₀, z₀)(y - y₀) + F_z(x₀, y₀, z₀)(z - z₀) = 0.
  • Normal line: ⟨x₀, y₀, z₀⟩ + t ∇F(x₀, y₀, z₀).

Worked example: the ellipsoid x² + 2y² + 3z² = 6 at (1, 1, 1). Check: 1 + 2 + 3 = 6. F = x² + 2y² + 3z², ∇F = ⟨2x, 4y, 6z⟩ = ⟨2, 4, 6⟩. Tangent plane: 2(x - 1) + 4(y - 1) + 6(z - 1) = 0, i.e. x + 2y + 3z = 6. Normal line: ⟨1 + 2t, 1 + 4t, 1 + 6t⟩.

Python Tangent plane and normal line of a level surface

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Graphs as level surfaces

The surface z = f(x, y) is the level set F = 0 of F(x, y, z) = f(x, y) - z. Then ∇F = ⟨f_x, f_y, -1⟩, and the tangent plane is f_x(x - a) + f_y(y - b) - (z - c) = 0, which is exactly the formula from the tangent-plane lesson. Everything fits together.

Worked example: z = x² + y² at (1, 2, 5). ∇F = ⟨2, 4, -1⟩, so the plane is 2(x - 1) + 4(y - 2) - (z - 5) = 0, i.e. z = 2x + 4y - 5.

Tangent line to a level curve

For f(x, y) = c at (x₀, y₀) with ∇f ≠ 0: the tangent line is f_x(x₀, y₀)(x - x₀) + f_y(x₀, y₀)(y - y₀) = 0.

Worked example: x² + xy + y² = 7 at (2, 1): 4 + 2 + 1 = 7. ∇f = ⟨2x + y, x + 2y⟩ = ⟨5, 4⟩. Tangent line: 5(x - 2) + 4(y - 1) = 0, i.e. 5x + 4y = 14. Its slope is -5/4, matching dy/dx = -F_x/F_y.

Python Gradient is perpendicular to the contour

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Angles between surfaces

Two surfaces meet at a point; the angle between them is defined as the angle between their normal vectors (that is, between their tangent planes). They are orthogonal at the point if ∇F · ∇G = 0.

Worked example: the sphere x² + y² + z² = 3 and the plane x + y + z = 3 both pass through (1, 1, 1). ∇F = ⟨2, 2, 2⟩, ∇G = ⟨1, 1, 1⟩: parallel normals, so the plane is tangent to the sphere there.

Python Tangency test between two surfaces

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Gradient = normal

Level surface F = c
∇F is its normal
Gives tangent plane
1 / 2

For a curve or surface given by any equation, move everything to one side to define F, then compute ∇F. This avoids solving for a variable.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. A normal vector to the surface x² + y² - z = 0 at (1, 1, 2) is

    ∇F = ⟨2x, 2y, -1⟩ = ⟨2, 2, -1⟩ at the point.
  2. 2. The tangent line to x² + y² = 25 at (3, 4) is

    ∇f = ⟨6, 8⟩; 6(x - 3) + 8(y - 4) = 0 simplifies to 3x + 4y = 25.
  3. 3. Why is ∇F perpendicular to the level surface F = c?

    Differentiating F(r(t)) = c shows the gradient is orthogonal to every tangent direction.
  4. 4. Two surfaces are tangent at a point when their normals are

    Parallel normals mean the tangent planes coincide.

Summary

  • ∇F at a point of the level surface F = c is normal to the surface.
  • Tangent plane: ∇F(P₀) · (r - r₀) = 0; normal line: r₀ + t ∇F(P₀).
  • Graphs z = f(x, y) are level surfaces of f - z, which recovers the earlier tangent plane.
  • The angle between surfaces is the angle between their normals.

Next: Gradient Descent and Steepest Ascent in Practice