Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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'm doing a basic quantum mechanics problem and am trying to learn how to do it in Mathematica. Any help would be much appreciated.

$\vec{L} = \vec{x} \times \vec{p}$

where $\vec{x}$ has components:

$\begin{align*} x &= r \sin \theta \cos \phi\\ y &= r \sin \theta \sin \phi\\ z &= r \cos \theta \end{align*}$

and $\vec{p}$ has components:

$p_x = - i \hbar \dfrac{\partial}{\partial x}$


Show that $L_z = -i \hbar \dfrac{\partial}{\partial \phi}$

share|improve this question
where have you gotten stuck? – acl Nov 9 '12 at 22:41
You can use this for a start. – b.gatessucks Nov 9 '12 at 22:47
up vote 15 down vote accepted

Here is the Mathematica proof. I'll leave out the prefactor $\hbar/i$ for simplicity. Also, in case this is a homework problem, I decided not to add too many comments to the code. Instead I'll let you figure it out. The basic idea is to do cross products and gradients in spherical coordinates. The calculation shown here actually gives you a way to calculate all angular momentum components (not just the $z$ component).

In terms of notation, I use the spherical coordinates r, θ, φ and call their unit vectors er, eθ, eφ.


Clear[r, θ, φ]

SetCoordinates[Spherical[r, θ, φ]]

(* ==> Spherical[r, θ, φ] *)

{er, eθ, eφ} = 
 Transpose[JacobianMatrix[{r, θ, φ}]]/
  ScaleFactors[{r, θ, φ}]

$\left( \begin{array}{ccc} \cos (\phi ) \sin (\theta ) & \sin (\theta ) \sin (\phi ) & \cos (\theta ) \\ \cos (\theta ) \cos (\phi ) & \cos (\theta ) \sin (\phi ) & -\sin (\theta ) \\ -\sin (\phi ) & \cos (\phi ) & 0 \\ \end{array} \right)$

l = 
  Cross[r er, 
   Transpose[{er, eθ, eφ}].Grad[f[θ, φ]]]

$\left( \begin{array}{c} \cot (\theta ) (-\cos (\phi )) f^{(0,1)}(\theta ,\phi )-\sin (\phi ) f^{(1,0)}(\theta ,\phi )\\ \cos (\phi ) f^{(1,0)}(\theta ,\phi )-\cot (\theta ) \sin (\phi ) f^{(0,1)}(\theta ,\phi )\\ f^{(0,1)}(\theta ,\phi) \end{array} \right)$

This is a list of Cartesian components (because the Cross product needed to be done in Cartesian coordinates) - the last entry in the list l is the z component of the angular momentum.

Here f is a test function to which I apply the operator. $f^{(0,1)}(\theta ,\phi)$ is the derivative with respect to the azimuthal coordinate.

The spherical components of the angular momentum (which you didn't ask for, but I mentioned in an earlier version of this answer) are obtained as follows:

FullSimplify[{er, eθ , eφ}.l]

$\left(0,-\csc (\theta ) f^{(0,1)}(\theta ,\varphi ),f^{(1,0)}(\theta ,\varphi )\right)$

Edit for version 9

Although the above solution still works if you load the VectorAnalysis package, there are compatibility warnings now because the package has become obsolete with Mathematica version 9. So for this new version it's better to extract the coordinate transformation data in a different way:

{er, eθ, eφ} = 
  CoordinateTransformData[{"Spherical" -> "Cartesian"}, 
   "OrthonormalBasisRotation", {r, θ, φ}];
l = FullSimplify@
  Cross[r er, 
   Transpose[{er, eθ, eφ}].Grad[
     f[θ, φ], {r, θ, φ}, 

The result is the same as above. Typing the lengthy "OrthonormalBasisRotation" expression to define the orthonormal basis vectors of the spherical coordinate system takes some getting used to. It's almost equally easy to re-derive them from first principles - but I wanted to show where the obsolete JacobianMatrix and ScaleFactors information is hidden now.

share|improve this answer
Thank you for your thorough explanation! This was in fact a homework problem, though I had solved it on paper already. – TaylorR137 Nov 12 '12 at 22:11

I wrote some quite general solution, that uses built in functions for coordinate transforming. I hope that it will be helpful.








coordinateTransformRules=Thread[$\[ScriptCapitalD]NewVariables->CoordinateTransform[ system1->system2,$\[ScriptCapitalD]Variables]];

inverseCoordinateTransformRules=Thread[$\[ScriptCapitalD]Variables->CoordinateTransform[ system2->system1,$\[ScriptCapitalD]NewVariables]];




Some examples:

\[ScriptCapitalD]Transform[D[u[x, y], x, x] + D[u[x, y], y, y], {u}, {x, y}, {r, \[Phi]}, "Cartesian" -> "Polar", {r > 0, 0 < \[Phi] < 2 Pi}]

\[ScriptCapitalD]Transform[D[u[x, y, z], x, x] + D[u[x, y, z], y, y] + D[u[x, y, z], z, z], {u}, {x, y, z}, {r, \[Theta], \[Phi]}, "Cartesian" -> "Spherical", {r > 0, 0 < \[Theta] < Pi, -Pi < \[Phi] < Pi}]

\[ScriptCapitalD]Transform[D[T[A, B], A] + 2 D[T[A, B], A, B] + 1/x D[T[A, B], B, B], {T}, {A,  B}, {\[CapitalPsi], \[CapitalOmega]}, "Cartesian" -> "PlanarParabolic", {\[CapitalPsi] \[Element] Reals, 0 <= \[CapitalOmega], (\[CapitalPsi] != 0 || \[CapitalOmega] != 0)}]
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.