# Differentiation spherical coordinates

1. Aug 23, 2013

### ebrattr

Hi ! I'm trying to inverse a mass matrix so I need to do something like this

$\dfrac{q}{\partial \mathbf{r}}$ where $\cos q = \dfrac{\mathbf{r}\cdot \hat{\mathbf{k}}}{r}$

However, when $\mathbf{r} = \hat{\mathbf{k}} \text{ or } -\hat{\mathbf{k}}$ I have problems.

¿What can I do?

Thanks !

2. Aug 23, 2013

### Staff: Mentor

What does $\dfrac{q}{\partial \mathbf{r}}$ mean?
Did you mean to write this?
$\dfrac{\partial q}{\partial \mathbf{r}}$
Isn't k$\cdot$k = 1, and similarly, isn't -k$\cdot$k = -1? What problems are you having?

3. Aug 23, 2013

### ebrattr

Yes, I mean $\dfrac{\partial q}{\partial \mathbf{r}}$ As you know if you do $\dfrac{\partial}{\partial \mathbf{r}}$ both sides you get $\dfrac{\partial q}{\partial \mathbf{r}} -\sin q = \dfrac{\hat{\mathbf{k}}}{L}$. Solving for $\dfrac{\partial q}{\partial \mathbf{r}}$ you get $\dfrac{\partial q}{\partial \mathbf{r}} = -\dfrac{\hat{\mathbf{k}}}{L\sin q}$ So, when $q=0$ I'm having troubles.

4. Aug 27, 2013

### vanhees71

You have to transform the gradient to spherical coordinates first. This you get with
$$\mathrm{d} f=\mathrm{d} \vec{r} \cdot \vec{\nabla} f = (\mathrm{d} r \vec{e}_r \cdot +\mathrm{d} \vartheta r \vec{e}_{\vartheta} + \mathrm{d} \varphi r \sin \vartheta \vec{e}_{\varphi}) \cdot \nabla{f}.$$
Since $\vec{e}_{r}$, $\vec{e}_{\vartheta}$, and $\vec{e}_{\varphi}$ build a complete orthonormal system you immediately read off
$$\vec{\nabla} \cdot \vec{r}=\vec{e}_r \frac{\partial f}{\partial r} + \vec{e}_{\vartheta} \frac{1}{r} \frac{\partial f}{\partial \vartheta} + \vec{e}_{\varphi} \frac{1}{r \sin \vartheta} \frac{\partial f}{\partial \vartheta}.$$
For $f=\vartheta$ you thus get
$$\vec{\nabla} \vartheta=\frac{1}{r} \vec{e}_{\vartheta}.$$
You can of course do the whole thing in Cartesian coordinates:
$$f=\arccos \left (\frac{\vec{k} \cdot \vec{r}}{r} \right ).$$
Using the chain rule gives
$$\vec{\nabla} f=-\frac{1}{\sin \vartheta} \vec{\nabla} \left (\frac{\vec{k} \cdot \vec{r}}{r} \right )=-\frac{1}{\sin \vartheta} \left (\frac{\vec{k}}{r}-\frac{(\vec{r} \cdot \vec{k}) \vec{r}}{r^3} \right ).$$
Now we can simplify
$$\frac{\vec{k}}{r}-\frac{(\vec{r} \cdot \vec{k}) \vec{r}}{r^3} =\frac{1}{r} \left (\vec{k} - \frac{(\vec{r} \cdot \vec{k}) \vec{r}}{r^2} \right )=-\frac{\sin \vartheta}{r} \begin{pmatrix} \cos \varphi \cos \vartheta \\ \sin \varphi \cos \vartheta \\ -\sin \vartheta \end{pmatrix}=-\frac{\vec{e}_{\vartheta} \sin \vartheta}{r}.$$
Plugging this into the equation above you again get
$$\vec{\nabla} \vartheta=\frac{1}{r} \vec{e}_{\vartheta}.$$
As you see you always must use the correct expression of the covariant differential operators to get the right result!