0
$\begingroup$

Where can one find the source code of the Mathematica function Curl? Alternatively, how can one define a function the argument of which is restricted to be a 3D vector function of three variables named x, y, z?

$\endgroup$
2

1 Answer 1

2
$\begingroup$

I would define

curl[u_?(VectorQ[#] && Length[#] == 3 &)] := {D[u[[3]], y] - 
   D[u[[2]], z], D[u[[1]], z] - D[u[[3]], x], 
  D[u[[2]], x] - D[u[[1]], y]}

EDIT

This function is intended to deal specifically with lists of length 3. It can handle symbolic inputs, but these must be explicitly defined as having 3 components.

curl[{fx[x, y, z], fy[x, y, z], fz[x, y, z]}]
{-Derivative[0, 0, 1][fy][x, y, z] + Derivative[0, 1, 0][fz][x, y, z], 
 Derivative[0, 0, 1][fx][x, y, z] - Derivative[1, 0, 0][fz][x, y, z], 
 -Derivative[0, 1, 0][fx][x, y, z] + Derivative[1, 0, 0][fy][x, y, z]}

This is certainly not the only way (and may not be the best way) of defining curl, but matched the OP's request for an implementation that applied to 3-vectors. (I assumed that the originator was aware of the built-in Curl and wanted something different).

$\endgroup$
3
  • $\begingroup$ Thank you, I see now how to specify u, thanks to the use of #. $\endgroup$ Commented Aug 26, 2016 at 21:15
  • $\begingroup$ Is it possible to modify this definition in order curl works like D ? I mean: With D, you may do some formal calculus. Try D[f[x], x] or D[f[x, y, z], {{x, y, z}, 1}] or D[2 f[x], x] - 2 D[f[x], x]. But if you enter curl[2 f[x]] - 2 curl[f(x]], you don't get 0. Even if you use Expand, Simplify, etc. you are stuck with your input. $\endgroup$ Commented Aug 26, 2016 at 22:47
  • $\begingroup$ @AndréBellaïche you would have to start expanding the program by adding definitions for curl. $\endgroup$
    – QuantumDot
    Commented Aug 27, 2016 at 18:31

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.