I would like to input a 3-vectors in spherical coordinates $(r, \theta, \phi)$ and be able to operate on such vectors (dot and cross product) with the results being given in the same spherical coordinate system.

Is there an easy way to achieve this in Mathematica?

  • 4
    $\begingroup$ I suggest you look at this tutorial. $\endgroup$
    – m_goldberg
    Sep 17, 2013 at 12:36
  • $\begingroup$ Any code you are working on ? $\endgroup$
    – Sektor
    Sep 17, 2013 at 13:04
  • $\begingroup$ Thanks @m_goldberg, this helps although it seems that this functionality is new in Mathematica 9, right? $\endgroup$
    – The Dude
    Sep 17, 2013 at 13:12
  • $\begingroup$ Yes. Is that a problem for you? $\endgroup$
    – m_goldberg
    Sep 17, 2013 at 13:32
  • $\begingroup$ Unfortunately yes but I hope I'll be able to upgrade to version 9 soon. Is there some external similar package for version 8? Thanks anyway @m_goldberg. $\endgroup$
    – The Dude
    Sep 17, 2013 at 13:49

2 Answers 2


In older versions of Mathematica, the standard package CalculusVectorAnalysisdid the trick, I believe.



you entered a new world where

CrossProduct[v1,v2] and 

are computed with the selected coordinate system. The computation is performed by MMA converting into Cartesian system and then converting back. You are bound to use those specialized function, but I believe it is still possibile (albeit non advisable) to unprotect the more general Dot and Cross operators to make them work in the new way. Problem is: what happens to the rest of the code that uses them? You might be better off with defining a new shorthand form for the above functions.

[Edit, oh, there were two more comments below, one of which with the link to the documentation, posted way before mine.]

Reference for mma8:

http://reference.wolfram.com/legacy/v8/VectorAnalysis/ref/SetCoordinates.html http://reference.wolfram.com/legacy/v8/VectorAnalysis/tutorial/VectorAnalysis.html


One possible workaround would be to first transform the vectors into Cartesian coordinates, then use standard operations and afterwards to transform them back to spherical ones, if needed. Something like the following.

These two functions make the transformations: toCart - from spherical to Cartesian, while toSph - from Cartesian to spherical:

toCart[a_List] := {a[[1]]*Sin[a[[2]]]*Cos[a[[3]]], 
   a[[1]]*Sin[a[[2]]]*Sin[a[[3]]], a[[1]]*Cos[a[[2]]]}; 

 toSph[r_List] := {Sqrt[r[[1]]^2 + r[[2]]^2 + r[[3]]^2], 
   ArcCos[r[[3]]/Sqrt[r[[1]]^2 + r[[2]]^2 + r[[3]]^2]], 
   ArcSin[r[[2]]/Sqrt[r[[1]]^2 + r[[2]]^2]]};

Consider, for example, two vectors u and v given in spherical coordinates:

u = {1., \[Pi]/6, \[Pi]/4};
v = {2., \[Pi]/3, \[Pi]/2};

Let us transform them into Cartesian ones and call their Cartesian versions u1 and v1

u1 = toCart[u]
v1 = toCart[v]

(*  {0.353553, 0.353553, 0.866025}  *)
(*  {0., 1.73205, 1.}               *)

Now here is their scalar product:



And this is the cross product transformed into the spherical coordinates:

Cross[u1, v1] // toSph

(*  {1.34697, 1.09884, -0.299137}  *)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.