I am trying compute the triple integral of a 3D Gaussian within a sphere hollow space. My questions are at the end.

You can think the problem in this manner. There is a very large ball whose center is hollow. The density follows 3D gaussian distribution, now I want to compute the mass of the hollow ball.

The 3D Gaussian is:

$$ f(x,y,z) = \frac{1}{(2 \pi)^{\frac{3}{2}} \sigma_x \sigma_y \sigma_z} \exp \left[ -\frac{(x-\mu_x)^2}{2\sigma_x^2} - \frac{(y-\mu_y)^2}{2\sigma_y^2} - \frac{(z-\mu_z)^2}{2\sigma_z^2} \right] , $$

where $$ \quad \Sigma = \begin{pmatrix} \sigma_x^2 & 0 & 0 \\ 0 & \sigma_y^2 & 0 \\ 0 & 0 & \sigma_z^2\end{pmatrix},$$

And the integral is $ \int \limits_{V} f(x,y,z)dv$, and $V$ is the area of $\sqrt{x^2 + y^2 + z^2} >= R$, $R \in [0, +\infty]$. After integration, it should be a function of $R$.

For further simplification, I treated $\mu_x = \mu_y = \mu_z = 0$, and $\sigma_z = \sigma_y = \sigma_z = \sigma$.

And the original equation became: $$ f(x,y,z) = \frac{1}{(2 \pi)^{\frac{3}{2}} \sigma^3} \exp \left[ -\frac{x^2 + y^2 + z^2}{2\sigma^2} \right]. $$

Followings are my integration process, and I am not sure whether I am correct or not.

$$ \int \limits_{V} f(x,y,z)dv = \int \limits_{V} f(x,y,z)dx dy dz $$

$$ = \int \limits_{V} \frac{1}{(2 \pi)^{\frac{3}{2}} \sigma^3} \exp \left( {- \frac{\rho^2}{2\sigma^2}}\right) \rho^2 \sin \phi d\rho d\phi d\theta $$

$$ = \frac{1}{(2 \pi)^{\frac{3}{2}} \sigma^3} \int \limits_{0}^{2\pi} d\theta \int \limits_{0}^{\pi} sin \phi d\phi \int \limits_{R}^{+\infty} \rho^2 \exp \left( {- \frac{\rho^2}{2\sigma^2}}\right) d\rho $$

$$ \int \limits_{0}^{2\pi} d\theta = 2\pi; \int \limits_{0}^{\pi} d\phi = -\cos(\pi) + \cos(0) = 2; $$

Thus, it becomes $$ = \frac{\sqrt{2}}{\sqrt{\pi}\sigma^3} \int \limits_{R}^{+\infty} \rho^2 \exp \left( {- \frac{\rho^2}{2\sigma^2}}\right) d\rho $$

$$ = \frac{\sqrt{2}}{\sqrt{\pi}\sigma} \int \limits_{R}^{+\infty} \rho \exp \left( {- \frac{\rho^2}{2\sigma^2}}\right) d{\left(\frac{\rho^2}{2\sigma^2}\right)} $$

$$ = \frac{\sqrt{2}}{\sqrt{\pi}\sigma} \int \limits_{R}^{+\infty} -\rho \cdot d \left( {\exp{\left[ -\frac{\rho^2}{2\sigma^2}\right]}} \right) $$

$$ = \frac{\sqrt{2}}{\sqrt{\pi}\sigma} \left[ {-\rho\exp{\left( -\frac{\rho^2}{2\sigma^2}\right)}} \Big|_R^{+\infty} + \int \limits_R^{+\infty} \exp \left({-\frac{\rho^2}{2\sigma^2} }\right) d\rho \right] $$

As $lim_{n\to\infty} \frac{x}{e^{x^2}} = lim_{n\to\infty} \frac{\frac{dx}{dx}}{d e^{x^2}} = lim_{n\to\infty} \frac{1}{2x e^{x^2}} = 0$

The original integration becomes $$ = \frac{\sqrt{2}}{\sqrt{\pi}\sigma} \left[ \left[ 0 + R\exp{\left( -\frac{R^2}{2\sigma^2}\right)}\right] + \int \limits_R^{+\infty} \exp \left({-\frac{\rho^2}{2\sigma^2} }\right) d\rho \right] $$

The integration in the equation can be calculated separately $$ \int \limits_R^{+\infty} \exp \left({-\frac{\rho^2}{2\sigma^2} }\right) d\rho $$ $$ = \sqrt{2\pi}\sigma \int \limits_R^{+\infty} \frac{1}{\sqrt{2\pi}\sigma }\exp \left({-\frac{\rho^2}{2\sigma^2} }\right) d\rho $$ This is the normal distribution function, which can be easily calculated as

$$ = \sqrt{2\pi}\sigma \left[ 1 - \int \limits_{-\infty}^R \frac{1}{\sqrt{2\pi}\sigma }\exp \left({-\frac{\rho^2}{2\sigma^2} }\right) d\rho \right] $$

$$ = \sqrt{2\pi}\sigma \left[ 1 - \frac{1}{2} \left[ 1 + erf \left( \frac{R}{\sqrt 2 \sigma} \right) \right] \right] $$

$$ = \frac{\sqrt\pi}{\sqrt2}\sigma \left[ 1 - erf \left( \frac{R}{\sqrt2 \sigma}\right) \right] $$ Plug the result in the original equation $$ \frac{\sqrt{2}}{\sqrt{\pi}\sigma} \left[ R\exp{\left( -\frac{R^2}{2\sigma^2}\right)} + \frac{\sqrt\pi}{\sqrt2}\sigma \left[ 1 - erf \left( \frac{R}{\sqrt2 \sigma}\right) \right] \right] $$ $$ = \frac{\sqrt{2}}{\sqrt{\pi}\sigma} \left[ R\exp{\left( -\frac{R^2}{2\sigma^2}\right)} + \frac{\sqrt\pi}{\sqrt2}\sigma \left[ 1 - erf \left( \frac{R}{\sqrt2 \sigma}\right) \right] \right] $$ $$ = 1 - erf{\left( \frac{R}{\sqrt2\sigma} \right)}+ \frac{\sqrt{2}}{\sqrt{\pi}\sigma} R\exp{\left( -\frac{R^2}{2\sigma^2}\right)} $$

  1. Is my calculation correct? I am not that confident of it, as have not been using this for a very long time.
  2. The problem has physical meaning when integral it from R to $\infty$. If I need to do the integral from $\infty$ to R, will the the sign be revised?
  • $\begingroup$ The case where $\sigma=\sigma_x=\sigma_y=\sigma_z$ is equivalent to a $\chi^2$ distribution with three degrees of freedom. $\endgroup$
    – irchans
    Nov 12 '18 at 18:28
  • $\begingroup$ wolframalpha.com/input/… $\endgroup$
    – irchans
    Nov 12 '18 at 18:30
  • 1
    $\begingroup$ I think your answer to the case where all the sigma's are the same is correct. I got the same answer using a $\chi^2$ distribution. $\endgroup$
    – irchans
    Nov 12 '18 at 18:41
  • $\begingroup$ @irchans Thanks very much for the input. Did not know χ2 distribution before, but glad to see it is correct. But for the case σx≠σy≠σz , do you think how it could be? And if I integrate it from $\infty$ to 0, will the sign be revised? $\endgroup$ Nov 15 '18 at 14:37
  • $\begingroup$ By convention, $\int_{x=a}^b f(x)dx= - \int_{x=b}^a f(x) dx$ for any real or complex valued function $f$. I don't think that I can do anything analytic when $\sigma_x\ne\sigma_y$. You can get very accurate numerical approximations in those cases. What is your application? $\endgroup$
    – irchans
    Nov 15 '18 at 14:57

When I typed

"1 - FunctionExpand[ CDF[ ChiSquareDistribution[3], x][[1, 1, 1]]] /. x -> (R/s)^2 // Simplify//PowerExpand//Simplify"

into Mathematica, Mathematica returns

$$1-\text{erf}\left(\frac{R}{\sqrt{2} s}\right)+\frac{\sqrt{\frac{2}{\pi }} R e^{-\frac{R^2}{2 s^2}}}{s}$$ which is exactly the same as your result.

I worked on the case where $\sigma_x\ne \sigma_y \ne \sigma_z$, but I did not make much progress.

  • $\begingroup$ That is a really wow. I did not have much experience with Mathematica, it feels so great to see it is confirmed. Thank you so much. And please let me know if you have any progress on the case of $ \sigma_x\ne \sigma_y \ne \sigma_z$ $\endgroup$ Nov 15 '18 at 14:30

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.