Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sympy.vector.express doesn't express field in spherical coordinates #15987

Open
Mantabit opened this issue Feb 15, 2019 · 6 comments · May be fixed by #17507
Open

sympy.vector.express doesn't express field in spherical coordinates #15987

Mantabit opened this issue Feb 15, 2019 · 6 comments · May be fixed by #17507
Labels

Comments

@Mantabit
Copy link

Mantabit commented Feb 15, 2019

Hello

I am using the vector module to define a field in Cartesian coordinates and I want to get an expression for that field in spherical coordinates:

from sympy.vector import CoordSys3D, express

C=CoordSys3D('C')
S=C.create_new('S',transformation="spherical")

testfield=C.x*C.i+C.y*C.j+C.z*C.k

print(S.base_scalars())
print(S.base_vectors())
print(express(testfield,S,variables=True))

However, this code will result in the output:

(S.r, S.theta, S.phi)
(S.i, S.j, S.k)
S.rS.i + S.thetaS.j + S.phi*S.k

Not quite sure what's the issue here?

@friyaz
Copy link
Member

friyaz commented Feb 15, 2019

It looks like scalar_map() does not work correctly when system is defined with help of transformation equation.

>>> S.scalar_map(C)
{S.r: C.x, S.phi: C.z, S.theta: C.y}

@Mantabit
Copy link
Author

I also get an incorrect result if I pass a lambda expression as the argument for transformation:

from sympy.vector import CoordSys3D, express
from sympy import sin,cos

C=CoordSys3D('C')
S=C.create_new('S',transformation=lambda r,phi,theta: (r*sin(theta)*cos(phi),r*sin(theta)*sin(phi),r*cos(theta)),variable_names=("r","phi","theta"))

testfield=C.x*C.i+C.y*C.j+C.z*C.k

print(S.base_scalars())
print(S.base_vectors())
print(express(testfield,S,variables=True))

This results in the output:

(S.r, S.phi, S.theta)
(S.i, S.j, S.k)
S.r * S.i + S.phi * S.j + S.theta * S.k

@friyaz
Copy link
Member

friyaz commented Feb 17, 2019

I think rotation_matrix is to blame here.
rotation_matrix does not change when transformation equations are used to define a new system.

>>> from sympy.vector import CoordSys3D, express
>>> C = CoordSys3D('C')
>>> S = C.create_new('S',transformation="spherical")
>>> S.rotation_matrix()
Matrix([
[1, 0, 0],
[0, 1, 0],
[0, 0, 1]])

>>> B = C.create_new('B', transformation=lambda x,y,z: (x*sin(y), x*cos(y), z))
>>> B.rotation_matrix()
Matrix([
[1, 0, 0],
[0, 1, 0],
[0, 0, 1]])

Can you have a look @smichr .

@friyaz
Copy link
Member

friyaz commented Feb 19, 2019

ping @jksuom

@jksuom
Copy link
Member

jksuom commented Feb 19, 2019

It seems to me that express was designed to work with rectilinear coordinate systems only.

@Mantabit
Copy link
Author

It seems to me that express was designed to work with rectilinear coordinate systems only.

True. As far as I can tell, there's also no way to get the unit vectors of a spherical coordinate system which would be required to transform a vectorial expression.

@jksuom jksuom mentioned this issue Mar 1, 2019
@rflowers rflowers linked a pull request Aug 25, 2019 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants