Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

As the error message says, you must use set_inverse() to set the inverse by hand, because SageMath is not capable to invert the system automatically in this case. So you should run

spherical_to_Cartesian.set_inverse(sqrt(x^2+y^2+z^2), 
                                   atan2(sqrt(x^2+y^2), z),
                                   atan2(y, x))

Then you may write

Cartesian_to_spherical = spherical_to_Cartesian.inverse()
Cartesian_to_spherical.display()

the output of which is

r = sqrt(x^2 + y^2 + z^2)
th = arctan2(sqrt(x^2 + y^2), z)
ph = arctan2(y, x)

Note that you can add the optional parameter verbose=True to set_inverse in order for SageMath to check that the provided inverse is valid (the check consists in performing the coordinate transformation followed by its inverse, in both directions):

spherical_to_Cartesian.set_inverse(sqrt(x^2+y^2+z^2), 
                                   atan2(sqrt(x^2+y^2), z),
                                   atan2(y, x), verbose=True)

This results in

Check of the inverse coordinate transformation:
  r == abs(r)
  th == arctan2(abs(r)*sin(th), r*cos(th))
  ph == arctan2(r*cos(ph)*sin(th), r*sin(ph)*sin(th))
  x == y
  y == x
  z == z

As you can see, the check is not perfect, partly because you did not specify the range for the coordinate r, so that abs(r) could not be simplified. If you specify r:(0,+oo) while declaring sphericalChart, then you get:

Check of the inverse coordinate transformation:
  r == r
  th == arctan2(r*sin(th), r*cos(th))
  ph == arctan2(r*cos(ph)*sin(th), r*sin(ph)*sin(th))
  x == y
  y == x
  z == z

This is almost OK, except for some lack of simplification of the arctan2 function.

As the error message says, you must use set_inverse() to set the inverse by hand, because SageMath is not capable to invert the system automatically in this case. So you should run

spherical_to_Cartesian.set_inverse(sqrt(x^2+y^2+z^2), 
                                   atan2(sqrt(x^2+y^2), z),
                                   atan2(y, x))

Then you may write

Cartesian_to_spherical = spherical_to_Cartesian.inverse()
Cartesian_to_spherical.display()

the output of which is

r = sqrt(x^2 + y^2 + z^2)
th = arctan2(sqrt(x^2 + y^2), z)
ph = arctan2(y, x)

Note that you can add the optional parameter verbose=True to set_inverse in order for SageMath to check that the provided inverse is valid (the check consists in performing the coordinate transformation followed by its inverse, in both directions):

spherical_to_Cartesian.set_inverse(sqrt(x^2+y^2+z^2), 
                                   atan2(sqrt(x^2+y^2), z),
                                   atan2(y, x), verbose=True)

This results in

Check of the inverse coordinate transformation:
  r == abs(r)
  th == arctan2(abs(r)*sin(th), r*cos(th))
  ph == arctan2(r*cos(ph)*sin(th), r*sin(ph)*sin(th))
  x == y
  y == x
  z == z

As you can see, the check is not perfect, partly because you did not specify the range for the coordinate r, so that abs(r) could not be simplified. If you specify r:(0,+oo) while declaring sphericalChart, then you get:

Check of the inverse coordinate transformation:
  r == r
  th == arctan2(r*sin(th), r*cos(th))
  ph == arctan2(r*cos(ph)*sin(th), r*sin(ph)*sin(th))
  x == y
  y == x
  z == z

This is almost OK, except for some lack of simplification of the arctan2 function.

PS: many examples of use of set_inverse() can be found in the $H^2$ example.

As the error message says, you must use set_inverse() to set the inverse by hand, because SageMath is not capable to invert the system automatically in this case. So you should run

spherical_to_Cartesian.set_inverse(sqrt(x^2+y^2+z^2), 
                                   atan2(sqrt(x^2+y^2), z),
                                   atan2(y, x))

Then you may write

Cartesian_to_spherical = spherical_to_Cartesian.inverse()
Cartesian_to_spherical.display()

the output of which is

r = sqrt(x^2 + y^2 + z^2)
th = arctan2(sqrt(x^2 + y^2), z)
ph = arctan2(y, x)

Note that you can add the optional parameter verbose=True to set_inverse in order for SageMath to check that the provided inverse is valid (the check consists in performing the coordinate transformation followed by its inverse, in both directions):

spherical_to_Cartesian.set_inverse(sqrt(x^2+y^2+z^2), 
                                   atan2(sqrt(x^2+y^2), z),
                                   atan2(y, x), verbose=True)

This results in

Check of the inverse coordinate transformation:
  r == abs(r)
  th == arctan2(abs(r)*sin(th), r*cos(th))
  ph == arctan2(r*cos(ph)*sin(th), r*sin(ph)*sin(th))
  x == y
  y == x
  z == z

As you can see, the check is not perfect, partly because you did not specify the range for the coordinate r, so that abs(r) could not be simplified. If you specify r:(0,+oo) while declaring sphericalChart, then you get:

Check of the inverse coordinate transformation:
  r == r
  th == arctan2(r*sin(th), r*cos(th))
  ph == arctan2(r*cos(ph)*sin(th), r*sin(ph)*sin(th))
  x == y
  y == x
  z == z

This is almost OK, except for some lack of simplification of the arctan2 function.

PS: many examples of use of set_inverse() can be found in the $H^2$ hyperbolic plane example.