Derive expression for the gradient of an arbitrary scalar function I'm trying to do the following problem but I have no idea how to start and was wondering if someone could point me in the right direction?
Start from the expression for the metric (the square of the infinitesimal
line element) in an arbitrary orthogonal curvilinear 3-dimensional coor-
dinate system, and obtain an expression for the gradient, grad$\phi$, of an arbitrary  differentiable  scalar  function $\phi$.
The square of the infinitesimal line element I think is: $(ds)^2=h_1^2(dx_1)^2+h_2^2(dx_2)^2+h_3^2(dx_3)^2$
Any help would be greatly appreciated!
 A: For reference, there is a derivation of gradient, divergence, and curl in curvilinear coordinates here. Note that for differentiable $\phi : \mathbb{R}^3\to \mathbb{R}$, $$\mathrm{d}\phi = \nabla\phi\cdot \mathrm{d}\mathbf{r}$$ where $\mathbf{r}$ is the position vector in your curvilinear coordinate system. As you have already found, $$\mathrm{d}\mathbf{r} = \left\lvert \frac{\partial \mathbf{r}}{\partial u_1}\right\rvert\mathrm{d}u_1\mathbf{e}_1+\left\lvert \frac{\partial \mathbf{r}}{\partial u_2}\right\rvert\mathrm{d}u_2\mathbf{e}_2+\left\lvert \frac{\partial \mathbf{r}}{\partial u_3}\right\rvert\mathrm{d}u_3\mathbf{e}_3$$ where $\mathbf{e}_i$ is the unit vector pointing along $\frac{\partial \mathbf{r}}{\partial u_i}$ (the orthogonality of our curvilinear coordinates implies that the $\mathbf{e}_i$ are orthonormal). By the chain rule, $$\mathrm{d}\phi = \frac{\partial \phi}{\partial u_1}\mathrm{d}u_1+\frac{\partial \phi}{\partial u_2}\mathrm{d}u_2+\frac{\partial \phi}{\partial u_3}\mathrm{d}u_3$$ Using a little bit of reverse engineering, we can therefore see that $\nabla\phi$ will necessarily satisfy $$\nabla\phi = \left\lvert \frac{\partial \mathbf{r}}{\partial u_1}\right\rvert^{-1}\frac{\partial \phi}{\partial u_1}\mathbf{e}_1+\left\lvert \frac{\partial \mathbf{r}}{\partial u_2}\right\rvert^{-1}\frac{\partial \phi}{\partial u_2}\mathbf{e}_2+\left\lvert \frac{\partial \mathbf{r}}{\partial u_3}\right\rvert^{-1}\frac{\partial \phi}{\partial u_3}\mathbf{e}_3$$
An example might be a spherical coordinate system, i.e. $$\mathbf{r} = (r\cos(\varphi)\sin(\theta), r\sin(\varphi)\sin(\theta), r\cos(\theta))$$ for $r > 0$, $0\leq \theta < \pi$, and $0\leq \varphi < 2\pi$. If we want to calculate the gradient in $(r, \varphi, \theta)$ coordinates, we find \begin{align*} \frac{\partial \mathbf{r}}{\partial r} &= (\cos(\varphi)\sin(\theta), \sin(\varphi)\sin(\theta), \cos(\theta)) \\ \frac{\partial \mathbf{r}}{\partial \varphi} &= (-r\sin(\varphi)\sin(\theta), r\cos(\varphi)\sin(\theta), 0) \\ \frac{\partial \mathbf{r}}{\partial \theta} &= (r\cos(\varphi)\cos(\theta), r\cos(\theta)\cos(\varphi), -r\sin(\theta)) \end{align*} You should, of course, check that these are orthogonal. This gives us \begin{align*} \left\lvert \frac{\partial \mathbf{r}}{\partial r}\right\rvert &= 1 \\ \left\lvert \frac{\partial \mathbf{r}}{\partial \varphi}\right\rvert &= r\sin(\theta) \\ \left\lvert \frac{\partial \mathbf{r}}{\partial \theta}\right\rvert &= r \end{align*} Therefore, the gradient is $$\nabla\phi = \frac{\partial \phi}{\partial r}\mathbf{e}_r+\frac{1}{r\sin(\theta)}\frac{\partial \phi}{\partial \varphi}\mathbf{e}_{\varphi}+\frac{1}{r}\frac{\partial \phi}{\partial \theta}\mathbf{e}_{\theta}$$
