Vector Analysis

Vector analysis forms the basis of many physical and mathematical models. Mathematica can compute the basic operations of gradient, divergence, curl, and Laplacian in a variety of coordinate systems. Moreover, these operators are implemented in a quite general form, allowing them to be used in different dimensions and with higher-rank tensors.

Vector Analysis in Cartesian Coordinates

Vector Derivatives

The four basic vector derivatives are shown in the following table.

Grad[f,{x1,...,xn}]gradient of a scalar function
Div[{f1,...,fn},{x1,...,xn}]divergence of a vector-valued function
Curl[{f1,...,fn},{x1,...,xn}]curl of a vector-valued function
Laplacian[f,{x1,...,xn}]Laplacian of a scalar function

Classical vector derivative operators in Cartesian coordinates.

Although these operators are available in any dimension, they are most commonly encountered in three dimensions.

This gives the gradient in three dimensions.
In[1]:=
Click for copyable input
Out[1]=
Compute a three-dimensional divergence.
In[2]:=
Click for copyable input
Out[2]=
The curl in three dimensions returns a vector.
In[3]:=
Click for copyable input
Out[3]=
This gives the Laplacian in three-dimensional space.
In[4]:=
Click for copyable input
Out[4]=

The following examples explore these operators in dimensions other than three.

This gives a two-dimensional gradient.
In[5]:=
Click for copyable input
Out[5]=
The divergence of a vector is a scalar in any dimension.
In[6]:=
Click for copyable input
Out[6]=
Compute a five-dimensional Laplacian.
In[7]:=
Click for copyable input
Out[7]=
The curl is not restricted to three dimensions. This gives a two-dimensional curl, which is a scalar.
In[8]:=
Click for copyable input
Out[8]=
More generally, the curl of a vector in dimension is a completely antisymmetric tensor of rank .
In[9]:=
Click for copyable input
Out[9]=
In[10]:=
Click for copyable input
Out[10]=

The meaning of the curl in dimensions other than three is discussed more fully in the next subsection.

Generalization to Higher-Rank Tensors

All four operators introduced in the previous subsection are general operators that can take vectors and higher-rank tensors as input. For Curl in dimension , the input can be a scalar, vector, or tensor of rank up to . For the other functions, the allowed rank of input tensors is unlimited.

The gradient of a vector is a rank-2 tensor. Each additional gradient raises the rank by one.
In[11]:=
Click for copyable input
Out[11]=
In[12]:=
Click for copyable input
Out[12]=
The divergence is a gradient followed by contraction of the last two slots. It therefore reduces the rank by 1.
In[13]:=
Click for copyable input
Out[13]=
In[14]:=
Click for copyable input
Out[14]=
It is possible to take the divergence in a slot other than the final one by using TensorContract.
In[15]:=
Click for copyable input
Out[15]=
The Laplacian preserves rank, so the Laplacian of a vector is another vector.
In[16]:=
Click for copyable input
Out[16]=
In dimension , the curl of tensor of rank is a tensor of rank .
In[17]:=
Click for copyable input
Out[17]=
In[18]:=
Click for copyable input
Out[18]=
In[19]:=
Click for copyable input
Out[19]=
The reason for this behavior is that the curl is the Hodge dual of the anti-symmetrized gradient. This explains the restriction on rank.
In[20]:=
Click for copyable input
Out[20]=
In[21]:=
Click for copyable input
Out[21]=
In[22]:=
Click for copyable input
Out[22]=

Vector Analysis in Non-Cartesian Coordinates

Known Coordinate Charts

Mathematica contains information about a large number of coordinate charts. The function CoordinateChartData provides a mechanism for retrieving this information.

CoordinateChartData[{"coordsys",n}]standard name for -dimensional Euclidean chart
CoordinateChartData[{All,n}]available coordinate charts in -dimensional Euclidean space
CoordinateChartData[{All,All,n}]available coordinate charts in -dimensional space
CoordinateChartData[chart,"prop"]property for the specified coordinate chart
CoordinateChartData[chart,"prop",pt]property for the specified coordinate chart at the point pt

Information about coordinate charts.

The following examples show how to look up available coordinate charts. In their most general form, coordinate chart specifications contain a coordinate system name, a metric, and a dimension. Note that many charts require parameters. These can be specified or left at the shown defaults.

This gives the Mathematica standard name for three-dimensional Cartesian coordinates.
In[23]:=
Click for copyable input
Out[23]=
Prolate spheroidal coordinates take a parameter, the half-focal length.
In[24]:=
Click for copyable input
Out[24]=
The parameters can be specified in the input.
In[25]:=
Click for copyable input
Out[25]=
When multiple parameters are specified, they should be enclosed in a list.
In[26]:=
Click for copyable input
Out[26]=
These are the available coordinate charts in two-dimensional Euclidean space.
In[27]:=
Click for copyable input
Out[27]=
The previous input is equivalent to the following, more explicit, input.
In[28]:=
Click for copyable input
Out[28]=
Replacing the metric with the symbol All includes non-Euclidean coordinate charts.
In[29]:=
Click for copyable input
Out[29]=

Although the coordinate chart standard names are quite long, it is typically possible to omit and the dimension when using Euclidean coordinate charts.

CoordinateChartData contains many properties regarding the different coordinate charts. The most fundamental is the metric, which ultimately determines all lengths and volumes in the coordinate chart. However, in the context of vector analysis in orthogonal coordinates, it is more common to consider the scale factors and volume factor.

This retrieves the metric for polar coordinates at the point .
In[30]:=
Click for copyable input
Out[30]=
For a diagonal metric, the scale factors are the square roots of the diagonal entries.
In[31]:=
Click for copyable input
Out[31]=
The volume factor is the square root of the determinant of the metric.
In[32]:=
Click for copyable input
Out[32]=
This gives the scale factors for elliptic coordinates along a curve . Notice that the default parameter has been used.
In[33]:=
Click for copyable input
In[34]:=
Click for copyable input
Out[34]=
The scale factors relate the coordinate velocity to the physical velocity.
In[35]:=
Click for copyable input
Out[35]=
The physical speed is then the norm of the velocity. This could also have been obtained directly from the metric and coordinate velocity.
In[36]:=
Click for copyable input
Out[36]=
In[37]:=
Click for copyable input
Out[37]=
This gives the volume factor in bipolar coordinates with the parameter set to 1. Notice that a double list is needed to ensure that 1 is treated as a parameter instead of a dimension.
In[38]:=
Click for copyable input
Out[38]=
For a diagonal metric, the volume factor is the product of the scale factors.
In[39]:=
Click for copyable input
Out[39]=
This gives the physical area of a coordinate annulus in bipolar coordinates.
In[40]:=
Click for copyable input
Out[40]=
All available properties can be discovered using the following syntax.
In[41]:=
Click for copyable input
Out[41]=

Vector Derivatives in Non-Cartesian Coordinates

The four vector derivative operators work in any coordinate chart. It is only necessary to specify the chart in the third argument of the function.

Grad[f,{x1,...,xn},chart]gradient in the specified coordinate chart
Div[{f1,...,fn},{x1,...,xn},chart]divergence in the specified coordinate chart
Curl[{f1,...,fn},{x1,...,xn},chart]curl in the specified coordinate chart
Laplacian[f,{x1,...,xn},chart]Laplacian in the specified coordinate chart

Vector analysis operators in non-Cartesian coordinates.

Arrays are treated in these commands as components in the orthonormal basis. This applies to both input and output. As a result, the physical dot product can be computed using Dot.

In an orthogonal coordinate system, the gradient of a scalar equals the partial derivatives divided by the scale factors.
In[42]:=
Click for copyable input
Out[42]=
In[43]:=
Click for copyable input
Out[43]=
The gradient of vectors and higher-rank tensors introduces connection terms to the result, meaning it is not simply the gradient of each component.
In[44]:=
Click for copyable input
Out[44]=
In[45]:=
Click for copyable input
Out[45]=
Since the divergence only applies to vectors and tensors, it always has connection terms. However, since arrays are treated as being in the orthonormal basis, the divergence is still a gradient followed by a contraction.
In[46]:=
Click for copyable input
Out[46]=
In[47]:=
Click for copyable input
Out[47]=
Because of the connection terms, the divergence of a rank-2 tensor is not simply the divergence of each row.
In[48]:=
Click for copyable input
Out[48]=
In[49]:=
Click for copyable input
Out[49]=
By definition, the Laplacian is the divergence of the gradient. As a result, the Laplacian has connection terms in non-Cartesian coordinates as well.
In[50]:=
Click for copyable input
Out[50]=
In[51]:=
Click for copyable input
Out[51]=
This means the vector Laplacian is not simply the Laplacian of each component.
In[52]:=
Click for copyable input
Out[52]=
In[53]:=
Click for copyable input
Out[53]=
When acting on vectors and higher-rank tensors, the curl also contains connection terms.
In[54]:=
Click for copyable input
Out[54]=
When acting on scalars, there are no connection terms, but the normalization from the scale factors does appear in the result.
In[55]:=
Click for copyable input
Out[55]=

Classical Definitions

As seen above, the gradient of a scalar in orthogonal coordinates involves the partial derivatives and the scale factors. There are similar definitions for the divergence of a vector, the Laplacian of a scalar, and the curl of a vector in terms of the scale factors and volume factor.

The gradient in an orthogonal chart is related to the gradient in Cartesian coordinates by the scale factors.
In[56]:=
Click for copyable input
Out[56]=
In[57]:=
Click for copyable input
Out[57]=
In[58]:=
Click for copyable input
Out[58]=
In an orthogonal coordinate system, the classical formula for the divergence of a vector relates it to the divergence in Cartesian coordinates using the scale factors and volume factor.
In[59]:=
Click for copyable input
Out[59]=
In[60]:=
Click for copyable input
Out[60]=
In[61]:=
Click for copyable input
Out[61]=
In[62]:=
Click for copyable input
Out[62]=
Combining the classical formula for divergence with the definition of the gradient of a scalar in an orthogonal system produces a classical formula for the Laplacian.
In[63]:=
Click for copyable input
Out[63]=
In[64]:=
Click for copyable input
Out[64]=
In[65]:=
Click for copyable input
Out[65]=
In[66]:=
Click for copyable input
Out[66]=
The following illustrates a similar formula for the three-dimensional curl of a vector. To generalize to dimension , replace the leading scales with the TensorProduct of copies of scales.
In[67]:=
Click for copyable input
Out[67]=
In[68]:=
Click for copyable input
Out[68]=
In[69]:=
Click for copyable input
Out[69]=
In[70]:=
Click for copyable input
Out[70]=
New to Mathematica? Find your learning path »
Have a question? Ask support »