Vector fields

> restart; with(LinearAlgebra): with(VectorCalculus): with(plots):

Warning, the names &x, CrossProduct and DotProduct have been rebound

Warning, the assigned names <,> and <|> now have a global binding

Warning, these protected names have been redefined and unprotected: *, +, ., D, Vector, diff, int, limit, series

Warning, the name changecoords has been redefined

To use vector fields in Maple, we need to set the coordinate system.  For us this means we have to say whether we are using [x,y] or [x,y,z].  Once this is said, it remains in effect until changed.

> SetCoordinates( 'cartesian'[x,y] );

cartesian[x, y]

Now we define a vector field as a vector whose components depend on the variables.

> F:= VectorField( <x*y,-y^2*x> );

F := Vector[column]([[x*y], [-y^2*x]], [

> SetCoordinates( 'cartesian'[x,y,z] );

cartesian[x, y, z]

> gravity:= VectorField( -<x,y,z> / sqrt(x^2+y^2+z^2)^3 );

gravity := Vector[column]([[-x/(x^2+y^2+z^2)^(3/2)], [-y/(x^2+y^2+z^2)^(3/2)], [-z/(x^2+y^2+z^2)^(3/2)]], [

There are functions in plots for plotting vector fields.

> fieldplot( F, x=-1..1, y=-1..1, scaling=constrained );

[Plot]

> fieldplot( [y,-x], x=-2..2,y=-2..2 );

[Plot]

> fieldplot3d( gravity, x=-1..1, y=-1..1, z=-1..1, arrows=THICK,axes=boxed );

[Plot]

> fieldplot3d( [ y/z, -x/z, z/4], x=-1..1, y=-1..1, z=1..3, axes=normal) ;

[Plot]

Gradients and conservative fields

Maple makes it easy to check whether a field is conservative and find a potential function.  

> f:= ScalarPotential( gravity );

f := 1/(x^2+y^2+z^2)^(1/2)

Check:

> Gradient( f, [x,y,z] );

Vector[column]([[-x/(x^2+y^2+z^2)^(3/2)], [-y/(x^2+y^2+z^2)^(3/2)], [-z/(x^2+y^2+z^2)^(3/2)]], [

If the field does not have a potential, nothing is returned.

> F:= VectorField( <cos(x), x*y, 1> );

F := Vector[column]([[cos(x)], [x*y], [1]], [

> ScalarPotential( F );

Divergence and curl

Divergence and curl are straightforward to compute.  Tip: For a planar vector field, define it as a 3D field with a third component of zero.

> F:= VectorField( <x*y+x^2,-x*y^2,0> );

F := Vector[column]([[x*y+x^2], [-y^2*x], [0]], [

Divergence is easy.  We can even use the "del dot F" notation.

> divF:= Divergence( F );

divF := y+2*x-2*x*y

> Del . F;

y+2*x-2*x*y

Curl is more of the same.

> curlF:= Curl( F );

curlF := Vector[column]([[0], [0], [-y^2-x]], [

> Del &x F;

Vector[column]([[0], [0], [-y^2-x]], [

curlF := -y^2-x

> with(plots):

> p1:= fieldplot( [F[1],F[2]], x=-3..3,y=-3..3 ):

> pd:= contourplot( divF, x=-3..3,y=-3..3 ):

> pc:= contourplot( curlF[3], x=-3..3,y=-3..3 ):

> display( {p1,pd}, scaling=constrained );

[Plot]

> display( {p1,pc}, scaling=constrained );

[Plot]

>