multivariable calc25 min

Vector Fields

Assign a vector to every point in space, then measure divergence and curl to understand flow and rotation

0/9Not Started

Why This Matters

A vector field assigns a vector to every point in a region. Wind velocity at every point on a weather map, the force of gravity at every point in space, the velocity of water in a river -- all of these are vector fields. Understanding how to analyze them is essential for physics, engineering, and computer graphics.

Two fundamental measurements tell you what a vector field is doing at each point. Divergence measures how much the field is spreading out from (or converging into) a point -- it detects sources and sinks. Curl measures how much the field is swirling or rotating around a point -- it detects vortices. Together, divergence and curl give a complete local picture of any vector field. They are the key ingredients in Maxwell equations, fluid dynamics, and the great integral theorems (Green, Stokes, Divergence).

Define Terms

Visual Model

Vector Field FF(x,y) = (P, Q)
dP/dxHow P changes in x
dQ/dyHow Q changes in y
dP/dyHow P changes in y
dQ/dxHow Q changes in x
DivergencedP/dx + dQ/dy
Curl (2D)dQ/dx - dP/dy
Source / Sinkdiv > 0 or div < 0
Rotationcurl > 0 or curl < 0

The full process at a glance. Click Start tour to walk through each step.

Divergence detects sources and sinks. Curl detects rotation. Together they characterize the local behavior of any vector field.

Code Example

Code
// Vector fields: divergence and curl in 2D and 3D

// 2D vector field F(x, y) = (P, Q)
function F2d(x, y) {
  return [x * y, x * x - y];  // P = xy, Q = x^2 - y
}

// Numerical partial derivative helper
function partialD(fn, argIndex, point, h = 1e-6) {
  const pPlus = [...point];
  const pMinus = [...point];
  pPlus[argIndex] += h;
  pMinus[argIndex] -= h;
  return (fn(...pPlus) - fn(...pMinus)) / (2 * h);
}

// 2D divergence: dP/dx + dQ/dy
function divergence2d(field, x, y) {
  const P = (a, b) => field(a, b)[0];
  const Q = (a, b) => field(a, b)[1];
  const dPdx = partialD(P, 0, [x, y]);
  const dQdy = partialD(Q, 1, [x, y]);
  return dPdx + dQdy;
}

// 2D curl (scalar): dQ/dx - dP/dy
function curl2d(field, x, y) {
  const P = (a, b) => field(a, b)[0];
  const Q = (a, b) => field(a, b)[1];
  const dQdx = partialD(Q, 0, [x, y]);
  const dPdy = partialD(P, 1, [x, y]);
  return dQdx - dPdy;
}

console.log("F(1,2) =", F2d(1, 2)); // [2, -1]
// Exact: div = y + (-1) = y - 1, curl = 2x - x = x
console.log("div F at (1,2):", divergence2d(F2d, 1, 2).toFixed(4)); // 1
console.log("curl F at (1,2):", curl2d(F2d, 1, 2).toFixed(4));     // 1

// 3D curl: cross product of nabla and F
function F3d(x, y, z) {
  return [y * z, x * z, x * y]; // conservative field
}

function curl3d(field, x, y, z) {
  const Fx = (a, b, c) => field(a, b, c)[0];
  const Fy = (a, b, c) => field(a, b, c)[1];
  const Fz = (a, b, c) => field(a, b, c)[2];
  const p = [x, y, z];
  return [
    partialD(Fz, 1, p) - partialD(Fy, 2, p),
    partialD(Fx, 2, p) - partialD(Fz, 0, p),
    partialD(Fy, 0, p) - partialD(Fx, 1, p)
  ];
}

console.log("3D curl at (1,2,3):", curl3d(F3d, 1, 2, 3).map(v => v.toFixed(4)));
// Should be [0, 0, 0] since F = grad(xyz) is conservative

Interactive Experiment

Try these exercises:

  • Compute divergence and curl of F(x,y) = (x, y). This is a radial outward field. What do you expect the divergence to be? What about the curl?
  • Try F(x,y) = (-y, x), which represents pure counterclockwise rotation. Compute its divergence (should be 0) and curl (should be 2).
  • Create the field F(x,y) = (x^2, y^2). Where is the divergence positive? Where is it negative? Plot the field vectors at several points to build intuition.
  • For the 3D conservative field F = (yz, xz, xy), verify that the curl is zero everywhere. This is because F = grad(xyz).
  • Add a non-conservative part to the 3D field and observe that the curl becomes nonzero.

Quick Quiz

Coding Challenge

Divergence and Curl Calculator

Write a function called `divAndCurl` that takes x and y as inputs and computes the divergence and 2D curl of the vector field F(x,y) = (x^2*y, -x*y^2) at that point using central differences with h = 1e-5. Return a string `div,curl` with both values rounded to 4 decimal places.

Loading editor...

Real-World Usage

Vector fields and their divergence and curl model fundamental physical phenomena:

  • Fluid dynamics: The velocity field of a fluid is a vector field. Divergence measures compression or expansion. Curl measures vorticity (spinning). The Navier-Stokes equations govern how these evolve.
  • Electromagnetism: Electric and magnetic fields are vector fields. Maxwell equations relate their divergence and curl to charge density and current, fully describing all electromagnetic phenomena.
  • Weather modeling: Wind velocity is a vector field over the surface of the Earth. Meteorologists use divergence to find convergence zones (where storms form) and curl to identify cyclones.
  • Computer graphics: Flow fields guide particle systems for smoke, fire, and water simulations. Curl noise generates realistic turbulent patterns.
  • Aerodynamics: The circulation (integral of velocity around a closed curve, related to curl) determines the lift on an airfoil via the Kutta-Joukowski theorem.

Connections