# Vector calculus with SageMath¶

This worksheet illustrates the operators regarding scalar and vector fields on pseudo-Riemannian manifolds introduced in Trac ticket #24622.

Since SageMath 8.3, it is rather obsolete regarding calculus in Euclidean spaces. See these vector calculus examples instead.

In :
version()

Out:
'SageMath version 8.2.beta4, Release Date: 2018-01-27'
In :
%display latex

In :
from sage.manifolds.operators import *   # to get the operators grad, div, curl, etc.


### The Euclidean space as a 3-dimensional Riemannian manifold¶

In :
M = Manifold(3, 'M', structure='Riemannian', start_index=1)
X.<x,y,z> = M.chart()

In :
g = M.metric()
g[1,1], g[2,2], g[3,3] = 1, 1, 1
g.display()

Out:

### Gradient of a scalar field¶

In :
F = M.scalar_field(function('f')(x,y,z), name='F')
F.display()

Out:
In :
grad(F).display()

Out:
In :
curl(grad(F)).display()

Out:
In :
norm(grad(F)).display()

Out:

### Laplacien of a scalar field¶

In :
laplacian(F).display()

Out:
In :
laplacian(F) == div(grad(F))

Out:

### Vector field¶

In :
v = M.vector_field(name='v')
v = function('v_x')(x,y,z)
v = function('v_y')(x,y,z)
v = function('v_z')(x,y,z)
v.display()

Out:

In order not to clutter the outputs, we omit the coordinate arguments in the display of chart functions:

In :
M.options.omit_function_arguments=True

In :
v.display()

Out:

Norm of a vector field:

In :
s = norm(v)
print(s)

Scalar field |v| on the 3-dimensional Riemannian manifold M

In :
s.display()

Out:

Scalar product of two vector fields:

In :
v.dot(grad(F)).display()

Out:

Cross product of two vector fields:

In :
v.cross(grad(F)).display()

Out:

Divergence :

In :
s = div(v)
s.display()

Out:

Curl:

In :
w = curl(v)
print(w)

Vector field curl(v) on the 3-dimensional Riemannian manifold M

In :
w.display()

Out:

To use the notation rot instead of curl, simply do

In :
rot = curl


An alternative is

In :
from sage.manifolds.operators import curl as rot


We have then

In :
rot(v).display()

Out:
In :
rot(v) == curl(v)

Out:

The divergence of a curl is always zero:

In :
div(curl(v)).display()

Out:

Laplacian of a vector field:

In :
laplacian(v).display()

Out:
In :
curl(curl(v)).display()

Out:
In :
grad(div(v)).display()

Out:

Check of a famous identity:

In :
curl(curl(v)) == grad(div(v)) - laplacian(v)

Out:

Two other identities regarding any scalar field F and any vector field v:

In :
div(F*v) == F*div(v) + v.dot(grad(F))

Out:
In :
curl(F*v) == grad(F).cross(v) + F*curl(v)

Out:

The left-hand side is

In :
curl(F*v).display()

Out:
In [ ]: