What the divergence measures
The divergence of a vector field at a point is the net outward flux per unit volume from an infinitesimally small region around it. Positive divergence marks a source — more field lines leave the region than enter it. Negative divergence marks a sink. Zero divergence means everything that flows in flows out again, which is what "incompressible" means for a fluid velocity field and what "solenoidal" means in electromagnetism.
That definition is coordinate-free, which is why the same quantity has three different-looking formulas. In Cartesian coordinates the three terms are plain partial derivatives and simply add. In cylindrical and spherical coordinates extra factors of r and sin θ appear, and they are not decoration: they are the areas of the coordinate surfaces the flux crosses. A shell at radius r in cylindrical coordinates has circumference proportional to r, so a radial flow of constant speed carries more material outward across a distant shell than a near one, and the field has divergence even though its magnitude never changes.
The physical importance of divergence rests on one theorem. The divergence theorem states that the total flux of F out through a closed surface equals the integral of div F over the volume inside. That converts a statement about a boundary into a statement about the interior, which is how the integral form of Gauss's law becomes the differential form ∇·E = ρ/ε₀, and how conservation of mass in a fluid becomes the continuity equation.
Reading each formula, and where the metric factors come from
In Cartesian coordinates the derivation is a box argument. Take a rectangular box with sides Δx, Δy, Δz. The flux out through the two faces perpendicular to x is [F₁(x + Δx) − F₁(x)]ΔyΔz, which divided by the volume ΔxΔyΔz tends to ∂F₁/∂x. Repeat for the other two pairs of faces and add. The three axes contribute independently because the face areas do not depend on position.
In cylindrical coordinates they do. The face at radius r + Δr has area (r + Δr)ΔθΔz while the one at r has area rΔθΔz, so the radial flux difference is Δ(rF_r)ΔθΔz and the volume is rΔrΔθΔz. Dividing gives (1/r)∂(rF_r)/∂r — the r inside the derivative is the growing shell area, and the 1/r outside is the volume element. The angular term picks up its own 1/r because arc length is rΔθ rather than Δθ, while the axial term is unchanged because the z-faces have the same area at every z.
Spherical coordinates repeat the pattern with an extra factor. The shell area now grows like r², giving (1/r²)∂(r²F_r)/∂r, and the polar-angle faces have area proportional to sin θ, which is why sin θ appears inside the second derivative and 1/(r sin θ) in front of both angular terms.
This calculator computes each derivative numerically, including the composite quantities rF_r, r²F_r and F_θ sin θ, so the metric factors are applied exactly as written and you can read each term's contribution separately. The differencing is a central difference at a step of 10⁻⁴ scaled to the coordinate, then Richardson-extrapolated to fourth order — about twelve significant figures on a smooth field.
Worked example: the same field in three coordinate systems
Take the radial field that points outward with magnitude equal to distance from the origin. Its Cartesian components are F = (x, y, z), and in spherical coordinates it is simply F_r = r with both angular components zero.
- Cartesian. ∂x/∂x = 1, ∂y/∂y = 1, ∂z/∂z = 1. So div F = 3, at every point.
- Spherical, the wrong way. A naive ∂F_r/∂r = ∂r/∂r = 1 gives 1, not 3. That is the classic error: dropping the metric factors.
- Spherical, correctly. (1/r²)∂(r²·r)/∂r = (1/r²)∂(r³)/∂r = (1/r²)(3r²) = 3. The two angular terms are zero because F_θ = F_φ = 0. Total: 3, agreeing with the Cartesian answer as it must.
- Now the cylindrical field F_r = r — a different field, radial from the z-axis rather than from the origin. (1/r)∂(r·r)/∂r = (1/r)(2r) = 2. In Cartesian components that field is (x, y, 0), whose divergence is 1 + 1 + 0 = 2. Agreement again.
- Check the divergence theorem on the first field. Over a ball of radius a, the volume integral of div F = 3 is 3 × (4/3)πa³ = 4πa³. The surface flux is |F| = a times the sphere's area 4πa², which is 4πa³. Identical.
Now the field that is genuinely divergence-free despite pointing outward everywhere: the inverse-square field F_r = 1/r² in spherical coordinates. Then r²F_r = 1, a constant, so its derivative vanishes and div F = 0 at every point except the origin, where the field is undefined. That single calculation is why the electrostatic field of a point charge satisfies ∇·E = 0 away from the charge, and why all the charge in Gauss's law sits at the singular point the formula cannot reach.
Reading the result
The sign is the headline. Positive divergence means a source, negative means a sink, and near-zero against terms of order one means the field is solenoidal at that point. Because the terms are computed by finite differences, a genuinely zero divergence appears as a residue near 10⁻¹¹, so the verdict uses a tolerance scaled to the size of the largest term rather than testing against exact zero.
The units matter and are easy to forget. Divergence is a flux per unit volume, so it carries the units of the field divided by length: a velocity field in metres per second has divergence in reciprocal seconds. That is why the continuity equation reads ∂ρ/∂t + ∇·(ρv) = 0 — both terms are a density per unit time.
Read the individual terms when the total surprises you. In curvilinear coordinates it is common for one term to be large and another to cancel most of it; the inverse-square field is the extreme case, where ∂F_r/∂r = −2/r³ is large and negative while the metric factor supplies exactly the compensation that makes the total zero. Seeing that cancellation in the table is the fastest way to understand why the naive formula fails.
Finally, remember what divergence does not tell you. A field can have zero divergence and enormous rotation, as (−y, x, 0) does. The complementary measurement is the curl, and the Helmholtz decomposition theorem says that a sufficiently well-behaved field is determined, up to a harmonic remainder, by its divergence and its curl together. One number is half the story.
Reference: divergence of standard fields
| Field | System | div F | Interpretation |
|---|---|---|---|
| (c₁, c₂, c₃) constant | Cartesian | 0 | Uniform flow, no sources |
| (x, y, z) | Cartesian | 3 | Uniform expansion in three dimensions |
| (x, y, 0) | Cartesian | 2 | Uniform expansion in the plane |
| (x², y², z²) | Cartesian | 2x + 2y + 2z | Source strength grows with position |
| (−y, x, 0) | Cartesian | 0 | Pure rotation, incompressible |
| F_r = r | Cylindrical | 2 | Same field as (x, y, 0) |
| F_r = 1/r | Cylindrical | 0 for r > 0 | Line source: all the divergence is on the axis |
| F_r = r | Spherical | 3 | Same field as (x, y, z) |
| F_r = 1/r² | Spherical | 0 for r > 0 | Point source: inverse-square law, Gauss's law |
The two zero rows are the important ones. Both fields point outward everywhere and both have zero divergence away from the origin, because the metric factor exactly cancels the fall-off — 1/r in the plane and 1/r² in space. That is the geometric content of the inverse-square law.
Mistakes and assumptions
- Using the Cartesian formula in curvilinear coordinates. ∂F_r/∂r + ∂F_θ/∂θ + ∂F_z/∂z is not the divergence of anything. The metric factors are compulsory.
- Putting the r outside the derivative. It is (1/r)∂(rF_r)/∂r, not (1/r)∂F_r/∂r. The two differ by F_r/r, which is exactly what makes the inverse-square field divergence-free.
- Evaluating on the axis or at the origin. Both cylindrical and spherical coordinates are singular where r = 0, and spherical coordinates are singular on the whole polar axis where sin θ = 0. Convert to Cartesian components there.
- Confusing the polar and azimuthal angles. This page follows the physics convention: θ is measured from the positive z-axis and runs from 0 to π, while φ is the azimuth. Many mathematics texts swap the two names.
- Working in degrees. Every angle here is in radians. A full turn is 2π ≈ 6.283185.
- Expecting an exact zero. Finite differences leave a residue. Compare the divergence with the size of the individual terms, not with zero.
- Reading divergence as a measure of magnitude. A large field can have zero divergence and a small one can have large divergence; what matters is how the field changes across the point, not how big it is.
The divergence theorem in one line
∬F·n dS = ∭(∇·F) dV: the flux out of a closed surface equals the integral of the divergence over the volume it encloses. This is the three-dimensional relative of the fundamental theorem of calculus, and it is why the differential and integral forms of Gauss's law are equivalent. The volume integral on the right is evaluated by exactly the quadrature machinery used in the volume of revolution calculator when the geometry has an axis of symmetry.
Divergence among the vector operators
Divergence, gradient and curl are the three first-order differential operators of vector calculus, and they compose in exactly two non-trivial ways. The divergence of a curl is always zero, and the curl of a gradient is always zero — both follow from the symmetry of mixed partial derivatives, and both are worth using as checks on any field you construct. The divergence of a gradient is the Laplacian, ∇²φ, which governs steady heat conduction, electrostatic potential and every other equilibrium problem.
In fluid mechanics, ∇·v = 0 is the incompressibility condition, and it is a constraint rather than an equation of motion: it is what forces the pressure field to adjust instantaneously throughout an incompressible flow. In electromagnetism, two of Maxwell's four equations are divergence equations, ∇·E = ρ/ε₀ and ∇·B = 0, and the second is the statement that magnetic monopoles have never been observed.
Numerically, every partial derivative here is computed the way the numerical derivative calculator describes, one coordinate at a time. The composite derivatives — of rF_r and of F_θ sin θ — are differenced as single functions rather than expanded by the product rule, which keeps the metric factors exact and avoids an extra source of error.
One caution about interpretation: divergence is a local quantity, and "the field has a source at the origin" is often a statement about a singularity the formula cannot evaluate. The inverse-square field has zero divergence everywhere it is defined, and all of its source strength is concentrated at a point where it is not. Handling that properly requires the divergence theorem on a surface surrounding the singularity, or the language of distributions.
