I am working in a script to do analytical calculations in Python. For it I would need vector representation of my parameters and also some basic vector operations such as Gradient and Divergence, and for this reason I started working in SymPy. However, I noticed there is not a straightforward way of working in spherical coordinates.
After reading the documentation I found out a Cartessian environment can be simply defined as
from sympy.vector import CoordSys3D
N = CoordSys3D('N')
and directly start working with the unitary cartessian unitary vectors i, j, k
v = 2*N.i + 3*N.j - N.k
Is there any way of initializing such an environment for spherical coordinates where I have access to radial, theta and phi unitary vectors, and consequently the basic vector operations are done accordingly? Thank you so much in advance!
You can access spherical coordinate unitary vectors as 'r', 't', 'p' (or you can use full names like 'radius', 'theta', 'phi') instead of 'i', 'j', ,'k' if you indicate that the transformation is 'spherical':
>>> from sympy.vector import CoordSys3D
>>> P = CoordSys3D('P', transformation='spherical', variable_names=list('rtp'))
>>> P.r
P.r