1
$\begingroup$

Let us consider a function $f(r,\theta,\phi)$ that can only be efficiently computed in spherical coordinates. We need its Cartesian gradient. We can implement its analytical spherical derivatives, compute the spherical gradient, $\left(\frac{\partial f}{\partial r},\frac{1}{r}\frac{\partial f}{\partial \theta},\frac{1}{r\sin\theta}\frac{\partial f}{\partial \phi}\right)$, and convert the gradient to Cartesian component.

What would you do with the values along the $z$-axis, where $\theta$ is undefined and usually set to 0, and in the origin, where $r$ is 0 as well? More specifically, what would you do with the terms in the denominators $r$ and $r\sin\theta$?

$\endgroup$
  • 3
    $\begingroup$ If the surface given by $f$ is smooth enough (I guess you are with an expansion of $f$ in terms of spherical harmonics) , you will not have any problem with your gradient (as long as you take care within these areas $\theta=0$ and $r=0$). Usually, the smoothness of the surface implies that the terms $\partial u/\partial\theta /(r\sin{\theta})=\mathcal{O}(1)$ or $\partial u/\partial \phi /r=\mathcal{O}(1)$ at least, when $\theta\to 0$ and $r\to 0$ $\endgroup$ – HBR Jul 21 '17 at 18:13
  • $\begingroup$ Is your function numerically unstable at the origin? If it is, then there's no general technique for fixing that for an arbitrary $f$ (apart from using arbitrary precision arithmetic), so one would have to know some details about the function itself. $\endgroup$ – Kirill Jul 21 '17 at 21:12
  • $\begingroup$ @Kirill Let us say that $f$ returns high-order spherical harmonics computed by Legendre polynomial recursion (so you need spherical coordinates for that). You get that the $\phi$-component of the spherical gradient blows up along the $z$-axis. $\endgroup$ – Pippo Jul 22 '17 at 9:53
  • 1
    $\begingroup$ Supposing that your function may be expandible in terms of spherical harmonics, $i.e.$ $f=\sum_{l,m}{f_{lm} Y_l^{m}}$. If the spherical harmonics depend only on the Legendre polynomials, the function $f$ can be considered axisymetric and therefore $\partial f/\partial\phi=0$. If not, the spherical harmonics that depend on $\phi$ are always proportional to some power of $\sin{\theta}$ and therefore the third component of yout gradient, computed in spherical coodinates will be always finite and well defined when $\theta\to 0$, see for example mathworld.wolfram.com/SphericalHarmonic.html $\endgroup$ – HBR Jul 22 '17 at 11:18
  • $\begingroup$ You are right, @HBR, I made a mistake in my calculations. $\endgroup$ – Pippo Jul 22 '17 at 12:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.