laplacian( f, var, params = list(), coordinates ="cartesian", accuracy =4, stepsize =NULL, drop =TRUE)f %laplacian% var
Arguments
f: array of characters or a function returning a numeric array.
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 derivative.
params: list of additional parameters passed to f.
coordinates: coordinate system to use. One of: cartesian, polar, spherical, cylindrical, parabolic, parabolic-cylindrical or a vector of scale factors for each varibale.
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 TRUE, return the Laplacian as a scalar and not as an array for scalar-valued functions.
Returns
Scalar for scalar-valued functions when drop=TRUE, array otherwise.
Details
The Laplacian is a differential operator given by the divergence of the gradient of a scalar-valued function F, resulting in a scalar value giving the flux density of the gradient flow of a function. The laplacian is computed in arbitrary orthogonal coordinate systems using the scale factors hi:
∇2F=J1i∑∂i(hi2J∂iF)
where J=∏ihi. When the function F is a tensor-valued function Fd1…dn, the laplacian is computed for each scalar component:
(∇2F)d1…dn=J1i∑∂i(hi2J∂iFd1…dn)
Functions
f %laplacian% var: binary operator with default parameters.
Examples
### symbolic Laplacian laplacian("x^3+y^3+z^3", var = c("x","y","z"))### numerical Laplacian in (x=1, y=1, z=1)f <-function(x, y, z) x^3+y^3+z^3laplacian(f = f, var = c(x=1, y=1, z=1))### vectorized interfacef <-function(x) sum(x^3)laplacian(f = f, var = c(1,1,1))### symbolic vector-valued functionsf <- array(c("x^2","x*y","x*y","y^2"), dim = c(2,2))laplacian(f = f, var = c("x","y"))### numerical vector-valued functionsf <-function(x, y) array(c(x^2,x*y,x*y,y^2), dim = c(2,2))laplacian(f = f, var = c(x=0,y=0))### binary operator"x^3+y^3+z^3"%laplacian% c("x","y","z")
References
Guidotti E (2022). "calculus: High-Dimensional Numerical and Symbolic Calculus in R." Journal of Statistical Software, 104(5), 1-37. tools:::Rd_expr_doi("10.18637/jss.v104.i05")
See Also
Other differential operators: curl(), derivative(), divergence(), gradient(), hessian(), jacobian()