Vector calculus example with cartesian coordinates in two dimensions

To set up the environement to use Cartesian coordinates in two dimensions, we use the following commands:

[> with( VectorCalculus ):
[> SetCoordinates( cartesian[x, y] ):

You may specify the symbols that will represent the first and second coordinates, but in general, x and y do quite well.

Defining a vector field

[> F1 := VectorField( <-sin(y), cos(x)> );

$F1 := (-\sin(y))\textbf{e}_x + (\cos(x))\textbf{e}_y$

You will note that the vector field is written as a sum of algebraic expressions multiplied by the corresponding unit vectors. We can plot this vector field:

[> PlotVector( F1, x = -Pi..Pi, y = -Pi..Pi );

We can also calculate the divergence and the flux across the surface of a circle that is centered at the origin with a radius of $1$:

[> Divergence( F1 );

$0$

[> Flux( F1, Circle( <0, 0>, 1 ) );

$0$

There are many curves across which you can calculate the flux, including arcs, circles, ellipses, lines, piecewise lines, and paths. We will give an example of a path:

[> SpaceCurve( , t = 0..1, scaling = constrained );

The flux across this path is:

[> Flux( F1, Path( , t = 0..1 ) );

$-1 + \cos(1) - \sin(1)$

We can also calculate the radius of curvature of this path:

[> RadiusOfCurvature(  );

$\frac{(9t^2 + 4)\sqrt{t^2(9t^2 + 4)}}{6 \textrm{csgn}\left( \frac{1}{9t^2 + 4} \right)}$

Now, the csgn(...) function is usually associated with complex numbers, hence the leading c, so we can ask Maple to simplify this, but we'll assume that $t$ is real:

[> simplify( %, 'size' ) assuming t::real;

$\frac{(9t^2 + 4)^{\frac{3}{2}}|t|}{6}$

We can also calculate line integrals along various curves, so we can integrate around the circle:

[> LineInt( F1, Circle( <0, 0>, 1 ) );

$0$

or we can integrate along our path:

[> LineInt( F1, Path( , t = 0..1 ) );

$-1/3\,\sqrt {\pi}{2}^{2/3} \left( 3/5\,{\frac {\sqrt [3]{2}\sin \left( 1 \right) }{\sqrt {\pi}}}-3/5\,{\frac {\sqrt [3]{2}\sin \left( 1 \right) {\it LommelS1} \left( 7/6,3/2,1 \right) }{\sqrt {\pi }}}-{\frac {\sqrt [3]{2} \left( \cos \left( 1 \right) -\sin \left( 1 \right) \right) {\it LommelS1} \left( 1/6,1/2,1 \right) }{\sqrt {\pi }}} \right)$ $+ 3/2\,\sqrt {2}\sqrt {\pi} \left( 1/2\,{\frac {\sqrt {2} \sin \left( 1 \right) }{\sqrt {\pi}}}-1/2\,{\it FresnelS} \left( { \frac {\sqrt {2}}{\sqrt {\pi}}} \right) \right)$

Fortunately, we can evaluate this to a floating-point number:

[> evalf( % );

$0.4261437275$

Starting with a scalar field

We can also start with a scalar field:

[> f := (x, y) -> -1/sqrt( x^2 + y^2 );

$f := (x, y) \mapsto -\frac{1}{\sqrt{x^2 + y^2}}$

[> F2 := Gradient( f( x, y ) );

$F1 := \left( \frac{x}{(x^2 + y^2)^\frac{3}{2}} \right)\textbf{e}_x + \left( \frac{y}{(x^2 + y^2)^\frac{3}{2}} \right)\textbf{e}_y$

We can plot this gradient:

[> PlotVector( F2, x = -3..3, y = -3..3 );

In addition to everything we have previously done, we can also calculate the Laplacian and the Hessian of this scalar field; however, we will immediately simplify the results:

[> simplify( Laplacian( f( x, y ) ), 'size' );

$-\frac{1}{(x^2 + y^2)^\frac{3}{2}}$

[> simplify( Hessian( f( x, y ) ), 'size' );

$\begin{pmatrix} \frac{-6x^2 + 2y^2}{(x^2 + y^2)^3} & -\frac{8xy}{(x^2 + y^2)^3} \\ -\frac{8xy}{(x^2 + y^2)^3} & \frac{2x^2 - 6y^2}{(x^2 + y^2)^3} \end{pmatrix}$

We can continue to, for example, calculate the flux through the unit circle:

[> Flux( F2, Circle( <0, 0>, 1 ) );

$2 \pi$

We can even calculate the flux across an infinite line:

[> Flux( F2 , Path( <1, t>, t = -infinity..infinity ) );

$2$

The line integral along these paths, however, are both zero (which we should expect from symmetry):

[> LineInt( F2, Circle( <0, 0>, 1 ) );

$2 \pi$

[> LineInt( F2 , Path( <1, t>, t = -infinity..infinity ) );

$0$

You are welcome to investigate the other topics in the vector calculus package by visiting the web page.