
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
array of characters
or a function
returning a numeric
array.
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 derivative
.
list
of additional parameters passed to f
.
coordinate system to use. One of: cartesian
, polar
, spherical
, cylindrical
, parabolic
, parabolic-cylindrical
or a vector of scale factors for each varibale.
degree of accuracy for numerical derivatives.
finite differences stepsize for numerical derivatives. It is based on the precision of the machine by default.
if TRUE
, return the divergence as a scalar and not as an array
for vector-valued functions.
Scalar for vector-valued functions when drop=TRUE
, array
otherwise.
%divergence%
: binary operator with default parameters.
The divergence of a vector-valued function divergence
is computed in arbitrary orthogonal coordinate systems using the
scale factors
where array
of vector-valued functions
divergence
is computed for each vector:
Guidotti, E. (2020). "calculus: High dimensional numerical and symbolic calculus in R". https://arxiv.org/abs/2101.00086
Other differential operators:
curl()
,
derivative()
,
gradient()
,
hessian()
,
jacobian()
,
laplacian()
# NOT RUN {
### 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 vector-valued 3-d 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 vector-valued 3-d 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")
# }
Run the code above in your browser using DataLab