\( \DeclareMathOperator{\abs}{abs} \newcommand{\ensuremath}[1]{\mbox{$#1$}} \)

The Curl

 1 Set-Up

Since we will be working with vectors, we will do our usual set-up routine.  This time we will
also include the @ helper from the section on the gradient:

(%i10) load("vect")$
mag(u):=sqrt(u.u)$
hat(u):=u/mag(u)$
infix("##")$
u ## v := express(u~v)$
prefix("@")$
@E := ev(express(E),diff)$
i:[1,0,0]$
j:[0,1,0]$
k:[0,0,1]$

 2 Intro to curl()

The "vect" library has a built-in curl() function that takes vector fields and applies the curl.
But just like the gradient, it returns a high-level symbolic object.  Let's start by defining a vector
field:

(%i11) F:[z^2,x^2,y^2];
\[\tag{F}[{{z}^{2}},{{x}^{2}},{{y}^{2}}]\]

Now we will attempt to take its curl:

(%i12) curl(F);
\[\tag{%o12} \operatorname{curl}\left( [{{z}^{2}},{{x}^{2}},{{y}^{2}}]\right) \]

Alright, so we've hit the same road-block that we did when working with grad().  Let's try to express the above:

(%i13) express(curl(F));
\[\tag{%o13} [\frac{d}{d y} {{y}^{2}}-\frac{d}{d z} {{x}^{2}},\frac{d}{d z} {{z}^{2}}-\frac{d}{d x} {{y}^{2}},\frac{d}{d x} {{x}^{2}}-\frac{d}{d y} {{z}^{2}}]\]

Yes!  That's the curl alright!  But it needs to be evaluated for the the derivatives.  Let's do that too:

(%i14) ev(express(curl(F)),diff);
\[\tag{%o14} [2 y,2 z,2 x]\]

Aha!  We got it!  But again, we don't want to keep typing ev(express(curl(F)),diff) every time we want a curl!
That would get really messy.  That's where our @ helper comes in!

(%i15) @curl(F);
\[\tag{%o15} [2 y,2 z,2 x]\]

So when we want our curl(F) we just prepend it with @ to do the heavy lifting under the hood!

 3 Examples

(%i16) kill(F);
\[\tag{%o16} \mathit{done}\]
(%i18) F(x,y,z):=[exp(x+y+z),cos(x*z),sin(z)];
@curl(F(x,y,z));
\[\tag{%o17} \operatorname{F}\left( x,y,z\right) :=[\operatorname{exp}\left( x+y+z\right) ,\cos{\left( x z\right) },\sin{(z)}]\] \[\tag{%o18} [x \sin{\left( x z\right) },{{\% e}^{z+y+x}},-z \sin{\left( x z\right) }-{{\% e}^{z+y+x}}]\]

Notice that since we defined F(x,y,z) to be a vector valued *function* we must write F(x,y,z) in curl()
to get the correct output.  Otherwise:

(%i19) @curl(F);
\[\mbox{curl used in space of wrong dimension}\mbox{\ensuremath{\neq}0: express1(expn=curl F)(vect.mac line 154)}\mbox{\ensuremath{\neq}1: \ensuremath\{\backslash\}\ensuremath{@}(e=curl F)(vect.mac line 44)}\mbox{ -- an error. To debug this try: debugmode(true);}\]
(%i20) kill(F);
\[\tag{%o20} \mathit{done}\]

Let's catch the curl as a new vector field:

(%i22) F:[exp(x+y+z),sqrt(x-z),log(x)];
define(curlF(x,y,z),@curl(F));
\[\tag{F}[{{\% e}^{z+y+x}},\sqrt{x-z},\log{(x)}]\] \[\tag{%o22} \operatorname{curlF}\left( x,y,z\right) :=[\frac{1}{2 \sqrt{x-z}},{{\% e}^{z+y+x}}-\frac{1}{x},\frac{1}{2 \sqrt{x-z}}-{{\% e}^{z+y+x}}]\]

Now we can work with curlF at our leisure.  For example:

(%i24) curlF(2,0,1);curlF(2*a,-3*a,a);
\[\tag{%o23} [\frac{1}{2},{{\% e}^{3}}-\frac{1}{2},\frac{1}{2}-{{\% e}^{3}}]\] \[\tag{%o24} [\frac{1}{2 \sqrt{a}},1-\frac{1}{2 a},\frac{1}{2 \sqrt{a}}-1]\]
(%i25) kill(F);
\[\tag{%o25} \mathit{done}\]

If we have defined i, j, and k (as we did in the set-up), then we can use them exactly as one would expect:

(%i28) @curl(exp(x+y+z)*i+y^3*j);
\[\tag{%o28} [0,{{\% e}^{z+y+x}},-{{\% e}^{z+y+x}}]\]

 4 2D curl()

What happens if our vector field is in R^2?  Let's see:

(%i26) @curl([3*y^2,2*x^2]);
\[\tag{%o26} 4 x-6 y\]

Hmmm... the result is a scalar.  Let's look more closely at that scalar:

(%i27) express(curl([F[1],F[2]]));
\[\tag{%o27} \frac{d}{d x} {F_2}-\frac{d}{d y} {F_1}\]

Aha!  Just as in the case of cross product of two 2-vectors, the curl is yielding the coefficient of the k component
of the vector.  To avoid this, we could either be careful to define 3D vectorfields with z-components 0 like so:

(%i29) @curl([3*y^2,2*x^2,0]);
\[\tag{%o29} [0,0,4 x-6 y]\]

Or we could use the i,j,k vectors that we defined in the set-up:

(%i30) @curl(3*y^2*i+2*x^2*j);
\[\tag{%o30} [0,0,4 x-6 y]\]

Or even still, we could simply throw the 2D curl onto the k vector:

(%i31) @curl([3*y^2,2*x^2])*k;
\[\tag{%o31} [0,0,4 x-6 y]\]

In any case, special care must be taken when curl-ing 2D vector fields.

(%i33) kill(F);
\[\tag{%o33} \mathit{done}\]

 5 Intro to div()

Just like grad() and curl(), div() must be expressed and evaluated.  So we will use @ to help with this.
Let's walk through the chain just to see what div() is doing:

(%i35) div([F[1],F[2],F[3]]);
express(%);
\[\tag{%o34} \operatorname{div}\left( [{F_1},{F_2},{F_3}]\right) \] \[\tag{%o35} \frac{d}{d z} {F_3}+\frac{d}{d y} {F_2}+\frac{d}{d x} {F_1}\]

So we see that div() returns a high-level symbolic object which we then express.  After expression
we must then evaluate the derivatives.  Again: @ to the rescue:

(%i37) @div([x^2,y^3,z^4]);
\[\tag{%o37} 4 {{z}^{3}}+3 {{y}^{2}}+2 x\]

Let's catch a divergence as a scalar function:

(%i41) F:[x^2,y^3,z^4];
define(f(x,y,z),@div(F));
\[\tag{F}[{{x}^{2}},{{y}^{3}},{{z}^{4}}]\] \[\tag{%o41} \operatorname{f}\left( x,y,z\right) :=4 {{z}^{3}}+3 {{y}^{2}}+2 x\]
(%i42) kill(f,F);
\[\tag{%o42} \mathit{done}\]
(%i47) F(x,y,z):=[cos(x),sin(x+y),tan(z)];
@div(F(x,y,z));
trigexpand(%);
\[\tag{%o45} \operatorname{F}\left( x,y,z\right) :=[\cos{(x)},\sin{\left( x+y\right) },\tan{(z)}]\] \[\tag{%o46} {{\sec{(z)}}^{2}}+\cos{\left( y+x\right) }-\sin{(x)}\] \[\tag{%o47} {{\sec{(z)}}^{2}}-\sin{(x)} \sin{(y)}+\cos{(x)} \cos{(y)}-\sin{(x)}\]

Let's see what div() does with 2D vector fields:

(%i48) @div([x^2,y^3]);
\[\mbox{part: invalid index of list or matrix.}\mbox{\ensuremath{\neq}0: express1(expn=div [x\textasciicircum2,y\textasciicircum3])(vect.mac line 132)}\mbox{\ensuremath{\neq}1: \ensuremath\{\backslash\}\ensuremath{@}(e=div [x\textasciicircum2,y\textasciicircum3])(vect.mac line 44)}\mbox{ -- an error. To debug this try: debugmode(true);}\]

Looks like div() simply isn't defined for 2D vector fields.  This makes some sense: think back to class,
when did we ever compute div() of a 2D vector field?

 6 Other Variables?

What happens if we attempt a curl() or a div() on a field with variables other than x,y, or z?

(%i51) @curl([s,t,u]);@div([s,t,u]);
\[\tag{%o50} [0,0,0]\] \[\tag{%o51} 0\]

As in the case of grad(), s,t, and u don't mean anything to curl() and div() and so they are treated as constants.
We can get around this by swapping in x,y,z and then swapping back out like so:

(%i71) F:[t^2,s^2,0];
subst([s=x,t=y],F)$
@curl(%)$
subst([x=s,y=t],%);
\[\tag{F}[{{t}^{2}},{{s}^{2}},0]\] \[\tag{%o71} [0,0,2 s-2 t]\]
(%i72) kill(F);
\[\tag{%o72} \mathit{done}\]
(%i87) F:[s^3,t^4,u^5];
subst([s=x,t=y,u=z],F)$
@div(%)$
subst([x=s,y=t,z=u],%)$
define(divF(s,t,u),%);
\[\tag{F}[{{s}^{3}},{{t}^{4}},{{u}^{5}}]\] \[\tag{%o87} \operatorname{divF}\left( s,t,u\right) :=5 {{u}^{4}}+4 {{t}^{3}}+3 {{s}^{2}}\]
Created with wxMaxima.