Calculus, Linear Algebra & Discrete Math Multivariable & Vector Calculus Vector calculus: ∇·F in orthogonal curvilinear coordinates

Divergence of a Vector Field Calculator

Enter the three components of a vector field and a point, choose Cartesian, cylindrical or spherical coordinates, and this calculator evaluates div F = ∇·F there. Each of the three terms is reported separately, including the metric factors that curvilinear coordinates introduce — the 1/r and 1/(r sin θ) that make the cylindrical and spherical formulas look nothing like the Cartesian one. It also classifies the point as a source, a sink or divergence-free.

Calculator

This calculator runs in your browser. Enable JavaScript for live results — the inputs, formula and worked example below remain fully readable without it.

Inputs this calculator takes, with typical values
InputWhat to enterExample
Coordinate systemThe variable names and the metric factors both change with the system you pick.Cartesian — variables x, y, z
First component (Fₓ, F_r)In curvilinear systems this is the radial component. Available: + - * / ^, sin, cos, exp, ln, sqrt, abs, pi, e.x
Second component (F_y, F_θ)The angular component in cylindrical and spherical coordinates.y
Third component (F_z, F_φ)The axial component in cylindrical coordinates, the azimuthal one in spherical.z
First coordinate (x or r)Radial coordinates must be positive in cylindrical and spherical systems.1
Second coordinate (y or θ)Angles are in radians; the polar angle θ runs from 0 to π.1
Third coordinate (z or φ)The axial height in cylindrical coordinates, the azimuth in radians in spherical.1

It returns

  • div F at the point — Net outflow per unit volume. Positive is a source, negative a sink, zero is solenoidal.
  • Radial (or x) term
  • Angular (or y) term
  • Axial (or z / azimuthal) term
  • |F| at the point

The formula

F=F1x+F2y+F3z
F=1r(rFr)r+1rFθθ+Fzz
F=1r2(r2Fr)r+1rsinθ(Fθsinθ)θ+1rsinθFφφ

In plain text: div F = ∇·F = ∂F₁/∂x + ∂F₂/∂y + ∂F₃/∂z

  • FThe vector field whose components you enter
  • div FA scalar: net outward flux per unit volume at the point
  • rRadial coordinate — distance from the axis in cylindrical, from the origin in spherical
  • θThe angular coordinate; the polar angle from the +z axis in spherical
  • φThe azimuthal angle in spherical coordinates

The divergence is defined without reference to coordinates as the limit of flux per unit volume, so all three formulas below describe the same quantity.

Updated Category Multivariable & Vector Calculus Verified against published test cases Reading time 11 min

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 , 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.

  1. Cartesian. ∂x/∂x = 1, ∂y/∂y = 1, ∂z/∂z = 1. So div F = 3, at every point.
  2. 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.
  3. 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.
  4. 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.
  5. 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

Each entry is derived from the definition; all are reproducible above.
FieldSystemdiv FInterpretation
(c₁, c₂, c₃) constantCartesian0Uniform flow, no sources
(x, y, z)Cartesian3Uniform expansion in three dimensions
(x, y, 0)Cartesian2Uniform expansion in the plane
(x², y², z²)Cartesian2x + 2y + 2zSource strength grows with position
(−y, x, 0)Cartesian0Pure rotation, incompressible
F_r = rCylindrical2Same field as (x, y, 0)
F_r = 1/rCylindrical0 for r > 0Line source: all the divergence is on the axis
F_r = rSpherical3Same field as (x, y, z)
F_r = 1/r²Spherical0 for r > 0Point 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.

Frequently asked questions

What does divergence physically mean?

It is the net outward flux per unit volume from an infinitesimal region. For a fluid velocity field, positive divergence means the fluid is expanding at that point and negative means it is being compressed. For an electric field, the divergence is proportional to the charge density there. Zero divergence means whatever enters a small region also leaves it.

Why does the cylindrical formula have an r inside the derivative?

Because the area of the cylindrical shell that the radial flux crosses grows with r. The flux out through the outer face is F_r times an area proportional to r, so the quantity whose change matters is rF_r, not F_r alone. Dividing by the volume element supplies the 1/r in front. The two are not interchangeable: they differ by F_r/r.

How can a field that points outward everywhere have zero divergence?

If its magnitude falls off at exactly the rate the geometry demands. In spherical coordinates F_r = 1/r² gives r²F_r = 1, a constant, so the radial term vanishes and div F = 0 for every r > 0. The field spreads over a surface growing as while weakening as 1/r², so the total flux through every sphere is the same. That is the inverse-square law seen from the differential side.

What is the difference between divergence and curl?

Divergence is a scalar measuring outflow; curl is a vector measuring rotation. The radial field (x, y, z) has divergence 3 and zero curl; the rotational field (−y, x, 0) has zero divergence and curl (0, 0, 2). They are independent measurements, and the Helmholtz decomposition says that together they essentially determine a well-behaved field.

Why can't I evaluate at r = 0?

Because the coordinate system itself is singular there — every direction is the same point, and the formula divides by r. The field may be perfectly well behaved at the origin; it is the coordinates that fail. Convert the components to Cartesian form and evaluate there, where no metric factor appears.

Which angle is θ in the spherical formula?

The polar angle, measured from the positive z-axis and running from 0 to π, with φ the azimuth around that axis. This is the physics convention, and it is the one used by the formula quoted here. Many mathematics texts swap the letters, so check which convention a source is using before copying a formula from it.

Does zero divergence mean the field is a curl?

On a suitably simple region, yes: a divergence-free field can be written as F = ∇ × A for some vector potential A. That is the reason the magnetic field, which satisfies ∇·B = 0 everywhere, always has a vector potential. As with the conservative-field criterion, the topology of the region matters, and the statement can fail on a domain with the wrong kind of hole.

What units does divergence have?

The units of the field divided by length. A velocity field in metres per second has a divergence in reciprocal seconds, which is a fractional rate of volume expansion. An electric field in volts per metre has a divergence in volts per square metre, which Gauss's law equates to charge density over permittivity.

Why is my divergence 1e-11 instead of 0?

Because the derivatives are finite differences rather than symbolic ones. Subtracting two nearly equal values and dividing by a small step leaves a residue at the level of machine precision divided by the step. Against terms of order 1, anything below about 10⁻⁹ is numerically zero, and the solenoidal test on this page uses a tolerance scaled to the size of the largest term for that reason.

References