Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
I suggest you look at this tutorial. – m_goldberg Sep 17 '13 at 12:36
Any code you are working on ? – Sektor Sep 17 '13 at 13:04
Thanks @m_goldberg, this helps although it seems that this functionality is new in Mathematica 9, right? – The Dude Sep 17 '13 at 13:12
Yes. Is that a problem for you? – m_goldberg Sep 17 '13 at 13:32
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. – The Dude Sep 17 '13 at 13:49

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:

share|improve this answer

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}  *)
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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