Ask Your Question

Revision history [back]

Since SageMath 7.3, it's possible to deal with coordinate transforms as transition maps between charts on a manifold. For instance, the transition from polar to Cartesian coordinates in the Euclidean plane is defined as follows:

sage: M = Manifold(2, 'M') # the Euclidean plane
sage: Cart.<x,y> = M.chart()  # Cartesian coordinates (x,y)
sage: Polar.<r,th> = M.chart(r'r:(0,+oo) th:(0,2*pi):\theta') # polar coordinates (r,th)
sage: Polar_to_Cart = Polar.transition_map(Cart, [r*cos(th), r*sin(th)])
sage: Polar_to_Cart.display()
x = r*cos(th)
y = r*sin(th)
sage: Polar_to_Cart.set_inverse(sqrt(x^2+y^2), atan2(y,x))
sage: Cart_to_Polar = Polar_to_Cart.inverse()
sage: Cart_to_Polar.display()
r = sqrt(x^2 + y^2)
th = arctan2(y, x)

The examples in the CoordinateTransform Mathematica page referred to in the question are then

sage: Polar_to_Cart(r,th)
(r*cos(th), r*sin(th))
sage: Cart_to_Polar(1,-1)
(sqrt(2), -1/4*pi)

The first example of the TransformedField Mathematica page becomes

sage: f = M.scalar_field({Polar: r^2*cos(th)}, name='f')
sage: f.coord_function(Cart)
sqrt(x^2 + y^2)*x
sage: f.display()
f: M --> R
   (x, y) |--> sqrt(x^2 + y^2)*x
   (r, th) |--> r^2*cos(th)

The second example of TransformedField involves a vector field. Since vector fields on manifolds are not included in SageMath yet (but should be soon), one has to install SageManifolds atop SageMath 7.3 to deal with them. The Mathematica example becomes then:

sage: e_x, e_y = Cart.frame()[0], Cart.frame()[1]
sage: v = x*e_x + y*e_y
sage: v.display()
x d/dx + y d/dy
sage: v[:]
[x, y]
sage: v[Polar.frame(), :, Polar]
[r, 0]
sage: v.display(Polar.frame(), Polar)
r d/dr

Since SageMath 7.3, it's possible to deal with coordinate transforms as transition maps between charts on a manifold. For instance, the transition from polar to Cartesian coordinates in the Euclidean plane is defined as follows:

sage: M = Manifold(2, 'M') # the Euclidean plane
sage: Cart.<x,y> = M.chart()  # Cartesian coordinates (x,y)
sage: Polar.<r,th> = M.chart(r'r:(0,+oo) th:(0,2*pi):\theta') # polar coordinates (r,th)
sage: Polar_to_Cart = Polar.transition_map(Cart, [r*cos(th), r*sin(th)])
sage: Polar_to_Cart.display()
x = r*cos(th)
y = r*sin(th)
sage: Polar_to_Cart.set_inverse(sqrt(x^2+y^2), atan2(y,x))
sage: Cart_to_Polar = Polar_to_Cart.inverse()
sage: Cart_to_Polar.display()
r = sqrt(x^2 + y^2)
th = arctan2(y, x)

The examples in the CoordinateTransform Mathematica page referred to in the question are then

sage: Polar_to_Cart(r,th)
(r*cos(th), r*sin(th))
sage: Cart_to_Polar(1,-1)
(sqrt(2), -1/4*pi)

The first example of the TransformedField Mathematica page becomes

sage: f = M.scalar_field({Polar: r^2*cos(th)}, name='f')
sage: f.coord_function(Cart)
f.expr(Cart)
sqrt(x^2 + y^2)*x
sage: f.display()
f: M --> R
   (x, y) |--> sqrt(x^2 + y^2)*x
   (r, th) |--> r^2*cos(th)

The second example of TransformedField involves a vector field. Since vector fields on manifolds are not included in SageMath yet (but should be soon), one has to install SageManifolds atop SageMath 7.3 to deal with them. The Mathematica example becomes then:

sage: e_x, e_y = Cart.frame()[0], Cart.frame()[1]
sage: v = x*e_x + y*e_y
sage: v.display()
x d/dx + y d/dy
sage: v[:]
[x, y]
sage: v[Polar.frame(), :, Polar]
[r, 0]
sage: v.display(Polar.frame(), Polar)
r d/dr

Since SageMath 7.3, it's possible to deal with coordinate transforms as transition maps between charts on a manifold. For instance, the transition from polar to Cartesian coordinates in the Euclidean plane is defined as follows:

sage: M = Manifold(2, 'M') # the Euclidean plane
sage: Cart.<x,y> = M.chart()  # Cartesian coordinates (x,y)
sage: Polar.<r,th> = M.chart(r'r:(0,+oo) th:(0,2*pi):\theta') # polar coordinates (r,th)
sage: Polar_to_Cart = Polar.transition_map(Cart, [r*cos(th), r*sin(th)])
sage: Polar_to_Cart.display()
x = r*cos(th)
y = r*sin(th)
sage: Polar_to_Cart.set_inverse(sqrt(x^2+y^2), atan2(y,x))
sage: Cart_to_Polar = Polar_to_Cart.inverse()
sage: Cart_to_Polar.display()
r = sqrt(x^2 + y^2)
th = arctan2(y, x)

The examples in the CoordinateTransform Mathematica page referred to in the question are then

sage: Polar_to_Cart(r,th)
(r*cos(th), r*sin(th))
sage: Cart_to_Polar(1,-1)
(sqrt(2), -1/4*pi)

The first example of the TransformedField Mathematica page becomes

sage: f = M.scalar_field({Polar: r^2*cos(th)}, name='f')
sage: f.expr(Cart)
sqrt(x^2 + y^2)*x
sage: f.display()
f: M --> R
   (x, y) |--> sqrt(x^2 + y^2)*x
   (r, th) |--> r^2*cos(th)

The second example of TransformedField involves a vector field. Since vector fields on manifolds are not included in SageMath yet (but should be soon), one has to install SageManifolds atop SageMath 7.3 to deal with them. The Mathematica example becomes then:

sage: e_x, e_y = Cart.frame()[0], Cart.frame()[1]
sage: v = x*e_x + y*e_y
sage: v.display()
x d/dx + y d/dy
sage: v[:]
[x, y]
sage: v[Polar.frame(), :, Polar]
[r, 0]
sage: v.display(Polar.frame(), Polar)
r d/dr

Another example, involving coordinate transforms between 6 charts on the hyperbolic plane, is here.