divergence {calculus}  R Documentation 
Computes the numerical divergence of functions
or the symbolic divergence of characters
in arbitrary orthogonal coordinate systems.
divergence(
f,
var,
params = list(),
coordinates = "cartesian",
accuracy = 4,
stepsize = NULL,
drop = TRUE
)
f %divergence% var
f 
array of 
var 
vector giving the variable names with respect to which the derivatives are to be computed and/or the point where the derivatives are to be evaluated. See 
params 

coordinates 
coordinate system to use. One of: 
accuracy 
degree of accuracy for numerical derivatives. 
stepsize 
finite differences stepsize for numerical derivatives. It is based on the precision of the machine by default. 
drop 
if 
The divergence of a vectorvalued function F_i
produces a scalar value
\nabla \cdot F
representing the volume density of the outward flux of the
vector field from an infinitesimal volume around a given point.
The divergence
is computed in arbitrary orthogonal coordinate systems using the
scale factors h_i
:
\nabla \cdot F = \frac{1}{J}\sum_i\partial_i\Biggl(\frac{J}{h_i}F_i\Biggl)
where J=\prod_ih_i
. When F
is an array
of vectorvalued functions
F_{d_1\dots d_n,i}
, the divergence
is computed for each vector:
(\nabla \cdot F)_{d_1\dots d_n} = \frac{1}{J}\sum_i\partial_i\Biggl(\frac{J}{h_i}F_{d_1\dots d_n,i}\Biggl)
Scalar for vectorvalued functions when drop=TRUE
, array
otherwise.
f %divergence% var
: binary operator with default parameters.
Guidotti E (2022). "calculus: HighDimensional Numerical and Symbolic Calculus in R." Journal of Statistical Software, 104(5), 137. doi:10.18637/jss.v104.i05
Other differential operators:
curl()
,
derivative()
,
gradient()
,
hessian()
,
jacobian()
,
laplacian()
### symbolic divergence of a vector field
f < c("x^2","y^3","z^4")
divergence(f, var = c("x","y","z"))
### numerical divergence of a vector field in (x=1, y=1, z=1)
f < function(x,y,z) c(x^2, y^3, z^4)
divergence(f, var = c(x=1, y=1, z=1))
### vectorized interface
f < function(x) c(x[1]^2, x[2]^3, x[3]^4)
divergence(f, var = c(1,1,1))
### symbolic array of vectorvalued 3d functions
f < array(c("x^2","x","y^2","y","z^2","z"), dim = c(2,3))
divergence(f, var = c("x","y","z"))
### numeric array of vectorvalued 3d functions in (x=0, y=0, z=0)
f < function(x,y,z) array(c(x^2,x,y^2,y,z^2,z), dim = c(2,3))
divergence(f, var = c(x=0, y=0, z=0))
### binary operator
c("x^2","y^3","z^4") %divergence% c("x","y","z")