Navigation

In sympy.vector, every CoordSysCartesian instance is assigned basis
vectors corresponding to the \(X\), \(Y\) and
\(Z\) axes. These can be accessed using the properties
named i, j and k respectively. Hence, to define a vector
\(\mathbf{v}\) of the form
\(3\mathbf{\hat{i}} + 4\mathbf{\hat{j}} + 5\mathbf{\hat{k}}\) with
respect to a given frame \(\mathbf{R}\), you would do

Vector math and basic calculus operations with respect to vectors have
already been elaborated upon in the earlier section of this module’s
documentation.

On the other hand, base scalars (or coordinate variables) are implemented
in a special class called BaseScalar, and are assigned to every
coordinate system, one for each axis from \(X\), \(Y\) and
\(Z\). These coordinate variables are used to form the expressions of
vector or scalar fields in 3D space.
For a system R, the \(X\), \(Y\) and \(Z\)BaseScalars instances can be accessed using the R.x, R.y
and R.z expressions respectively.

Therefore, to generate the expression for the aforementioned electric
potential field \(2{x}^{2}y\), you would have to do

It is to be noted that BaseScalar instances can be used just
like any other SymPy Symbol, except that they store the information
about the coordinate system and axis they correspond to.

Scalar fields can be treated just as any other SymPy expression,
for any math/calculus functionality. Hence, to differentiate the above
electric potential with respect to \(x\) (i.e. R.x), you would
use the diff method.

It is worth noting that having a BaseScalar in the expression implies
that a ‘field’ changes with position, in 3D space. Technically speaking, a
simple Expr with no BaseScalar s is still a field, though
constant.

Like scalar fields, vector fields that vary with position can also be
constructed using BaseScalar s in the measure-number expressions.

The Del, or ‘Nabla’ operator - written as \(\mathbf{\nabla}\) is
commonly known as the vector differential operator. Depending on its
usage in a mathematical expression, it may denote the gradient of a
scalar field, or the divergence of a vector field, or the curl of a
vector field.

Essentially, \(\mathbf{\nabla}\) is not technically an ‘operator’,
but a convenient mathematical notation to denote any one of the
aforementioned field operations.

In sympy.vector, \(\mathbf{\nabla}\) has been implemented
as the delop property of the CoordSysCartesian class.
Hence, assuming C is a coordinate system, the
\(\mathbf{\nabla}\) operator corresponding to the vector
differentials wrt C‘s coordinate variables and basis vectors
would be accessible as C.delop.

A curl is a mathematical operator that describes an infinitesimal rotation of a
vector in 3D space. The direction is determined by the right-hand rule (along the
axis of rotation), and the magnitude is given by the magnitude of rotation.

In the 3D Cartesian system, the curl of a 3D vector \(\mathbf{F}\) ,
denoted by \(\nabla \times \mathbf{F}\) is given by:

Consider a scalar field \(f(x, y, z)\) in 3D space. The gradient of this field
is defined as the vector of the 3 partial derivatives of \(f\) with respect to
\(x\), \(y\) and \(z\) in the \(X\), \(Y\) and \(Z\)
axes respectively.

In the 3D Cartesian system, the divergence of a scalar field \(f\),
denoted by \(\nabla f\) is given by -

Apart from the above three common applications of \(\mathbf{\nabla}\),
it is also possible to compute the directional derivative of a field wrt
a Vector in sympy.vector.

By definition, the directional derivative of a field \(\mathbf{F}\)
along a vector \(v\) at point \(x\) represents the instantaneous
rate of change of \(\mathbf{F}\) moving through \(x\) with the
velocity \(v\). It is represented mathematically as:
\((\vec v \cdot \nabla) \, \mathbf{F}(x)\).

Directional derivatives of vector and scalar fields can be computed in
sympy.vector using the delop property of
CoordSysCartesian.

In vector calculus, a conservative field is a field that is the gradient of
some scalar field. Conservative fields have the property that their line
integral over any path depends only on the end-points, and is independent
of the path travelled.
A conservative vector field is also said to be ‘irrotational’, since the
curl of a conservative field is always zero.

In physics, conservative fields represent forces in physical systems where
energy is conserved.

To check if a vector field is conservative in sympy.vector, the
is_conservative function can be used.

We have previously mentioned that every conservative field can be defined as
the gradient of some scalar field. This scalar field is also called the ‘scalar
potential field’ corresponding to the aforementioned conservative field.

The scalar_potential function in sympy.vector calculates the
scalar potential field corresponding to a given conservative vector field in
3D space - minus the extra constant of integration, of course.

Providing a non-conservative vector field as an argument to
scalar_potential raises a ValueError.

The scalar potential difference, or simply ‘potential difference’,
corresponding to a conservative vector field can be defined as the difference
between the values of its scalar potential function at two points in space.
This is useful in calculating a line integral with respect to a conservative
function, since it depends only on the endpoints of the path.