ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 21 Aug 2016 18:25:03 +0200Coordinate Transformshttps://ask.sagemath.org/question/9966/coordinate-transforms/Is there something in sage that does the same thing that `CoordinateTransform` and `TransformedField` in Mathematica 9 ?
The idea is that `CoordinateTransform` is given some coordinates, e.g. (r,th) and asked to transform them from "polar" to "cartesian", thus gives the expression of the cartesian coordinates in terms of the polar coordinates, e.g.
(x(r,th), y(r,th)) = (r*cos(th), r*sin(th))
Obvioulsly, it also works with other coordinates systems.
`TransformedField` makes the transformation between a scalar, vector, or tensor field in, say, cartesian coordinates, to spherical coordinates.
These actions are not very complicated, nor difficult to implement when needed, but they are also very common.
Thanks.
references :
* http://reference.wolfram.com/mathematica/ref/CoordinateTransform.html
* http://reference.wolfram.com/mathematica/ref/TransformedField.htmlSun, 31 Mar 2013 20:04:28 +0200https://ask.sagemath.org/question/9966/coordinate-transforms/Answer by eric_g for <p>Is there something in sage that does the same thing that <code>CoordinateTransform</code> and <code>TransformedField</code> in Mathematica 9 ?</p>
<p>The idea is that <code>CoordinateTransform</code> is given some coordinates, e.g. (r,th) and asked to transform them from "polar" to "cartesian", thus gives the expression of the cartesian coordinates in terms of the polar coordinates, e.g.</p>
<pre><code>(x(r,th), y(r,th)) = (r*cos(th), r*sin(th))
</code></pre>
<p>Obvioulsly, it also works with other coordinates systems.</p>
<p><code>TransformedField</code> makes the transformation between a scalar, vector, or tensor field in, say, cartesian coordinates, to spherical coordinates. </p>
<p>These actions are not very complicated, nor difficult to implement when needed, but they are also very common.</p>
<p>Thanks.</p>
<p>references :</p>
<ul>
<li><a href="http://reference.wolfram.com/mathematica/ref/CoordinateTransform.html">http://reference.wolfram.com/mathemat...</a></li>
<li><a href="http://reference.wolfram.com/mathematica/ref/TransformedField.html">http://reference.wolfram.com/mathemat...</a></li>
</ul>
https://ask.sagemath.org/question/9966/coordinate-transforms/?answer=34550#post-id-34550Since 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](http://sagemanifolds.obspm.fr/) 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](http://nbviewer.jupyter.org/github/sagemanifolds/SageManifolds/blob/master/Worksheets/v0.9/SM_hyperbolic_plane.ipynb).Sun, 21 Aug 2016 18:25:03 +0200https://ask.sagemath.org/question/9966/coordinate-transforms/?answer=34550#post-id-34550Answer by Jason Grout for <p>Is there something in sage that does the same thing that <code>CoordinateTransform</code> and <code>TransformedField</code> in Mathematica 9 ?</p>
<p>The idea is that <code>CoordinateTransform</code> is given some coordinates, e.g. (r,th) and asked to transform them from "polar" to "cartesian", thus gives the expression of the cartesian coordinates in terms of the polar coordinates, e.g.</p>
<pre><code>(x(r,th), y(r,th)) = (r*cos(th), r*sin(th))
</code></pre>
<p>Obvioulsly, it also works with other coordinates systems.</p>
<p><code>TransformedField</code> makes the transformation between a scalar, vector, or tensor field in, say, cartesian coordinates, to spherical coordinates. </p>
<p>These actions are not very complicated, nor difficult to implement when needed, but they are also very common.</p>
<p>Thanks.</p>
<p>references :</p>
<ul>
<li><a href="http://reference.wolfram.com/mathematica/ref/CoordinateTransform.html">http://reference.wolfram.com/mathemat...</a></li>
<li><a href="http://reference.wolfram.com/mathematica/ref/TransformedField.html">http://reference.wolfram.com/mathemat...</a></li>
</ul>
https://ask.sagemath.org/question/9966/coordinate-transforms/?answer=14715#post-id-14715You can define functions to act as transformations:
T(r,theta) = (r*sin(theta), r*cos(theta))
and then just use them as normal functions: `T(2,pi/2)`
Also, you can pass an arbitrary 3d transformation to 3d plots using the transformation keyword. See the examples in the [plot3d documentation](http://www.sagemath.org/doc/reference/plot3d/sage/plot/plot3d/plot3d.html#sage.plot.plot3d.plot3d.plot3d). See also the builtin [Spherical](http://www.sagemath.org/doc/reference/plot3d/sage/plot/plot3d/plot3d.html#sage.plot.plot3d.plot3d.Spherical) and [Cylindrical](http://www.sagemath.org/doc/reference/plot3d/sage/plot/plot3d/plot3d.html#sage.plot.plot3d.plot3d.Cylindrical) transformations, or even the [spherical_plot3d](http://www.sagemath.org/doc/reference/plot3d/sage/plot/plot3d/plot3d.html#sage.plot.plot3d.plot3d.spherical_plot3d) or [cylindrical_plot3d](http://www.sagemath.org/doc/reference/plot3d/sage/plot/plot3d/plot3d.html#sage.plot.plot3d.plot3d.cylindrical_plot3d) functions.
It would be cool to have a transformation module that defines a bunch of transformations for convenience.Mon, 01 Apr 2013 06:19:35 +0200https://ask.sagemath.org/question/9966/coordinate-transforms/?answer=14715#post-id-14715