Lesson 15 of 18
Divergence
Divergence of a 2D Vector Field
A vector field assigns a vector to every point in the plane.
The divergence measures how much the field "spreads out" at a point:
Interpretation
- : the field is a source — fluid flows outward
- : the field is a sink — fluid flows inward
- : incompressible flow — no net gain or loss
The Divergence Theorem
In 2D, the divergence theorem relates the integral of divergence over a region to flow across the boundary:
This is the 2D version of Gauss's law.
Examples
(radially outward):
- ,
- (constant — uniform spreading)
(rotation):
- ,
- (incompressible rotation — no sources or sinks)
:
- ,
Your Task
Implement double divergence_2d(double (*Fx)(double, double), double (*Fy)(double, double), double x, double y, double h) that computes the divergence using central differences.
TCC compiler loading...
Loading...
Click "Run" to execute your code.