## Gradient of a Pure Function
cavallini@ogs.trieste.it The
gradient is an operator that associates a vector field to a scalar field. Both scalar and
vector fields may be naturally represented in
has a function to compute gradients,
but
operates on expressions like
This note presents and compares four ways to implement the gradient operator for pure functions. The author acknowledges helpful conversations with G. Seriani. Roman Maeder's
This implementation allows for any number of Cartesian independent variables, but it too operates on expressions and not on pure functions. One can overcome these limitations by defining the operator
We use the symbol ▽ ( \[ EmptyDownTriangle ] ) and not ∇ (), which is an prefix operator. The operator computes the gradient of a pure function of an arbitrary number of independent variables. For example, given the pure function
or the alternative forms
the gradient at the generic point is
and analogously for and .
The only limitation is that the functions to which is applied must be defined in terms of Cartesian coordinates. However, in dimension higher than three this is by far the most common situation and, in dimension two or three, similar routines may be written (using the appropriate mathematical formulae) to cope with the spherical, cylindrical, or any other coordinate system. The main problem with is that the derivatives are re-evaluated each time the gradient is applied. Hence, it is not efficient for repeated numerical computations. For pure functions, shorter and more efficient code is possible:
However, does not work with the alternative forms or . A third solution has the flexibility of and the efficiency of ;
the only penalty for the improvement is that we must use an extra argument (the number
For example:
One might argue that the preceding solutions constitute, in
some sense, a way of "cheating." Indeed, these algorithms temporarily create an
expression from a pure function, then perform the derivatives, and turn the result into a
function again, but do not handle the abstract differential operators as such. The real
problem is the lack of an "operator algebra" in
We introduce the notation
which applies a function of operators to the same argument.
We may define the -dimensional gradient as
For example, the two-dimensional gradient
applied to and evaluated at yields
and similarly for . With this formalism, any differential operator is easily constructed. The -dimensional divergence
gives, for example,
Here is the -dimensional Laplacian:
The operator is
applicable to functions defined in any of the three possible ways (as , , or Document converted by Mathematica of Wolfram Research |