I have this problem:

I define the gradient operator as:

gradiente = {D[#, x] &, D[#, y] &, D[#, z] &}

Now, if I want to apply the operator on a function i put:

Through[gradiente[x^2 + y^2 + z^2]]

Out: {2 x, 2 y, 2 z}

How to define the laplcian?? I tried this but it doesn't work when I put it on a function:

laplaciano =Dot[gradiente, gradiente]
  • $\begingroup$ I found a solution: laplaciano = Tr[Through[gradiente[gradiente]]] but I think it doesn't work for polar coordinates... $\endgroup$
    – ame_math
    Feb 20, 2015 at 11:43
  • 2
    $\begingroup$ Why do not you use built-in functions, or, otherwise, laplasiano=D[#, {x,2}]+D[#, {y,2}]+D[#, {z,2}] & ? $\endgroup$ Feb 20, 2015 at 12:26

1 Answer 1


I would do this using some of the ideas from an earlier answer, as follows (I'm reproducing some definitions from the link here, to be self-contained):

dx = Function[{f}, D[f, x]];
dy = Function[{f}, D[f, y]];
dz = Function[{f}, D[f, z]];

gradient = Function[ψ, Through[{dx, dy, dz}[ψ]]];

CenterDot[op1_List, op2_List] := Block[
  {ψ, x, y, z, functionBody},
  functionBody = Inner[Composition, op1, op2];
  (Function[ψ, Through[#1[ψ]]] &)[functionBody]


laplacian = {dx, dy, dz}·{dx, dy, dz};

laplacian[f[x, y, z]]

$f^{(0,0,2)}[x,y,z]+f^{(0,2,0)}[x,y,z]+f^{(2,0,0)}[x,y,z] $

The first lines define the first derivatives with respect to the Cartesian variables, and then use those to construct the gradient. The CenterDot function is the new ingredient. It does the composition of gradients component-wise. I wrote it so that it can also be used to compose other vector operators. Since all my operators are Function objects, CenterDot also has to return such an object. But this has to be assembled from the operators given as arguments, which is done inside Block. The body of the resulting function is inserted into the Function only after the inner product of the two vector operators has been formed. This requires two steps because Function has HoldAll attribute so that the Inner wouldn't be evaluated at the proper time if I did it inside the Function.

Finally, I use that "operator operation" to construct the Laplacian.

The point of this is that you can now construct other scalar operators in the same way I did it for laplacian, by combining vector operators with a simple $\cdot$. This centered dot has the keyboard shortcut Esc-.-Esc


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.