$\operatorname{div}$ and $\operatorname{grad}$ in spherical coordinates. Formula from general relativity goes crazy

I try to calculate the gradient of a function and the divergence of a vector field in spherical coordinates. Nothing special so far, but a formula that I learned in a general relativity lecture creates confusion.

First of all consider a vector field $f$ and a function $h$ on $\mathbb R^3$. Of course in spherical coordinates we have

\begin{align*} \operatorname{div} f &= \frac{1}{r^2}\partial_r (r^2 f^r) + \frac{1}{r \sin \theta} \partial_\theta (\sin \theta f^\theta) + \frac{1}{r \sin \theta} \partial_\varphi f^\varphi\\ \operatorname{grad} h &= e_r \partial_r h + e_\theta \frac{1}{r}\partial_\theta h + e_\varphi \frac{1}{r \sin \theta} \partial_\varphi h \end{align*}

In the general relativity lecture I learned the two formulas

$$\nabla_\mu f^\mu = \frac{1}{\sqrt{|\operatorname{det} g|}}\partial_\mu (\sqrt{|\operatorname{det}g|}f^\mu)$$

and

$$\nabla h = (\nabla h)^\nu \partial_\nu = g^{\mu\nu}\partial_\mu h \partial_\nu$$

where the Riemannian Metric in spherical coordinates reads

$$g = \text d r^2 + r^2 \text d \theta^2 + r^2 \sin^2 \theta \text d \varphi^2$$

so that

$$\sqrt{|\operatorname{det}g|} = r^2 \sin \theta$$

If I now use the two formulas I get different results for the gradient and the divergence:

\begin{align*} \nabla_\mu f^\mu &= \frac{1}{r^2} \partial_r (r^2 f^r) + \frac{1}{\sin\theta}\partial_\theta(\sin\theta f^\theta) + \partial_\varphi f^\varphi\\ \nabla h &= \partial_r h \partial_r + \frac{1}{r^2}\partial_\theta h \partial_\theta + \frac{1}{r^2 \sin^2 \theta}\partial_\varphi h \partial_\varphi \end{align*}

Can someone tell me what went wrong? I guess that something is wrong when I compare the unit vector notation $e_i$ with $\partial_i$

• Your guess is correct. While $\partial_r$ already has length $1$, note that $e_\theta = \frac{\partial_\theta}{\sqrt{g^{22}}}$ and $e_{\varphi} = \frac{\partial_\varphi}{\sqrt{g^{33}}}$. You should alse be grateful that the metric tensor is diagonal... – Thomas Mar 21 '14 at 14:57
• Hm, so when I introduce the normalized unit vectors $\tilde \partial_ \theta = 1/\sqrt {g^{22}}\,\partial_\theta$ and $\tilde \partial_ \varphi = 1/\sqrt {g^{33}}\,\partial_\varphi$ it works fine for the $\nabla h$ formula but not for $\nabla_\mu f^\mu$ – thyme Mar 21 '14 at 15:15
• @thyme What basis and coordinates are you using for $f$? It is a vector too, unlike $h$. – geodude Mar 21 '14 at 19:13
• So I shall write $f = f^\mu\partial_\mu = f^r\partial_r+f^\theta\sqrt {g^{22}}\tilde\partial_\theta+f^\varphi\sqrt {g^{33}}\tilde\partial_\varphi$ ? But it still does not fit. Sorry for my stupidity in this issue... – thyme Mar 21 '14 at 20:53
• It's really much clearer if you avoid unit vectors; honestly, it's a serious mistake in my opinion that vector calculus is taught using unit vectors for these formulas when you just have to ditch them later. – Muphrid Mar 22 '14 at 5:37